From f1a99b09385bb94b20fae3d1304f463a1d0cde5a Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 6 Aug 2022 19:29:56 +0200 Subject: [PATCH 1/7] ServerDataHandler --- .../src/de/steamwar/core/ChatWrapper19.java | 7 +++++++ .../src/de/steamwar/core/ChatWrapper8.java | 6 ++++++ .../src/de/steamwar/core/ChatWrapper.java | 2 ++ .../src/de/steamwar/core/Core.java | 4 ++++ .../network/handlers/ServerDataHandler.java | 20 +++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java diff --git a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java index 8be810b..718beb0 100644 --- a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java @@ -23,6 +23,7 @@ import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.chat.IChatMutableComponent; import net.minecraft.network.chat.contents.LiteralContents; +import net.minecraft.network.protocol.game.ClientboundServerDataPacket; public class ChatWrapper19 implements ChatWrapper { @Override @@ -35,4 +36,10 @@ public class ChatWrapper19 implements ChatWrapper { public String getNameByLoginPacket(Object packet) { return getName.get(packet); } + + @Override + public Object modifyServerDataPacket(Object o) { + ClientboundServerDataPacket clientboundServerDataPacket = (ClientboundServerDataPacket) o; + return new ClientboundServerDataPacket(clientboundServerDataPacket.b().get(),clientboundServerDataPacket.c().get(),true); + } } diff --git a/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java b/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java index 7d02dfd..65dee02 100644 --- a/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java @@ -22,6 +22,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; +import org.bukkit.entity.Player; public class ChatWrapper8 implements ChatWrapper { @@ -36,4 +37,9 @@ public class ChatWrapper8 implements ChatWrapper { public String getNameByLoginPacket(Object packet) { return getGameProfile.get(packet).getName(); } + + @Override + public Object modifyServerDataPacket(Object o) { + return null; + } } diff --git a/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java b/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java index eeddd1c..fd47522 100644 --- a/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/ChatWrapper.java @@ -24,4 +24,6 @@ public interface ChatWrapper { Object stringToChatComponent(String text); String getNameByLoginPacket(Object packet); + + Object modifyServerDataPacket(Object o); } diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index c510a6b..abc3192 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -31,6 +31,7 @@ import de.steamwar.core.events.PlayerJoinedEvent; import de.steamwar.core.events.WorldLoadEvent; import de.steamwar.message.Message; import de.steamwar.network.NetworkReceiver; +import de.steamwar.network.handlers.ServerDataHandler; import de.steamwar.sql.Statement; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -132,6 +133,9 @@ public class Core extends JavaPlugin{ if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) new PartialChunkFixer(); + if(Core.getVersion() < 18) + new ServerDataHandler(); + try { getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine()); } catch (IOException e) { diff --git a/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java b/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java new file mode 100644 index 0000000..940c48c --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java @@ -0,0 +1,20 @@ +package de.steamwar.network.handlers; + +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.core.ChatWrapper; +import de.steamwar.core.CraftbukkitWrapper; +import org.bukkit.entity.Player; + +public class ServerDataHandler { + + private Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.ClientboundServerDataPacket"); + + public ServerDataHandler() { + TinyProtocol.instance.addFilter(explosionPacket, this::packetFilter); + } + + private Object packetFilter(Player player, Object o) { + return ChatWrapper.impl.modifyServerDataPacket(o); + } +} From 23c0e507cd453753dd61aaae633d0870d268ad2d Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 6 Aug 2022 20:54:11 +0200 Subject: [PATCH 2/7] Use correct server version --- SpigotCore_Main/src/de/steamwar/core/Core.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index abc3192..715fb17 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -133,7 +133,7 @@ public class Core extends JavaPlugin{ if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) new PartialChunkFixer(); - if(Core.getVersion() < 18) + if(Core.getVersion() >= 19) new ServerDataHandler(); try { From 0a6eccf70fcf0f2498f145492079f94d20e02005 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 6 Aug 2022 20:56:23 +0200 Subject: [PATCH 3/7] Variable naming --- .../src/de/steamwar/network/handlers/ServerDataHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java b/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java index 940c48c..0882560 100644 --- a/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java +++ b/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java @@ -8,10 +8,10 @@ import org.bukkit.entity.Player; public class ServerDataHandler { - private Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.ClientboundServerDataPacket"); + private Class serverDataPacket = Reflection.getClass("{nms.network.protocol.game}.ClientboundServerDataPacket"); public ServerDataHandler() { - TinyProtocol.instance.addFilter(explosionPacket, this::packetFilter); + TinyProtocol.instance.addFilter(serverDataPacket, this::packetFilter); } private Object packetFilter(Player player, Object o) { From 71f7264789ff899c95b2048ff4fd8ca8a1c9fe64 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 6 Aug 2022 21:05:15 +0200 Subject: [PATCH 4/7] Fix unknown constructor --- SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java index 718beb0..e883f54 100644 --- a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java @@ -40,6 +40,11 @@ public class ChatWrapper19 implements ChatWrapper { @Override public Object modifyServerDataPacket(Object o) { ClientboundServerDataPacket clientboundServerDataPacket = (ClientboundServerDataPacket) o; - return new ClientboundServerDataPacket(clientboundServerDataPacket.b().get(),clientboundServerDataPacket.c().get(),true); + try{ + o.getClass().getDeclaredField("c").setBoolean(clientboundServerDataPacket,true); + }catch (NoSuchFieldException | IllegalAccessException e) { + //ignore + } + return clientboundServerDataPacket; } } From 3ca4a7d99f2d2eae3bbbdaacb6541a8db828a202 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 6 Aug 2022 21:30:24 +0200 Subject: [PATCH 5/7] Reflections --- SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java index e883f54..38393ba 100644 --- a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java @@ -26,6 +26,9 @@ import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.protocol.game.ClientboundServerDataPacket; public class ChatWrapper19 implements ChatWrapper { + + private static final Reflection.FieldAccessor accessor = Reflection.getField(ClientboundServerDataPacket.class, "c",Boolean.class); + @Override public Object stringToChatComponent(String text) { return IChatMutableComponent.a(new LiteralContents(text)); @@ -40,11 +43,7 @@ public class ChatWrapper19 implements ChatWrapper { @Override public Object modifyServerDataPacket(Object o) { ClientboundServerDataPacket clientboundServerDataPacket = (ClientboundServerDataPacket) o; - try{ - o.getClass().getDeclaredField("c").setBoolean(clientboundServerDataPacket,true); - }catch (NoSuchFieldException | IllegalAccessException e) { - //ignore - } + accessor.set(clientboundServerDataPacket,true); return clientboundServerDataPacket; } } From c2cc19450dd9f76364621bd70185dd85940c9113 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 6 Aug 2022 21:34:08 +0200 Subject: [PATCH 6/7] use class type --- SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java index 38393ba..c4ca415 100644 --- a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java @@ -27,7 +27,7 @@ import net.minecraft.network.protocol.game.ClientboundServerDataPacket; public class ChatWrapper19 implements ChatWrapper { - private static final Reflection.FieldAccessor accessor = Reflection.getField(ClientboundServerDataPacket.class, "c",Boolean.class); + private static final Reflection.FieldAccessor accessor = Reflection.getField(ClientboundServerDataPacket.class, Boolean.class,0); @Override public Object stringToChatComponent(String text) { From e2652fc25addac7192261dded43aa8ef20800d99 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 6 Aug 2022 22:53:29 +0200 Subject: [PATCH 7/7] use right class --- SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java index c4ca415..d25e410 100644 --- a/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java +++ b/SpigotCore_19/src/de/steamwar/core/ChatWrapper19.java @@ -27,7 +27,7 @@ import net.minecraft.network.protocol.game.ClientboundServerDataPacket; public class ChatWrapper19 implements ChatWrapper { - private static final Reflection.FieldAccessor accessor = Reflection.getField(ClientboundServerDataPacket.class, Boolean.class,0); + private static final Reflection.FieldAccessor accessor = Reflection.getField(ClientboundServerDataPacket.class, boolean.class,0); @Override public Object stringToChatComponent(String text) {