From 7d0370ffb2a43c12348adce6db5c7ca7f0589024 Mon Sep 17 00:00:00 2001 From: BAD7777 <129652614+BAD7777@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:25:13 +0300 Subject: [PATCH] Update 10.1 (#107) * Create v1.21.4 * Delete v1.21.4 * Create build.gradle * Create PlayerInjector_v1_21_4.java * Update settings.gradle * Update build.gradle * Update gradle.properties * Update build.gradle * Update AntiPopup.java --- build.gradle | 2 +- gradle.properties | 2 +- settings.gradle | 2 +- spigot/build.gradle | 3 +- .../antipopup/spigot/AntiPopup.java | 2 + v1.21.4/build.gradle | 21 +++++ .../nms/v1_21_4/PlayerInjector_v1_21_4.java | 86 +++++++++++++++++++ 7 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 v1.21.4/build.gradle create mode 100644 v1.21.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_4/PlayerInjector_v1_21_4.java diff --git a/build.gradle b/build.gradle index e66b03d..ec171b8 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ tasks { allprojects { group = "com.github.kaspiandev.antipopup" - version = "10" + version = "10.1" repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties index 2aae38e..9d221d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ userdevVer=1.7.1 shadowVer=8.1.7 tinyRemapperVer=0.10.3 -packetEventsVer=2.6.0 +packetEventsVer=2.7.0 diff --git a/settings.gradle b/settings.gradle index 5810b5e..84ae390 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,5 +7,5 @@ pluginManagement { rootProject.name = "AntiPopup" 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", "v1.21", "v1.21.2", "velocity" + "v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "v1.21", "v1.21.2", "v1.21.4", "velocity" diff --git a/spigot/build.gradle b/spigot/build.gradle index ccb4103..aafec65 100644 --- a/spigot/build.gradle +++ b/spigot/build.gradle @@ -22,9 +22,10 @@ dependencies { implementation project(path: ":v1.20.6", configuration: "reobf") implementation project(path: ":v1.21", configuration: "reobf") implementation project(path: ":v1.21.2", configuration: "reobf") + implementation project(path: ":v1.21.4", configuration: "reobf") compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT" - compileOnly "com.viaversion:viaversion:5.0.1" + compileOnly "com.viaversion:viaversion:5.2.0" compileOnly "org.apache.logging.log4j:log4j-core:2.19.0" implementation "org.bstats:bstats-bukkit:3.0.0" diff --git a/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java index f3d6948..634add0 100644 --- a/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java @@ -13,6 +13,7 @@ import com.github.kaspiandev.antipopup.nms.v1_20_6.PlayerInjector_v1_20_6; import com.github.kaspiandev.antipopup.nms.v1_21.PlayerInjector_v1_21; import com.github.kaspiandev.antipopup.nms.v1_21_2.PlayerInjector_v1_21_2; +import com.github.kaspiandev.antipopup.nms.v1_21_4.PlayerInjector_v1_21_4; import com.github.kaspiandev.antipopup.spigot.api.Api; import com.github.kaspiandev.antipopup.spigot.hook.HookManager; import com.github.kaspiandev.antipopup.spigot.hook.viaversion.ViaVersionHook; @@ -120,6 +121,7 @@ public void onEnable() { if (config.isBlockChatReports()) { if (!config.isExperimentalMode()) { PlayerListener playerListener = switch (serverManager.getVersion()) { + case V_1_21_4 -> new PlayerListener(new PlayerInjector_v1_21_4()); case V_1_21_2, V_1_21_3 -> new PlayerListener(new PlayerInjector_v1_21_2()); case V_1_21, V_1_21_1 -> new PlayerListener(new PlayerInjector_v1_21()); case V_1_20_5, V_1_20_6 -> new PlayerListener(new PlayerInjector_v1_20_6()); diff --git a/v1.21.4/build.gradle b/v1.21.4/build.gradle new file mode 100644 index 0000000..ad7d8f5 --- /dev/null +++ b/v1.21.4/build.gradle @@ -0,0 +1,21 @@ +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.21.4-R0.1-SNAPSHOT" + pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat" +} + +java { + disableAutoTargetJvm() + toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} diff --git a/v1.21.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_4/PlayerInjector_v1_21_4.java b/v1.21.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_4/PlayerInjector_v1_21_4.java new file mode 100644 index 0000000..8b81064 --- /dev/null +++ b/v1.21.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_4/PlayerInjector_v1_21_4.java @@ -0,0 +1,86 @@ +package com.github.kaspiandev.antipopup.nms.v1_21_4; + +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_21_4 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); + } + } + +}