diff --git a/build.gradle b/build.gradle index 714c6d2..75b3521 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,12 @@ plugins { id "java" - id "com.github.johnrengelman.shadow" version "7.1.2" + id "io.github.goooler.shadow" version "${shadowVer}" + id "org.jetbrains.gradle.plugin.idea-ext" version "1.0.1" } dependencies { - implementation project(path: ":main", configuration: "shadow") + implementation project(path: ":spigot", configuration: "shadow") + implementation project(path: ":velocity", configuration: "shadow") } tasks { @@ -18,7 +20,7 @@ tasks { allprojects { group = "com.github.kaspiandev.antipopup" - version = "7.3-HOTFIX" + version = "8" repositories { mavenCentral() @@ -35,6 +37,10 @@ allprojects { name = "No." url = "https://repo.viaversion.com" } + maven { + name = "codemc" + url = "https://repo.codemc.io/repository/maven-releases/" + } } } diff --git a/gradle.properties b/gradle.properties index 6a7c312..7b8eeac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,2 @@ -userdevVer=1.5.9 +userdevVer=1.7.0 +shadowVer=8.1.7 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 878fe04..48c0a02 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/lib/packetevents-api-2.2.1.jar b/lib/packetevents-api-2.2.1.jar new file mode 100644 index 0000000..a048c7c Binary files /dev/null and b/lib/packetevents-api-2.2.1.jar differ diff --git a/lib/packetevents-spigot-2.2.1.jar b/lib/packetevents-spigot-2.2.1.jar index 884f8f6..8f60713 100644 Binary files a/lib/packetevents-spigot-2.2.1.jar and b/lib/packetevents-spigot-2.2.1.jar differ diff --git a/lib/packetevents-velocity-2.2.1.jar b/lib/packetevents-velocity-2.2.1.jar new file mode 100644 index 0000000..56cb98f Binary files /dev/null and b/lib/packetevents-velocity-2.2.1.jar differ diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/listeners/PacketEventsListener.java b/main/src/main/java/com/github/kaspiandev/antipopup/listeners/PacketEventsListener.java deleted file mode 100644 index 0dd91b1..0000000 --- a/main/src/main/java/com/github/kaspiandev/antipopup/listeners/PacketEventsListener.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.github.kaspiandev.antipopup.listeners; - -import com.github.kaspiandev.antipopup.AntiPopup; -import com.github.retrooper.packetevents.event.PacketListenerAbstract; -import com.github.retrooper.packetevents.event.PacketListenerPriority; -import com.github.retrooper.packetevents.event.PacketReceiveEvent; -import com.github.retrooper.packetevents.event.PacketSendEvent; -import com.github.retrooper.packetevents.protocol.packettype.PacketType; -import com.github.retrooper.packetevents.protocol.player.ClientVersion; -import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerServerData; -import com.github.retrooper.packetevents.wrapper.status.server.WrapperStatusServerResponse; -import com.google.gson.JsonObject; -import dev.dejvokep.boostedyaml.YamlDocument; - -public class PacketEventsListener extends PacketListenerAbstract { - - private final YamlDocument yamlDoc = AntiPopup.getYamlDoc(); - - public PacketEventsListener() { - super(PacketListenerPriority.LOW); - } - - @Override - public void onPacketSend(PacketSendEvent event) { - if (event.getPacketType() == PacketType.Status.Server.RESPONSE) { - if (event.getUser().getClientVersion().isOlderThan(ClientVersion.V_1_19)) return; - WrapperStatusServerResponse wrapper = new WrapperStatusServerResponse(event); - JsonObject newObj = wrapper.getComponent(); - newObj.addProperty("preventsChatReports", true); - wrapper.setComponent(newObj); - } - if (event.getPacketType() == PacketType.Play.Server.SERVER_DATA) { - WrapperPlayServerServerData serverData = new WrapperPlayServerServerData(event); - serverData.setEnforceSecureChat(true); - } - if (event.getPacketType() == PacketType.Play.Server.PLAYER_CHAT_HEADER - && yamlDoc.getBoolean("dont-send-header")) { - event.setCancelled(true); - } - } - - @Override - public void onPacketReceive(PacketReceiveEvent event) { - if (event.getPacketType() == PacketType.Play.Client.CHAT_SESSION_UPDATE) { - event.setCancelled(true); - } - } - -} diff --git a/nms/build.gradle b/nms/build.gradle new file mode 100644 index 0000000..0011987 --- /dev/null +++ b/nms/build.gradle @@ -0,0 +1,7 @@ +plugins { + id "java" +} + +dependencies { + compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT" +} diff --git a/shared/src/main/java/com/github/kaspiandev/antipopup/nms/AbstractInjector.java b/nms/src/main/java/com/github/kaspiandev/antipopup/spigot/nms/PacketInjector.java similarity index 54% rename from shared/src/main/java/com/github/kaspiandev/antipopup/nms/AbstractInjector.java rename to nms/src/main/java/com/github/kaspiandev/antipopup/spigot/nms/PacketInjector.java index 027cfdb..a8406d9 100644 --- a/shared/src/main/java/com/github/kaspiandev/antipopup/nms/AbstractInjector.java +++ b/nms/src/main/java/com/github/kaspiandev/antipopup/spigot/nms/PacketInjector.java @@ -1,11 +1,11 @@ -package com.github.kaspiandev.antipopup.nms; +package com.github.kaspiandev.antipopup.spigot.nms; import org.bukkit.entity.Player; -public interface AbstractInjector { +public interface PacketInjector { void inject(Player player); void uninject(Player player); -} \ No newline at end of file +} diff --git a/settings.gradle b/settings.gradle index 7bf8536..098b1f0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,4 +6,5 @@ pluginManagement { } rootProject.name = "AntiPopup" -include "main", "shared", "v1.19.2", "v1.19.3", "v1.19.4", "v1.20", "v1.20.2", "v1.20.3" +include "spigot", "shared", "nms", "v1.19.2", "v1.19.3", "v1.19.4", "v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "velocity" + diff --git a/shared/build.gradle b/shared/build.gradle index 9fc138c..9ea5ecd 100644 --- a/shared/build.gradle +++ b/shared/build.gradle @@ -3,5 +3,11 @@ plugins { } dependencies { - compileOnly "org.spigotmc:spigot-api:1.19.3-R0.1-SNAPSHOT" -} \ No newline at end of file + compileOnly "org.apache.logging.log4j:log4j-core:2.19.0" + compileOnly "net.kyori:adventure-api:4.14.0" + + implementation "dev.dejvokep:boosted-yaml:1.3" + implementation "net.kyori:adventure-text-serializer-gson:4.14.0" + implementation "net.kyori:adventure-platform-bukkit:4.3.1" + implementation files("../lib/packetevents-api-2.2.1.jar") +} diff --git a/shared/src/main/java/com/github/kaspiandev/antipopup/config/APConfig.java b/shared/src/main/java/com/github/kaspiandev/antipopup/config/APConfig.java new file mode 100644 index 0000000..5c0aeda --- /dev/null +++ b/shared/src/main/java/com/github/kaspiandev/antipopup/config/APConfig.java @@ -0,0 +1,103 @@ +package com.github.kaspiandev.antipopup.config; + +import dev.dejvokep.boostedyaml.YamlDocument; +import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning; +import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings; +import dev.dejvokep.boostedyaml.settings.general.GeneralSettings; +import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; +import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; + +import java.io.File; +import java.io.IOException; +import java.util.Objects; + +public class APConfig { + + private final YamlDocument document; + + public APConfig(File folder, ClassLoader loader) throws IOException { + this.document = YamlDocument.create(new File(folder, "config.yml"), + Objects.requireNonNull(loader.getResourceAsStream("config.yml")), + GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), + DumperSettings.DEFAULT, + UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")) + .build()); + } + + public boolean isBstats() { + return document.getBoolean("bstats"); + } + + public boolean isFilterNotSecure() { + return document.getBoolean("filter-not-secure"); + } + + public boolean isSendHeader() { + return document.getBoolean("send-header"); + } + + public boolean isAutoSetup() { + return document.getBoolean("auto-setup"); + } + + public boolean isBlockChatReports() { + return document.getBoolean("block-chat-reports"); + } + + public void setBlockChatReports(boolean value) { + document.set("block-chat-reports", value); + } + + public boolean isClickableUrls() { + return document.getBoolean("clickable-urls"); + } + + public String getPropertiesLocation() { + return document.getString("properties-location"); + } + + public boolean isFirstRun() { + return document.getBoolean("first-run"); + } + + public void setFirstRun(boolean value) { + document.set("first-run", value); + } + + public boolean isAskBstats() { + return document.getBoolean("ask-bstats"); + } + + public void setAskBstats(boolean value) { + document.set("ask-bstats", value); + } + + public boolean isSetupMode() { + return document.getBoolean("setup-mode"); + } + + public void setSetupMode(boolean value) { + document.set("setup-mode", value); + } + + public boolean isShowPopup() { + return document.getBoolean("show-popup"); + } + + public void save() { + try { + document.save(); + } catch (IOException ex) { + throw new RuntimeException("Could not save the config.", ex); + } + } + + public void reload() { + try { + document.reload(); + } catch (IOException ex) { + throw new RuntimeException("Could not reload the config.", ex); + } + } + +} diff --git a/shared/src/main/java/com/github/kaspiandev/antipopup/format/ChatFormat.java b/shared/src/main/java/com/github/kaspiandev/antipopup/format/ChatFormat.java new file mode 100644 index 0000000..20b678e --- /dev/null +++ b/shared/src/main/java/com/github/kaspiandev/antipopup/format/ChatFormat.java @@ -0,0 +1,6 @@ +package com.github.kaspiandev.antipopup.format; + +public interface ChatFormat { + + +} diff --git a/shared/src/main/java/com/github/kaspiandev/antipopup/listener/PacketEventsListener.java b/shared/src/main/java/com/github/kaspiandev/antipopup/listener/PacketEventsListener.java new file mode 100644 index 0000000..22ac8e5 --- /dev/null +++ b/shared/src/main/java/com/github/kaspiandev/antipopup/listener/PacketEventsListener.java @@ -0,0 +1,59 @@ +package com.github.kaspiandev.antipopup.listener; + +import com.github.kaspiandev.antipopup.platform.Platform; +import com.github.retrooper.packetevents.event.PacketListenerAbstract; +import com.github.retrooper.packetevents.event.PacketListenerPriority; +import com.github.retrooper.packetevents.event.PacketReceiveEvent; +import com.github.retrooper.packetevents.event.PacketSendEvent; +import com.github.retrooper.packetevents.protocol.packettype.PacketType; +import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; +import com.github.retrooper.packetevents.protocol.player.ClientVersion; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame; +import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerServerData; +import com.github.retrooper.packetevents.wrapper.status.server.WrapperStatusServerResponse; +import com.google.gson.JsonObject; + +public class PacketEventsListener extends PacketListenerAbstract { + + private final Platform platform; + + public PacketEventsListener(Platform platform) { + super(PacketListenerPriority.LOW); + this.platform = platform; + } + + @Override + public void onPacketSend(PacketSendEvent event) { + PacketTypeCommon packetType = event.getPacketType(); + ClientVersion clientVersion = event.getUser().getClientVersion(); + if (packetType == PacketType.Status.Server.RESPONSE + && clientVersion.isNewerThan(ClientVersion.V_1_18_2)) { + WrapperStatusServerResponse wrapper = new WrapperStatusServerResponse(event); + JsonObject newObj = wrapper.getComponent(); + newObj.addProperty("preventsChatReports", true); + wrapper.setComponent(newObj); + } else if (packetType == PacketType.Play.Server.SERVER_DATA + && clientVersion.isOlderThan(ClientVersion.V_1_20_5) + && !platform.getApConfig().isShowPopup()) { + WrapperPlayServerServerData wrapper = new WrapperPlayServerServerData(event); + wrapper.setEnforceSecureChat(true); + } else if (packetType == PacketType.Play.Server.JOIN_GAME + && clientVersion.isNewerThan(ClientVersion.V_1_20_3) + && !platform.getApConfig().isShowPopup()) { + WrapperPlayServerJoinGame wrapper = new WrapperPlayServerJoinGame(event); + wrapper.setEnforcesSecureChat(true); + } else if (packetType == PacketType.Play.Server.PLAYER_CHAT_HEADER + && !platform.getApConfig().isSendHeader()) { + event.setCancelled(true); + } + } + + @Override + public void onPacketReceive(PacketReceiveEvent event) { + PacketTypeCommon packetType = event.getPacketType(); + if (packetType == PacketType.Play.Client.CHAT_SESSION_UPDATE) { + event.setCancelled(true); + } + } + +} diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/LogFilter.java b/shared/src/main/java/com/github/kaspiandev/antipopup/log/LogFilter.java similarity index 92% rename from main/src/main/java/com/github/kaspiandev/antipopup/LogFilter.java rename to shared/src/main/java/com/github/kaspiandev/antipopup/log/LogFilter.java index b945a7f..b959ad6 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/LogFilter.java +++ b/shared/src/main/java/com/github/kaspiandev/antipopup/log/LogFilter.java @@ -1,6 +1,5 @@ -package com.github.kaspiandev.antipopup; +package com.github.kaspiandev.antipopup.log; -import dev.dejvokep.boostedyaml.YamlDocument; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Marker; @@ -11,12 +10,9 @@ public class LogFilter implements Filter { - private final YamlDocument yamlDoc = AntiPopup.getYamlDoc(); - @Override public Filter.Result filter(LogEvent event) { - if (yamlDoc.getBoolean("filter-not-secure") - && event.getMessage().getFormattedMessage().contains("[Not Secure]") + if (event.getMessage().getFormattedMessage().contains("[Not Secure]") && event.getLoggerName().equals("net.minecraft.server.MinecraftServer") && event.getLevel() == Level.INFO) { LogManager.getLogger(event.getLoggerName()).log(event.getLevel(), @@ -131,4 +127,4 @@ public boolean isStopped() { return false; } -} \ No newline at end of file +} diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/message/ConsoleMessages.java b/shared/src/main/java/com/github/kaspiandev/antipopup/message/ConsoleMessages.java similarity index 100% rename from main/src/main/java/com/github/kaspiandev/antipopup/message/ConsoleMessages.java rename to shared/src/main/java/com/github/kaspiandev/antipopup/message/ConsoleMessages.java diff --git a/shared/src/main/java/com/github/kaspiandev/antipopup/platform/Platform.java b/shared/src/main/java/com/github/kaspiandev/antipopup/platform/Platform.java new file mode 100644 index 0000000..6187c1c --- /dev/null +++ b/shared/src/main/java/com/github/kaspiandev/antipopup/platform/Platform.java @@ -0,0 +1,21 @@ +package com.github.kaspiandev.antipopup.platform; + +import com.github.kaspiandev.antipopup.config.APConfig; + +import java.util.UUID; + +public abstract class Platform { + + private final APConfig apConfig; + + protected Platform(APConfig apConfig) { + this.apConfig = apConfig; + } + + public APConfig getApConfig() { + return apConfig; + } + + public abstract String getPlayerName(UUID playerUUID); + +} diff --git a/main/build.gradle b/spigot/build.gradle similarity index 77% rename from main/build.gradle rename to spigot/build.gradle index 42f4db1..4bbc17b 100644 --- a/main/build.gradle +++ b/spigot/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "com.github.johnrengelman.shadow" version "7.1.2" + id "io.github.goooler.shadow" version "${shadowVer}" } repositories { @@ -8,28 +8,24 @@ repositories { name = "devmart-other" url = "https://nexuslite.gcnt.net/repos/other/" } - maven { - name = "codemc" - url = "https://repo.codemc.io/repository/maven-releases/" - } } dependencies { implementation project(path: ":shared") + implementation project(path: ":nms") implementation project(path: ":v1.19.2", configuration: "reobf") implementation project(path: ":v1.19.3", configuration: "reobf") implementation project(path: ":v1.19.4", configuration: "reobf") - implementation project(path: ":v1.20", configuration: "reobf") + implementation project(path: ":v1.20.1", configuration: "reobf") implementation project(path: ":v1.20.2", configuration: "reobf") - implementation project(path: ":v1.20.3", configuration: "reobf") + implementation project(path: ":v1.20.4", configuration: "reobf") + implementation project(path: ":v1.20.6", configuration: "reobf") compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT" - compileOnly "dev.dejvokep:boosted-yaml-spigot:1.3" compileOnly "com.viaversion:viaversion:4.6.1" compileOnly "org.apache.logging.log4j:log4j-core:2.19.0" implementation "org.bstats:bstats-bukkit:3.0.0" - //implementation "com.github.retrooper.packetevents:spigot:2.2.1" implementation files("../lib/packetevents-spigot-2.2.1.jar") implementation "com.tcoded:FoliaLib:0.2.3" } @@ -45,13 +41,10 @@ tasks { relocate("net.kyori", "com.github.kaspiandev.antipopup.libs.kyori") relocate("org.bstats", "com.github.kaspiandev.antipopup.libs.bstats") relocate("com.tcoded.folialib", "com.github.kaspiandev.antipopup.libs.folialib") - dependencies { - exclude(dependency("com.google.code.gson:gson:2.8.0")) - } } } -def targetJavaVersion = 17 +def targetJavaVersion = 21 java { def javaVersion = JavaVersion.toVersion(targetJavaVersion) diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/AntiPopup.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java similarity index 68% rename from main/src/main/java/com/github/kaspiandev/antipopup/AntiPopup.java rename to spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java index c72d286..20bab37 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/AntiPopup.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java @@ -1,32 +1,29 @@ -package com.github.kaspiandev.antipopup; +package com.github.kaspiandev.antipopup.spigot; -import com.github.kaspiandev.antipopup.api.Api; -import com.github.kaspiandev.antipopup.listeners.ChatListener; -import com.github.kaspiandev.antipopup.listeners.PacketEventsListener; +import com.github.kaspiandev.antipopup.config.APConfig; +import com.github.kaspiandev.antipopup.listener.PacketEventsListener; +import com.github.kaspiandev.antipopup.log.LogFilter; import com.github.kaspiandev.antipopup.message.ConsoleMessages; -import com.github.kaspiandev.antipopup.nms.PlayerListener; import com.github.kaspiandev.antipopup.nms.v1_19_2.PlayerInjector_v1_19_2; import com.github.kaspiandev.antipopup.nms.v1_19_3.PlayerInjector_v1_19_3; import com.github.kaspiandev.antipopup.nms.v1_19_4.PlayerInjector_v1_19_4; -import com.github.kaspiandev.antipopup.nms.v1_20.PlayerInjector_v1_20; +import com.github.kaspiandev.antipopup.nms.v1_20_1.PlayerInjector_v1_20_1; import com.github.kaspiandev.antipopup.nms.v1_20_2.PlayerInjector_v1_20_2; -import com.github.kaspiandev.antipopup.nms.v1_20_3.PlayerInjector_v1_20_3; +import com.github.kaspiandev.antipopup.nms.v1_20_4.PlayerInjector_v1_20_4; +import com.github.kaspiandev.antipopup.nms.v1_20_6.PlayerInjector_v1_20_6; +import com.github.kaspiandev.antipopup.spigot.api.Api; +import com.github.kaspiandev.antipopup.spigot.listeners.ChatListener; +import com.github.kaspiandev.antipopup.spigot.nms.PlayerListener; +import com.github.kaspiandev.antipopup.spigot.platform.SpigotPlatform; import com.github.retrooper.packetevents.PacketEvents; import com.github.retrooper.packetevents.manager.server.ServerManager; import com.github.retrooper.packetevents.manager.server.ServerVersion; import com.tcoded.folialib.FoliaLib; -import dev.dejvokep.boostedyaml.YamlDocument; -import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning; -import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings; -import dev.dejvokep.boostedyaml.settings.general.GeneralSettings; -import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; -import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder; import org.apache.logging.log4j.LogManager; import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -43,10 +40,17 @@ public final class AntiPopup extends JavaPlugin { private static File propertiesFile; - private static YamlDocument yamlDoc; - private static Plugin instance; + private static APConfig config; private static FoliaLib foliaLib; + public static FoliaLib getFoliaLib() { + return foliaLib; + } + + public static File getPropertiesFile() { + return propertiesFile; + } + @Override public void onLoad() { PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this)); @@ -57,23 +61,18 @@ public void onLoad() { @Override public void onEnable() { - instance = this; foliaLib = new FoliaLib(this); try { - yamlDoc = YamlDocument.create(new File(getDataFolder(), "config.yml"), - Objects.requireNonNull(getResource("config.yml")), - GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), - DumperSettings.DEFAULT, - UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")) - .build()); + config = new APConfig(getDataFolder(), this.getClassLoader()); getLogger().info("Config enabled."); } catch (IOException ex) { getLogger().warning("Config file could not be initialized."); throw new RuntimeException(ex); } - propertiesFile = new File(Bukkit.getWorldContainer().getParentFile(), yamlDoc.getString("properties-location")); + SpigotPlatform spigotPlatform = new SpigotPlatform(config); + propertiesFile = new File(Bukkit.getWorldContainer().getParentFile(), config.getPropertiesLocation()); - if (yamlDoc.getBoolean("bstats")) { + if (config.isBstats()) { Metrics metrics = new Metrics(this, 16308); metrics.addCustomChart(new SimplePie("runs_viaversion", () -> Bukkit.getPluginManager().isPluginEnabled("ViaVersion") ? "Yes" : "No")); @@ -92,30 +91,31 @@ public void onEnable() { } } - if (yamlDoc.getBoolean("clickable-urls")) { + if (config.isClickableUrls()) { getServer().getPluginManager().registerEvents(new ChatListener(), this); getLogger().info("Enabled URL support."); } - PacketEvents.getAPI().getEventManager().registerListener(new PacketEventsListener()); + PacketEvents.getAPI().getEventManager().registerListener(new PacketEventsListener(spigotPlatform)); PacketEvents.getAPI().init(); getLogger().info("Initiated PacketEvents."); PluginManager pluginManager = getServer().getPluginManager(); ServerManager serverManager = PacketEvents.getAPI().getServerManager(); - if (yamlDoc.getBoolean("block-chat-reports") + if (config.isBlockChatReports() && serverManager.getVersion().isOlderThan(ServerVersion.V_1_19_1)) { - yamlDoc.set("block-chat-reports", false); + config.setBlockChatReports(false); ConsoleMessages.log(ConsoleMessages.BLOCKING_REPORTS_UNSUPPORTED, getLogger()::severe); throw new IllegalStateException("Blocking chat reports was enabled but your server version isn't supported!"); } - if (yamlDoc.getBoolean("block-chat-reports")) { + if (config.isBlockChatReports()) { PlayerListener playerListener = switch (serverManager.getVersion()) { - case V_1_20_3, V_1_20_4 -> new PlayerListener(new PlayerInjector_v1_20_3()); + case V_1_20_5, V_1_20_6 -> new PlayerListener(new PlayerInjector_v1_20_6()); + case V_1_20_3, V_1_20_4 -> new PlayerListener(new PlayerInjector_v1_20_4()); case V_1_20_2 -> new PlayerListener(new PlayerInjector_v1_20_2()); - case V_1_20, V_1_20_1 -> new PlayerListener(new PlayerInjector_v1_20()); + case V_1_20, V_1_20_1 -> new PlayerListener(new PlayerInjector_v1_20_1()); case V_1_19_4 -> new PlayerListener(new PlayerInjector_v1_19_4()); case V_1_19_3 -> new PlayerListener(new PlayerInjector_v1_19_3()); case V_1_19_1, V_1_19_2 -> new PlayerListener(new PlayerInjector_v1_19_2()); @@ -125,20 +125,18 @@ public void onEnable() { pluginManager.registerEvents(playerListener, this); getLogger().info("Hooked on " + serverManager.getVersion().getReleaseName()); - Objects.requireNonNull(this.getCommand("antipopup")).setExecutor(new CommandRegister()); + Objects.requireNonNull(this.getCommand("antipopup")).setExecutor(new CommandRegister(config)); getLogger().info("Commands registered."); - if (yamlDoc.getBoolean("filter-not-secure")) { + if (config.isFilterNotSecure()) { ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addFilter(new LogFilter()); getLogger().info("Logger filter enabled."); - } else { - getLogger().info("Logger filter has not been enabled."); } } foliaLib.getImpl().runLater(() -> { - if (yamlDoc.getBoolean("auto-setup")) Api.setupAntiPopup(80, true); - if (yamlDoc.getBoolean("first-run")) { + if (config.isAutoSetup()) Api.setupAntiPopup(80, true); + if (config.isFirstRun()) { try { FileInputStream in = new FileInputStream(propertiesFile); Properties props = new Properties(); @@ -147,20 +145,16 @@ public void onEnable() { ConsoleMessages.log(ConsoleMessages.ASK_SETUP, getLogger()::warning); } in.close(); - yamlDoc.set("first-run", false); - yamlDoc.save(); + config.setFirstRun(false); + config.save(); } catch (IOException ex) { throw new RuntimeException(ex); } } - if (yamlDoc.getBoolean("ask-bstats")) { - try { - ConsoleMessages.log(ConsoleMessages.ASK_BSTATS, getLogger()::warning); - yamlDoc.set("ask-bstats", false); - yamlDoc.save(); - } catch (IOException ex) { - throw new RuntimeException(ex); - } + if (config.isAskBstats()) { + ConsoleMessages.log(ConsoleMessages.ASK_BSTATS, getLogger()::warning); + config.setAskBstats(false); + config.save(); } }, 5 * 50L, TimeUnit.MILLISECONDS); } @@ -171,20 +165,4 @@ public void onDisable() { getLogger().info("Disabled PacketEvents."); } - public static Plugin getInstance() { - return instance; - } - - public static YamlDocument getYamlDoc() { - return yamlDoc; - } - - public static FoliaLib getFoliaLib() { - return foliaLib; - } - - public static File getPropertiesFile() { - return propertiesFile; - } - } diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/CommandRegister.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/CommandRegister.java similarity index 59% rename from main/src/main/java/com/github/kaspiandev/antipopup/CommandRegister.java rename to spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/CommandRegister.java index 0980c5d..ba67e8f 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/CommandRegister.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/CommandRegister.java @@ -1,22 +1,22 @@ -package com.github.kaspiandev.antipopup; +package com.github.kaspiandev.antipopup.spigot; -import com.github.kaspiandev.antipopup.api.Api; -import dev.dejvokep.boostedyaml.YamlDocument; +import com.github.kaspiandev.antipopup.config.APConfig; +import com.github.kaspiandev.antipopup.spigot.api.Api; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import java.io.IOException; - import static org.bukkit.Bukkit.getLogger; public class CommandRegister implements CommandExecutor { - private final Plugin instance = AntiPopup.getInstance(); - private final YamlDocument yamlDoc = AntiPopup.getYamlDoc(); + private final APConfig config; + + public CommandRegister(APConfig config) { + this.config = config; + } @Override public boolean onCommand(@NotNull CommandSender sender, @@ -28,12 +28,8 @@ public boolean onCommand(@NotNull CommandSender sender, if ("setup".equals(args[0])) { Api.setupAntiPopup(100, false); } else if ("reload".equals(args[0])) { - try { - yamlDoc.reload(); - getLogger().info("Config has been reloaded."); - } catch (IOException e) { - throw new RuntimeException(e); - } + config.reload(); + getLogger().info("Config has been reloaded."); } } diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/ViaHook.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/ViaHook.java similarity index 96% rename from main/src/main/java/com/github/kaspiandev/antipopup/ViaHook.java rename to spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/ViaHook.java index f01a189..a18170b 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/ViaHook.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/ViaHook.java @@ -1,4 +1,4 @@ -package com.github.kaspiandev.antipopup; +package com.github.kaspiandev.antipopup.spigot; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.protocol.Protocol; diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/api/Api.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/api/Api.java similarity index 94% rename from main/src/main/java/com/github/kaspiandev/antipopup/api/Api.java rename to spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/api/Api.java index 00d480b..b510e3c 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/api/Api.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/api/Api.java @@ -1,7 +1,7 @@ -package com.github.kaspiandev.antipopup.api; +package com.github.kaspiandev.antipopup.spigot.api; -import com.github.kaspiandev.antipopup.AntiPopup; import com.github.kaspiandev.antipopup.message.ConsoleMessages; +import com.github.kaspiandev.antipopup.spigot.AntiPopup; import com.github.retrooper.packetevents.PacketEvents; import java.io.FileInputStream; diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/listeners/ChatListener.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/listeners/ChatListener.java similarity index 94% rename from main/src/main/java/com/github/kaspiandev/antipopup/listeners/ChatListener.java rename to spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/listeners/ChatListener.java index d347b1b..7ce0816 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/listeners/ChatListener.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/listeners/ChatListener.java @@ -1,4 +1,4 @@ -package com.github.kaspiandev.antipopup.listeners; +package com.github.kaspiandev.antipopup.spigot.listeners; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -29,4 +29,4 @@ public void onMessage(AsyncPlayerChatEvent event) { true, sender, event.getMessage(), Set.of())); } -} \ No newline at end of file +} diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/nms/PlayerListener.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/nms/PlayerListener.java similarity index 79% rename from main/src/main/java/com/github/kaspiandev/antipopup/nms/PlayerListener.java rename to spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/nms/PlayerListener.java index a54e818..bf9d268 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/nms/PlayerListener.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/nms/PlayerListener.java @@ -1,4 +1,4 @@ -package com.github.kaspiandev.antipopup.nms; +package com.github.kaspiandev.antipopup.spigot.nms; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -8,9 +8,9 @@ public class PlayerListener implements Listener { - private final AbstractInjector injector; + private final PacketInjector injector; - public PlayerListener(AbstractInjector injector) { + public PlayerListener(PacketInjector injector) { this.injector = injector; } diff --git a/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/platform/SpigotPlatform.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/platform/SpigotPlatform.java new file mode 100644 index 0000000..4072d88 --- /dev/null +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/platform/SpigotPlatform.java @@ -0,0 +1,21 @@ +package com.github.kaspiandev.antipopup.spigot.platform; + +import com.github.kaspiandev.antipopup.config.APConfig; +import com.github.kaspiandev.antipopup.platform.Platform; +import org.bukkit.Bukkit; + +import java.util.Objects; +import java.util.UUID; + +public class SpigotPlatform extends Platform { + + public SpigotPlatform(APConfig apConfig) { + super(apConfig); + } + + @Override + public String getPlayerName(UUID playerUUID) { + return Objects.requireNonNull(Bukkit.getPlayer(playerUUID)).getDisplayName(); + } + +} diff --git a/main/src/main/java/com/github/kaspiandev/antipopup/util/VersionUtil.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/util/VersionUtil.java similarity index 87% rename from main/src/main/java/com/github/kaspiandev/antipopup/util/VersionUtil.java rename to spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/util/VersionUtil.java index d92f03e..0ba0629 100644 --- a/main/src/main/java/com/github/kaspiandev/antipopup/util/VersionUtil.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/util/VersionUtil.java @@ -1,4 +1,4 @@ -package com.github.kaspiandev.antipopup.util; +package com.github.kaspiandev.antipopup.spigot.util; import org.bukkit.Bukkit; diff --git a/main/src/main/resources/config.yml b/spigot/src/main/resources/config.yml similarity index 85% rename from main/src/main/resources/config.yml rename to spigot/src/main/resources/config.yml index 119b1e3..4383bcf 100644 --- a/main/src/main/resources/config.yml +++ b/spigot/src/main/resources/config.yml @@ -1,4 +1,4 @@ -config-version: 31 +config-version: 33 # Should we collect anonymous data about your server? # false by default. @@ -12,7 +12,7 @@ filter-not-secure: true # We dont need that packet if # we dont sign messages. -dont-send-header: true +send-header: false # Should setup be ran on first start? # Useful for all kinds of setups or server hosts. @@ -22,10 +22,16 @@ auto-setup: false # Only works for versions above 1.19(.0). block-chat-reports: true +# Should popup appear for players? +# Not recommended. +show-popup: false + +# --- SPIGOT ONLY --- # Readd clickable URLs in messages. # Could cause incompabilities! clickable-urls: false +# --- SPIGOT ONLY --- # Location of server.properties file relative to server's folder. # Do not change unless needed. properties-location: server.properties diff --git a/main/src/main/resources/plugin.yml b/spigot/src/main/resources/plugin.yml similarity index 79% rename from main/src/main/resources/plugin.yml rename to spigot/src/main/resources/plugin.yml index fd9ea83..0de3673 100644 --- a/main/src/main/resources/plugin.yml +++ b/spigot/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: AntiPopup version: '${version}' -main: com.github.kaspiandev.antipopup.AntiPopup +main: com.github.kaspiandev.antipopup.spigot.AntiPopup api-version: 1.17 load: POSTWORLD softdepend: @@ -12,8 +12,6 @@ softdepend: - Geyser-Spigot authors: [ Kaspian ] description: A plugin that removed annoying unsafe server popup. -libraries: - - "dev.dejvokep:boosted-yaml-spigot:1.3" commands: antipopup: description: Main antipopup command. diff --git a/v1.19.2/build.gradle b/v1.19.2/build.gradle index 8699989..3e1a5a8 100644 --- a/v1.19.2/build.gradle +++ b/v1.19.2/build.gradle @@ -5,6 +5,7 @@ plugins { dependencies { compileOnly project(path: ":shared") + compileOnly project(path: ":nms") paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.19.2-R0.1-SNAPSHOT" } diff --git a/v1.19.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_2/PlayerInjector_v1_19_2.java b/v1.19.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_2/PlayerInjector_v1_19_2.java index 7c3443e..e3bd72f 100644 --- a/v1.19.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_2/PlayerInjector_v1_19_2.java +++ b/v1.19.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_2/PlayerInjector_v1_19_2.java @@ -1,6 +1,6 @@ package com.github.kaspiandev.antipopup.nms.v1_19_2; -import com.github.kaspiandev.antipopup.nms.AbstractInjector; +import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; import io.netty.channel.*; import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.Component; @@ -15,7 +15,7 @@ import java.util.Optional; @SuppressWarnings("unused") -public class PlayerInjector_v1_19_2 implements AbstractInjector { +public class PlayerInjector_v1_19_2 implements PacketInjector { private static final String HANDLER_NAME = "antipopup_handler"; @@ -25,7 +25,7 @@ public void inject(Player player) { public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception { if (packet instanceof ClientboundPlayerChatPacket chatPacket) { Component content = chatPacket.message().unsignedContent() - .orElse(chatPacket.message().serverContent()); + .orElse(chatPacket.message().serverContent()); Optional chatType = chatPacket.chatType().resolve( ((CraftServer) Bukkit.getServer()).getServer().registryAccess()); diff --git a/v1.19.3/build.gradle b/v1.19.3/build.gradle index ad1c057..7389837 100644 --- a/v1.19.3/build.gradle +++ b/v1.19.3/build.gradle @@ -5,6 +5,7 @@ plugins { dependencies { compileOnly project(path: ":shared") + compileOnly project(path: ":nms") paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.19.3-R0.1-SNAPSHOT" } diff --git a/v1.19.3/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_3/PlayerInjector_v1_19_3.java b/v1.19.3/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_3/PlayerInjector_v1_19_3.java index cc3b404..1dd5d43 100644 --- a/v1.19.3/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_3/PlayerInjector_v1_19_3.java +++ b/v1.19.3/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_3/PlayerInjector_v1_19_3.java @@ -1,6 +1,6 @@ package com.github.kaspiandev.antipopup.nms.v1_19_3; -import com.github.kaspiandev.antipopup.nms.AbstractInjector; +import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; import io.netty.channel.*; import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.Component; @@ -15,7 +15,7 @@ import java.util.Optional; @SuppressWarnings("unused") -public class PlayerInjector_v1_19_3 implements AbstractInjector { +public class PlayerInjector_v1_19_3 implements PacketInjector { private static final String HANDLER_NAME = "antipopup_handler"; diff --git a/v1.19.4/build.gradle b/v1.19.4/build.gradle index 96682f4..76853f1 100644 --- a/v1.19.4/build.gradle +++ b/v1.19.4/build.gradle @@ -5,6 +5,7 @@ plugins { dependencies { compileOnly project(path: ":shared") + compileOnly project(path: ":nms") paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.19.4-R0.1-SNAPSHOT" } diff --git a/v1.19.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_4/PlayerInjector_v1_19_4.java b/v1.19.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_4/PlayerInjector_v1_19_4.java index 3104488..1da7543 100644 --- a/v1.19.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_4/PlayerInjector_v1_19_4.java +++ b/v1.19.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_19_4/PlayerInjector_v1_19_4.java @@ -1,6 +1,6 @@ package com.github.kaspiandev.antipopup.nms.v1_19_4; -import com.github.kaspiandev.antipopup.nms.AbstractInjector; +import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; import io.netty.channel.*; import net.minecraft.network.Connection; import net.minecraft.network.chat.ChatType; @@ -18,7 +18,7 @@ import java.util.Optional; @SuppressWarnings("unused") -public class PlayerInjector_v1_19_4 implements AbstractInjector { +public class PlayerInjector_v1_19_4 implements PacketInjector { private static final String HANDLER_NAME = "antipopup_handler"; private static Field connectionField; diff --git a/v1.20.3/build.gradle b/v1.20.1/build.gradle similarity index 78% rename from v1.20.3/build.gradle rename to v1.20.1/build.gradle index b4e0aae..e389fd0 100644 --- a/v1.20.3/build.gradle +++ b/v1.20.1/build.gradle @@ -5,6 +5,7 @@ plugins { dependencies { compileOnly project(path: ":shared") + compileOnly project(path: ":nms") - paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.3-R0.1-SNAPSHOT" + paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.1-R0.1-SNAPSHOT" } diff --git a/v1.20/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20/PlayerInjector_v1_20.java b/v1.20.1/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_1/PlayerInjector_v1_20_1.java similarity index 94% rename from v1.20/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20/PlayerInjector_v1_20.java rename to v1.20.1/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_1/PlayerInjector_v1_20_1.java index 3b07550..b83dd16 100644 --- a/v1.20/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20/PlayerInjector_v1_20.java +++ b/v1.20.1/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_1/PlayerInjector_v1_20_1.java @@ -1,6 +1,6 @@ -package com.github.kaspiandev.antipopup.nms.v1_20; +package com.github.kaspiandev.antipopup.nms.v1_20_1; -import com.github.kaspiandev.antipopup.nms.AbstractInjector; +import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; import io.netty.channel.*; import net.minecraft.network.Connection; import net.minecraft.network.chat.ChatType; @@ -18,7 +18,7 @@ import java.util.Optional; @SuppressWarnings("unused") -public class PlayerInjector_v1_20 implements AbstractInjector { +public class PlayerInjector_v1_20_1 implements PacketInjector { private static final String HANDLER_NAME = "antipopup_handler"; private static Field connectionField; diff --git a/v1.20.2/build.gradle b/v1.20.2/build.gradle index 0266e72..9f6fb1d 100644 --- a/v1.20.2/build.gradle +++ b/v1.20.2/build.gradle @@ -5,6 +5,8 @@ plugins { dependencies { compileOnly project(path: ":shared") + compileOnly project(path: ":nms") paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.2-R0.1-SNAPSHOT" + compileOnly "net.kyori:adventure-platform-bukkit:4.3.1" } diff --git a/v1.20.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_2/PlayerInjector_v1_20_2.java b/v1.20.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_2/PlayerInjector_v1_20_2.java index c609e1b..2b3a640 100644 --- a/v1.20.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_2/PlayerInjector_v1_20_2.java +++ b/v1.20.2/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_2/PlayerInjector_v1_20_2.java @@ -1,6 +1,6 @@ package com.github.kaspiandev.antipopup.nms.v1_20_2; -import com.github.kaspiandev.antipopup.nms.AbstractInjector; +import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; import io.netty.channel.*; import net.minecraft.network.Connection; import net.minecraft.network.chat.ChatType; @@ -19,7 +19,7 @@ import java.util.Optional; @SuppressWarnings("unused") -public class PlayerInjector_v1_20_2 implements AbstractInjector { +public class PlayerInjector_v1_20_2 implements PacketInjector { private static final String HANDLER_NAME = "antipopup_handler"; private static Field connectionField; diff --git a/v1.20/build.gradle b/v1.20.4/build.gradle similarity index 78% rename from v1.20/build.gradle rename to v1.20.4/build.gradle index 9d0145f..1286938 100644 --- a/v1.20/build.gradle +++ b/v1.20.4/build.gradle @@ -5,6 +5,7 @@ plugins { dependencies { compileOnly project(path: ":shared") + compileOnly project(path: ":nms") - paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20-R0.1-SNAPSHOT" + paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.4-R0.1-SNAPSHOT" } diff --git a/v1.20.3/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_3/PlayerInjector_v1_20_3.java b/v1.20.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_4/PlayerInjector_v1_20_4.java similarity index 94% rename from v1.20.3/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_3/PlayerInjector_v1_20_3.java rename to v1.20.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_4/PlayerInjector_v1_20_4.java index 19fc0e0..0b08797 100644 --- a/v1.20.3/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_3/PlayerInjector_v1_20_3.java +++ b/v1.20.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_4/PlayerInjector_v1_20_4.java @@ -1,6 +1,6 @@ -package com.github.kaspiandev.antipopup.nms.v1_20_3; +package com.github.kaspiandev.antipopup.nms.v1_20_4; -import com.github.kaspiandev.antipopup.nms.AbstractInjector; +import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; import io.netty.channel.*; import net.minecraft.network.Connection; import net.minecraft.network.chat.ChatType; @@ -19,7 +19,7 @@ import java.util.Optional; @SuppressWarnings("unused") -public class PlayerInjector_v1_20_3 implements AbstractInjector { +public class PlayerInjector_v1_20_4 implements PacketInjector { private static final String HANDLER_NAME = "antipopup_handler"; private static Field connectionField; diff --git a/v1.20.6/build.gradle b/v1.20.6/build.gradle new file mode 100644 index 0000000..4d91c55 --- /dev/null +++ b/v1.20.6/build.gradle @@ -0,0 +1,11 @@ +plugins { + id "java" + id "io.papermc.paperweight.userdev" version "${userdevVer}" +} + +dependencies { + compileOnly project(path: ":shared") + compileOnly project(path: ":nms") + + paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.6-R0.1-SNAPSHOT" +} diff --git a/v1.20.6/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_6/PlayerInjector_v1_20_6.java b/v1.20.6/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_6/PlayerInjector_v1_20_6.java new file mode 100644 index 0000000..9deb34c --- /dev/null +++ b/v1.20.6/src/main/java/com/github/kaspiandev/antipopup/nms/v1_20_6/PlayerInjector_v1_20_6.java @@ -0,0 +1,86 @@ +package com.github.kaspiandev.antipopup.nms.v1_20_6; + +import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; +import io.netty.channel.*; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket; +import net.minecraft.network.protocol.game.ClientboundSystemChatPacket; +import net.minecraft.server.network.ServerCommonPacketListenerImpl; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; +import java.lang.reflect.InaccessibleObjectException; + +@SuppressWarnings("unused") +public class PlayerInjector_v1_20_6 implements PacketInjector { + + private static final String HANDLER_NAME = "antipopup_handler"; + private static Field connectionField; + + static { + try { + for (Field field : ServerCommonPacketListenerImpl.class.getDeclaredFields()) { + if (field.getType().equals(Connection.class)) { + field.setAccessible(true); + connectionField = field; + break; + } + } + } catch (SecurityException | InaccessibleObjectException e) { + throw new RuntimeException(e); + } + } + + public void inject(Player player) { + ChannelDuplexHandler duplexHandler = new ChannelDuplexHandler() { + @Override + public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception { + if (packet instanceof ClientboundPlayerChatPacket chatPacket) { + Component content = chatPacket.unsignedContent(); + if (content == null) { + content = Component.literal(chatPacket.body().content()); + } + ChatType.Bound chatType = chatPacket.chatType(); + + ((CraftPlayer) player).getHandle().connection.send( + new ClientboundSystemChatPacket(chatType.decorate(content), false)); + return; + } + super.write(ctx, packet, promise); + } + }; + + ServerGamePacketListenerImpl listener = ((CraftPlayer) player).getHandle().connection; + Channel channel = getConnection(listener).channel; + ChannelPipeline pipeline = channel.pipeline(); + + if (pipeline.get(HANDLER_NAME) != null) { + pipeline.remove(HANDLER_NAME); + } + + channel.eventLoop().submit(() -> { + channel.pipeline().addBefore("packet_handler", HANDLER_NAME, duplexHandler); + }); + } + + public void uninject(Player player) { + ServerGamePacketListenerImpl listener = ((CraftPlayer) player).getHandle().connection; + Channel channel = getConnection(listener).channel; + channel.eventLoop().submit(() -> { + channel.pipeline().remove(HANDLER_NAME); + }); + } + + private Connection getConnection(ServerGamePacketListenerImpl listener) { + try { + return (Connection) connectionField.get(listener); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/velocity/build.gradle b/velocity/build.gradle new file mode 100644 index 0000000..05ca330 --- /dev/null +++ b/velocity/build.gradle @@ -0,0 +1,50 @@ +plugins { + id "java" + id "org.jetbrains.gradle.plugin.idea-ext" version "1.0.1" + id "io.github.goooler.shadow" version "${shadowVer}" +} + +repositories { + maven { + name = "papermc-repo" + url = "https://repo.papermc.io/repository/maven-public/" + } +} + +dependencies { + compileOnly "com.velocitypowered:velocity-api:3.2.0-SNAPSHOT" + annotationProcessor "com.velocitypowered:velocity-api:3.2.0-SNAPSHOT" + + implementation project(path: ":shared") + implementation files("../lib/packetevents-velocity-2.2.1.jar") +} + +tasks { + build { + dependsOn(shadowJar) + } + shadowJar { + minimize() + relocate("io.github.retrooper.packetevents", "com.github.kaspiandev.antipopup.libs.packetevents") + relocate("com.github.retrooper.packetevents", "com.github.kaspiandev.antipopup.libs.packetevents") + relocate("net.kyori", "com.github.kaspiandev.antipopup.libs.kyori") + relocate("org.bstats", "com.github.kaspiandev.antipopup.libs.bstats") + } +} + +def templateSource = file("src/main/templates") +def templateDest = layout.buildDirectory.dir("generated/sources/templates") +def generateTemplates = tasks.register("generateTemplates", Copy) { task -> + def props = [ + "version": project.version + ] + task.inputs.properties props + + task.from templateSource + task.into templateDest + task.expand props +} + +sourceSets.main.java.srcDir(generateTemplates.map { it.outputs }) + +rootProject.idea.project.settings.taskTriggers.afterSync generateTemplates diff --git a/velocity/src/main/java/com/github/kaspiandev/antipopup/velocity/AntiPopup.java b/velocity/src/main/java/com/github/kaspiandev/antipopup/velocity/AntiPopup.java new file mode 100644 index 0000000..29a9c82 --- /dev/null +++ b/velocity/src/main/java/com/github/kaspiandev/antipopup/velocity/AntiPopup.java @@ -0,0 +1,53 @@ +package com.github.kaspiandev.antipopup.velocity; + +import com.github.kaspiandev.antipopup.config.APConfig; +import com.github.kaspiandev.antipopup.listener.PacketEventsListener; +import com.github.kaspiandev.antipopup.velocity.platform.VelocityPlatform; +import com.github.retrooper.packetevents.PacketEvents; +import com.google.inject.Inject; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.PluginContainer; +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import com.velocitypowered.api.proxy.ProxyServer; +import io.github.retrooper.packetevents.velocity.factory.VelocityPacketEventsBuilder; +import org.slf4j.Logger; + +import java.io.IOException; +import java.nio.file.Path; + +@Plugin( + id = "antipopup", + name = "AntiPopup", + version = BuildConstants.VERSION +) +public class AntiPopup { + + private final ProxyServer server; + private final APConfig config; + private final Logger logger; + private final Path dataDirectory; + + @Inject + public AntiPopup(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) throws IOException { + this.server = server; + this.logger = logger; + this.config = new APConfig(dataDirectory.toFile(), this.getClass().getClassLoader()); + this.dataDirectory = dataDirectory; + } + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + VelocityPlatform platform = new VelocityPlatform(server, config); + + PluginContainer pluginContainer = server.getPluginManager().ensurePluginContainer(this); + PacketEvents.setAPI(VelocityPacketEventsBuilder.build(server, pluginContainer, logger, dataDirectory)); + PacketEvents.getAPI().getSettings().debug(false).bStats(false).checkForUpdates(false); + PacketEvents.getAPI().load(); + PacketEvents.getAPI().getEventManager().registerListener(new PacketEventsListener(platform)); + PacketEvents.getAPI().init(); + } + + +} diff --git a/velocity/src/main/java/com/github/kaspiandev/antipopup/velocity/platform/VelocityPlatform.java b/velocity/src/main/java/com/github/kaspiandev/antipopup/velocity/platform/VelocityPlatform.java new file mode 100644 index 0000000..95573d5 --- /dev/null +++ b/velocity/src/main/java/com/github/kaspiandev/antipopup/velocity/platform/VelocityPlatform.java @@ -0,0 +1,23 @@ +package com.github.kaspiandev.antipopup.velocity.platform; + +import com.github.kaspiandev.antipopup.config.APConfig; +import com.github.kaspiandev.antipopup.platform.Platform; +import com.velocitypowered.api.proxy.ProxyServer; + +import java.util.UUID; + +public class VelocityPlatform extends Platform { + + private final ProxyServer server; + + public VelocityPlatform(ProxyServer server, APConfig apConfig) { + super(apConfig); + this.server = server; + } + + @Override + public String getPlayerName(UUID playerUUID) { + return server.getPlayer(playerUUID).orElseThrow().getUsername(); + } + +} diff --git a/velocity/src/main/templates/com/github/kaspiandev/antipopup/velocity/BuildConstants.java b/velocity/src/main/templates/com/github/kaspiandev/antipopup/velocity/BuildConstants.java new file mode 100644 index 0000000..7f494c9 --- /dev/null +++ b/velocity/src/main/templates/com/github/kaspiandev/antipopup/velocity/BuildConstants.java @@ -0,0 +1,7 @@ +package com.github.kaspiandev.antipopup.velocity; + +// The constants are replaced before compilation +public class BuildConstants { + + public static final String VERSION = "${version}"; +}