From 055aaa2acad58a954d441489168fbb17bd8f3ad4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 12:06:12 +0100 Subject: [PATCH 1/2] Untested tablist name handling Signed-off-by: Lixfel --- .../bungeecore/comms/PacketIdManager.java | 2 ++ .../bungeecore/comms/SpigotReceiver.java | 2 ++ .../comms/handlers/TablistNameHandler.java | 21 +++++++++++++++++++ .../bungeecore/listeners/TablistManager.java | 4 ++++ 4 files changed, 29 insertions(+) create mode 100644 src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java diff --git a/src/de/steamwar/bungeecore/comms/PacketIdManager.java b/src/de/steamwar/bungeecore/comms/PacketIdManager.java index 32d25e3..349c24e 100644 --- a/src/de/steamwar/bungeecore/comms/PacketIdManager.java +++ b/src/de/steamwar/bungeecore/comms/PacketIdManager.java @@ -23,6 +23,8 @@ public class PacketIdManager { //0x0(X) Standalone Packets public final static byte PING_PACKET = 0x01; + public final static byte TABLIST_NAME = 0x02; + //0x1(X) Bungee Inventory public final static byte INVENTORY_PACKET = 0x10; public final static byte INVENTORY_CALLBACK_PACKET = 0x11; diff --git a/src/de/steamwar/bungeecore/comms/SpigotReceiver.java b/src/de/steamwar/bungeecore/comms/SpigotReceiver.java index 9a8da48..b18b3a0 100644 --- a/src/de/steamwar/bungeecore/comms/SpigotReceiver.java +++ b/src/de/steamwar/bungeecore/comms/SpigotReceiver.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.comms; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; import de.steamwar.bungeecore.comms.handlers.InventoryCallbackHandler; +import de.steamwar.bungeecore.comms.handlers.TablistNameHandler; import de.steamwar.bungeecore.listeners.BasicListener; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.event.EventHandler; @@ -53,5 +54,6 @@ public class SpigotReceiver extends BasicListener { static { registerHandler(PacketIdManager.INVENTORY_CALLBACK_PACKET, new InventoryCallbackHandler()); + registerHandler(PacketIdManager.TABLIST_NAME, new TablistNameHandler()); } } diff --git a/src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java b/src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java new file mode 100644 index 0000000..bd5acbc --- /dev/null +++ b/src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java @@ -0,0 +1,21 @@ +package de.steamwar.bungeecore.comms.handlers; + +import com.google.common.io.ByteArrayDataInput; +import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.comms.SpigotHandler; +import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class TablistNameHandler implements SpigotHandler { + + @Override + public void handle(ByteArrayDataInput byteArrayDataInput) { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer( + SteamwarUser.get( + byteArrayDataInput.readInt() + ).getUuid() + ); + Subserver.getSubserver(player).getTablistNames().set(player, byteArrayDataInput.readUTF()); + } +} diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index d79be22..7f5d354 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -196,6 +196,10 @@ public class TablistManager extends BasicListener { } private String getTablistName(ProxiedPlayer p, boolean sameServer) { + String tablistName = Subserver.getSubserver(p).getTablistNames().get(p); + if(tablistName != null) + return tablistName; + StringBuilder st = new StringBuilder(); if (p.hasPermission("bungeecore.group.admin")) st.append("§4"); else if (p.hasPermission("bungeecore.group.developer")) st.append("§3"); From c2f3ab8094e833a11843cd8f798b10a5c3dcba73 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 20:54:25 +0100 Subject: [PATCH 2/2] Fix errors in impl. Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/comms/PacketIdManager.java | 11 ++++++----- .../bungeecore/comms/handlers/TablistNameHandler.java | 8 ++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/de/steamwar/bungeecore/comms/PacketIdManager.java b/src/de/steamwar/bungeecore/comms/PacketIdManager.java index 349c24e..b2c3300 100644 --- a/src/de/steamwar/bungeecore/comms/PacketIdManager.java +++ b/src/de/steamwar/bungeecore/comms/PacketIdManager.java @@ -20,13 +20,14 @@ package de.steamwar.bungeecore.comms; public class PacketIdManager { + private PacketIdManager(){} //0x0(X) Standalone Packets - public final static byte PING_PACKET = 0x01; - public final static byte TABLIST_NAME = 0x02; + public static final byte PING_PACKET = 0x01; + public static final byte TABLIST_NAME = 0x02; //0x1(X) Bungee Inventory - public final static byte INVENTORY_PACKET = 0x10; - public final static byte INVENTORY_CALLBACK_PACKET = 0x11; - public final static byte INVENTORY_CLOSE_PACKET = 0x12; + public static final byte INVENTORY_PACKET = 0x10; + public static final byte INVENTORY_CALLBACK_PACKET = 0x11; + public static final byte INVENTORY_CLOSE_PACKET = 0x12; } diff --git a/src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java b/src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java index bd5acbc..6f04943 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/TablistNameHandler.java @@ -11,11 +11,7 @@ public class TablistNameHandler implements SpigotHandler { @Override public void handle(ByteArrayDataInput byteArrayDataInput) { - ProxiedPlayer player = ProxyServer.getInstance().getPlayer( - SteamwarUser.get( - byteArrayDataInput.readInt() - ).getUuid() - ); - Subserver.getSubserver(player).getTablistNames().set(player, byteArrayDataInput.readUTF()); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUuid()); + Subserver.getSubserver(player).getTablistNames().put(player, byteArrayDataInput.readUTF()); } }