From 07dcecd2008af490594fdd6c88e39010a660b78c Mon Sep 17 00:00:00 2001 From: Vincent <79623093+V1nc3ntWasTaken@users.noreply.github.com> Date: Sun, 18 Sep 2022 13:01:31 -0500 Subject: [PATCH] Add 1.19.1 support in 1.19.1 maven module --- 1.19.1/pom.xml | 121 ++++++++++++++++++ .../me/doclic/noencryption/NoEncryption.java | 30 +++++ .../doclic/noencryption/PlayerListener.java | 54 ++++++++ .../compatibility/Compatibility.java | 77 +++++++++++ .../CompatiblePacketListener.java | 68 ++++++++++ .../compatibility/CompatiblePlayer.java | 15 +++ 1.19.1/src/main/resources/plugin.yml | 6 + pom.xml | 1 + 8 files changed, 372 insertions(+) create mode 100644 1.19.1/pom.xml create mode 100644 1.19.1/src/main/java/me/doclic/noencryption/NoEncryption.java create mode 100644 1.19.1/src/main/java/me/doclic/noencryption/PlayerListener.java create mode 100644 1.19.1/src/main/java/me/doclic/noencryption/compatibility/Compatibility.java create mode 100644 1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePacketListener.java create mode 100644 1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePlayer.java create mode 100644 1.19.1/src/main/resources/plugin.yml diff --git a/1.19.1/pom.xml b/1.19.1/pom.xml new file mode 100644 index 0000000..6be5456 --- /dev/null +++ b/1.19.1/pom.xml @@ -0,0 +1,121 @@ + + + 4.0.0 + + NoEncryption-1.19.1 + 2.0 + jar + + NoEncryption-1.19.1 + + Makes every player message a system message + + + me.doclic + NoEncryption + 2.0 + + + + 1.17 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 16 + 16 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:1.19.1-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:1.19.1-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:1.19.1-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:1.19.1-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + + src/main/resources + true + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + io.papermc.paper + paper-api + 1.19.1-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot + 1.19.1-R0.1-SNAPSHOT + provided + remapped-mojang + + + diff --git a/1.19.1/src/main/java/me/doclic/noencryption/NoEncryption.java b/1.19.1/src/main/java/me/doclic/noencryption/NoEncryption.java new file mode 100644 index 0000000..9c1e3d0 --- /dev/null +++ b/1.19.1/src/main/java/me/doclic/noencryption/NoEncryption.java @@ -0,0 +1,30 @@ +package me.doclic.noencryption; + +import me.doclic.noencryption.compatibility.Compatibility; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +public final class NoEncryption extends JavaPlugin { + + @Override + public void onEnable() { + + if (Compatibility.SERVER_COMPATIBLE) { + + Bukkit.getPluginManager().registerEvents(new PlayerListener(), this); + + getLogger().info("Compatibility successful!"); + + getLogger().info("If you used /reload to update NoEncryption, your players need to"); + getLogger().info("disconnect and join back"); + + } else { + + getLogger().severe("Failed to setup NoEncryption's compatibility!"); + getLogger().severe("Your server version (" + Compatibility.SERVER_VERSION + ") is not compatible with this plugin!"); + + Bukkit.getPluginManager().disablePlugin(this); + } + + } +} diff --git a/1.19.1/src/main/java/me/doclic/noencryption/PlayerListener.java b/1.19.1/src/main/java/me/doclic/noencryption/PlayerListener.java new file mode 100644 index 0000000..e09bc01 --- /dev/null +++ b/1.19.1/src/main/java/me/doclic/noencryption/PlayerListener.java @@ -0,0 +1,54 @@ +package me.doclic.noencryption; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelDuplexHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.ChannelPromise; +import me.doclic.noencryption.compatibility.Compatibility; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerListener implements Listener { + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerJoin (PlayerJoinEvent e) { + + final Player player = e.getPlayer(); + final ChannelPipeline pipeline = Compatibility.COMPATIBLE_PLAYER.getChannel(player).pipeline(); + pipeline.addBefore("packet_handler", player.getUniqueId().toString(), new ChannelDuplexHandler() { + + @Override + public void channelRead(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception { + + Object newPacket = Compatibility.COMPATIBLE_PACKET_LISTENER.readPacket(channelHandlerContext, packet); + super.channelRead(channelHandlerContext, newPacket); + + } + + @Override + public void write(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise promise) throws Exception { + + Object newPacket = Compatibility.COMPATIBLE_PACKET_LISTENER.writePacket(channelHandlerContext, packet, promise); + super.write(channelHandlerContext, newPacket, promise); + + } + + }); + + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerQuit (PlayerQuitEvent e) { + + final Player player = e.getPlayer(); + final Channel channel = Compatibility.COMPATIBLE_PLAYER.getChannel(player); + channel.eventLoop().submit(() -> channel.pipeline().remove(player.getUniqueId().toString())); + + } + +} diff --git a/1.19.1/src/main/java/me/doclic/noencryption/compatibility/Compatibility.java b/1.19.1/src/main/java/me/doclic/noencryption/compatibility/Compatibility.java new file mode 100644 index 0000000..251d26d --- /dev/null +++ b/1.19.1/src/main/java/me/doclic/noencryption/compatibility/Compatibility.java @@ -0,0 +1,77 @@ +package me.doclic.noencryption.compatibility; + +import org.bukkit.Bukkit; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; + +public class Compatibility { + + public static final CompatiblePlayer COMPATIBLE_PLAYER; + public static final CompatiblePacketListener COMPATIBLE_PACKET_LISTENER; + + public static final String PLUGIN_COMPATIBLE_VERSION; + public static final boolean SERVER_COMPATIBLE; + public static final String SERVER_VERSION; + + static { + + String minecraftVersion; + + PLUGIN_COMPATIBLE_VERSION = "1.19.1-R0.1-SNAPSHOT"; + + try { + + minecraftVersion = Bukkit.getBukkitVersion(); + + + } catch (ArrayIndexOutOfBoundsException exception) { + minecraftVersion = null; + } + + SERVER_VERSION = minecraftVersion; + + Bukkit.getLogger().info("Your server is running version " + minecraftVersion); + + if (minecraftVersion != null && minecraftVersion.equals(PLUGIN_COMPATIBLE_VERSION)) { + + final String versionPackage = getVersionPackage(minecraftVersion); + + COMPATIBLE_PLAYER = instantiate(CompatiblePlayer.class); + COMPATIBLE_PACKET_LISTENER = instantiate(CompatiblePacketListener.class); + + SERVER_COMPATIBLE = true; + + } else { + + COMPATIBLE_PLAYER = null; + COMPATIBLE_PACKET_LISTENER = null; + + SERVER_COMPATIBLE = false; + + } + + } + + private static String getVersionPackage(String minecraftVersion) { + + return Compatibility.class.getPackage().getName(); + + } + + private static T instantiate(Class clazz) { + + if (clazz == null) return null; + + try { + final Constructor constructor = clazz.getConstructor(); + return constructor.newInstance(); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + + } + +} diff --git a/1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePacketListener.java b/1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePacketListener.java new file mode 100644 index 0000000..a228119 --- /dev/null +++ b/1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePacketListener.java @@ -0,0 +1,68 @@ +package me.doclic.noencryption.compatibility; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; +import net.minecraft.network.chat.*; +import net.minecraft.network.protocol.game.ClientboundPlayerChatHeaderPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket; +import net.minecraft.network.protocol.game.ClientboundSystemChatPacket; +import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage; + +import java.util.Optional; +import java.util.UUID; + +public class CompatiblePacketListener { + + public Object readPacket(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception { return packet; } + + public Object writePacket(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise promise) throws Exception { + if (packet instanceof final ClientboundPlayerChatPacket clientboundPlayerChatPacket) { + final PlayerChatMessage message = clientboundPlayerChatPacket.message(); + final Optional unsignedContent = message.unsignedContent(); + final ChatMessageContent signedContent = message.signedContent(); + final SignedMessageBody signedBody = message.signedBody(); + final ChatType.BoundNetwork chatType = clientboundPlayerChatPacket.chatType(); + + // recreate a new packet + return new ClientboundPlayerChatPacket( + new PlayerChatMessage( + new SignedMessageHeader( + new MessageSignature(new byte[0]), + new UUID(0, 0)), + new MessageSignature(new byte[0]), + new SignedMessageBody( + new ChatMessageContent( + signedContent.plain(), + signedContent.decorated()), + signedBody.timeStamp(), + 0, + signedBody.lastSeen()), + unsignedContent, + new FilterMask(0) + ), + chatType); + } else if (packet instanceof final ClientboundSystemChatPacket clientboundSystemChatPacket) { + if (clientboundSystemChatPacket.content() == null) { + return clientboundSystemChatPacket; + } else { + // recreate a new packet + return new ClientboundSystemChatPacket( + CraftChatMessage.fromJSONOrNull(clientboundSystemChatPacket.content()), + clientboundSystemChatPacket.overlay()); + } + } else if (packet instanceof final ClientboundPlayerChatHeaderPacket clientboundPlayerChatHeaderPacket) { + // recreate a new packet + return new ClientboundPlayerChatHeaderPacket( + new SignedMessageHeader( + new MessageSignature(new byte[0]), + new UUID(0, 0)), + new MessageSignature(new byte[0]), + clientboundPlayerChatHeaderPacket.bodyDigest() + ); + } + + return packet; + + } + +} diff --git a/1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePlayer.java b/1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePlayer.java new file mode 100644 index 0000000..acf233b --- /dev/null +++ b/1.19.1/src/main/java/me/doclic/noencryption/compatibility/CompatiblePlayer.java @@ -0,0 +1,15 @@ +package me.doclic.noencryption.compatibility; + +import io.netty.channel.Channel; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class CompatiblePlayer { + + public Channel getChannel(Player player) { + + return ((CraftPlayer) player).getHandle().connection.connection.channel; + + } + +} diff --git a/1.19.1/src/main/resources/plugin.yml b/1.19.1/src/main/resources/plugin.yml new file mode 100644 index 0000000..8207728 --- /dev/null +++ b/1.19.1/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: NoEncryption +version: '${project.parent.version}' +main: me.doclic.noencryption.NoEncryption +api-version: 1.19 +authors: [ Doclic ] +description: Strips signatures from player messages diff --git a/pom.xml b/pom.xml index b8a7831..0c14859 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ 1.19 + 1.19.1