From 9c56d1b048ebff69837bf402025838690b8d5674 Mon Sep 17 00:00:00 2001 From: Florian Stober Date: Wed, 8 Nov 2023 10:22:54 +0100 Subject: [PATCH] update for latest BungeeCord; see #735 --- .../bungeetablistplus/BungeeTabListPlus.java | 14 +++++-- .../AbstractLegacyTabOverlayHandler.java | 13 +++--- .../handler/AbstractTabOverlayHandler.java | 40 +++++++++++-------- .../handler/NewTabOverlayHandler.java | 6 ++- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/bungee/src/main/java/codecrafter47/bungeetablistplus/BungeeTabListPlus.java b/bungee/src/main/java/codecrafter47/bungeetablistplus/BungeeTabListPlus.java index 7b8d6a52..e21efd0d 100644 --- a/bungee/src/main/java/codecrafter47/bungeetablistplus/BungeeTabListPlus.java +++ b/bungee/src/main/java/codecrafter47/bungeetablistplus/BungeeTabListPlus.java @@ -187,25 +187,31 @@ public void onLoad() { try { Class.forName("net.md_5.bungee.api.Title"); } catch (ClassNotFoundException ex) { - throw new RuntimeException("You need to run at least BungeeCord version #1760"); + throw new RuntimeException("You need to run at least BungeeCord version #1766"); } try { Connection.class.getMethod("isConnected"); } catch (NoSuchMethodException ex) { - throw new RuntimeException("You need to run at least BungeeCord version #1760"); + throw new RuntimeException("You need to run at least BungeeCord version #1766"); } try { Class.forName("net.md_5.bungee.protocol.packet.PlayerListItemUpdate"); } catch (ClassNotFoundException ex) { - throw new RuntimeException("You need to run at least BungeeCord version #1760"); + throw new RuntimeException("You need to run at least BungeeCord version #1766"); } try { PlayerListHeaderFooter.class.getMethod("setHeader", BaseComponent.class); } catch (NoSuchMethodException ex) { - throw new RuntimeException("You need to run at least BungeeCord version #1760"); + throw new RuntimeException("You need to run at least BungeeCord version #1766"); + } + + try { + Class.forName("net.md_5.bungee.protocol.Either"); + } catch (ClassNotFoundException ex) { + throw new RuntimeException("You need to run at least BungeeCord version #1766"); } INSTANCE = this; diff --git a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractLegacyTabOverlayHandler.java b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractLegacyTabOverlayHandler.java index f64528c2..1d6a018a 100644 --- a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractLegacyTabOverlayHandler.java +++ b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractLegacyTabOverlayHandler.java @@ -39,6 +39,7 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.Either; import net.md_5.bungee.protocol.packet.*; import javax.annotation.Nonnull; @@ -433,9 +434,9 @@ private void updateSize() { Team t = new Team(); t.setName(slotID[index]); t.setMode((byte) 0); - t.setPrefix(new TextComponent(tabOverlay.text0[index])); - t.setDisplayName(new TextComponent()); - t.setSuffix(new TextComponent(tabOverlay.text1[index])); + t.setPrefix(Either.left(tabOverlay.text0[index])); + t.setDisplayName(Either.left("")); + t.setSuffix(Either.left(tabOverlay.text1[index])); t.setPlayers(new String[]{slotID[index]}); t.setNameTagVisibility("always"); t.setCollisionRule("always"); @@ -472,9 +473,9 @@ private void updateText(CustomTabOverlay tabOverlay, int index) { Team packet = new Team(); packet.setName(slotID[index]); packet.setMode((byte) 2); - packet.setPrefix(new TextComponent(tabOverlay.text0[index])); - packet.setDisplayName(new TextComponent()); - packet.setSuffix(new TextComponent(tabOverlay.text1[index])); + packet.setPrefix(Either.left(tabOverlay.text0[index])); + packet.setDisplayName(Either.left("")); + packet.setSuffix(Either.left(tabOverlay.text1[index])); packet.setNameTagVisibility("always"); packet.setCollisionRule("always"); sendPacket(packet); diff --git a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractTabOverlayHandler.java b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractTabOverlayHandler.java index c9418ee9..61e51d03 100644 --- a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractTabOverlayHandler.java +++ b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/AbstractTabOverlayHandler.java @@ -36,6 +36,7 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.Either; import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter; import net.md_5.bungee.protocol.packet.PlayerListItem; import net.md_5.bungee.protocol.packet.Team; @@ -180,6 +181,8 @@ public abstract class AbstractTabOverlayHandler implements PacketHandler, TabOve private boolean is119OrLater; protected boolean active; + private final Either emptyEither; + public AbstractTabOverlayHandler(Logger logger, Executor eventLoopExecutor, UUID viewerUuid, boolean is18, boolean is13OrLater, boolean is119OrLater) { this.logger = logger; this.eventLoopExecutor = eventLoopExecutor; @@ -189,6 +192,11 @@ public AbstractTabOverlayHandler(Logger logger, Executor eventLoopExecutor, UUID this.is119OrLater = is119OrLater; this.activeContentHandler = new PassThroughContentHandler(); this.activeHeaderFooterHandler = new PassThroughHeaderFooterHandler(); + if (is13OrLater) { + emptyEither = Either.right(EMPTY_TEXT_COMPONENT); + } else { + emptyEither = Either.left(""); + } } protected abstract void sendPacket(DefinedPacket packet); @@ -975,7 +983,7 @@ PacketListenerResult onPlayerListPacket(PlayerListItem packet) { // 2. add player to correct team sendPacket(createPacketTeamAddPlayers(playerTeamName, new String[]{slotUsername[index]})); // 3. reset custom slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } } @@ -1051,7 +1059,7 @@ void onTeamPacketPreprocess(Team packet) { int slot = playerUsernameToSlotMap.getInt(playerName); if (slot != -1) { // reset slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[slot], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[slot], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } } } @@ -1129,7 +1137,7 @@ PacketListenerResult onTeamPacket(Team packet) { filteredPlayers[j++] = playerName; } else { // reset slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[slot], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[slot], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } } packet.setPlayers(filteredPlayers); @@ -1203,7 +1211,7 @@ void onServerSwitch() { // 1. remove player from team sendPacket(createPacketTeamRemovePlayers(CUSTOM_SLOT_TEAMNAME[index], new String[]{slotUsername[index]})); // reset slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } // 2. create new custom slot @@ -1306,12 +1314,12 @@ private void createTeamsIfNecessary() { if (!hasCreatedCustomTeams) { hasCreatedCustomTeams = true; - sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[0], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[0], CUSTOM_SLOT_USERNAME_SMILEYS[0], ""})); + sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[0], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[0], CUSTOM_SLOT_USERNAME_SMILEYS[0], ""})); for (int i = 1; i < 80; i++) { - sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[i], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[i], CUSTOM_SLOT_USERNAME_SMILEYS[i]})); + sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[i], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[i], CUSTOM_SLOT_USERNAME_SMILEYS[i]})); } - sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[80], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[80]})); + sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[80], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[80]})); } } @@ -1330,7 +1338,7 @@ void onDeactivated() { // 2. add player to correct team sendPacket(createPacketTeamAddPlayers(playerTeamName, new String[]{slotUsername[index]})); // 3. reset custom slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } } else { customSlots++; @@ -1462,7 +1470,7 @@ void update() { // 2. add player to correct team sendPacket(createPacketTeamAddPlayers(playerTeamName, new String[]{slotUsername[index]})); // 3. reset custom slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } else { // 2. add player to overflow team sendPacket(createPacketTeamAddPlayers(CUSTOM_SLOT_TEAMNAME[80], new String[]{slotUsername[index]})); @@ -1650,7 +1658,7 @@ void update() { playerUsernameToSlotMap.removeInt(slotUsername[index]); // reset slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } // 2. update slot state @@ -1671,7 +1679,7 @@ void update() { playerUsernameToSlotMap.removeInt(slotUsername[index]); // reset slot team - sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1)); + sendPacket(createPacketTeamUpdate(CUSTOM_SLOT_TEAMNAME[index], emptyEither, emptyEither, emptyEither, "always", "always", 21, (byte) 1)); } freePlayers.add(slotUuid[index]); @@ -2468,7 +2476,7 @@ private static String[][] toPropertiesArray(ProfileProperty textureProperty) { } } - private static Team createPacketTeamCreate(String name, BaseComponent displayName, BaseComponent prefix, BaseComponent suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire, String[] players) { + private static Team createPacketTeamCreate(String name, Either displayName, Either prefix, Either suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire, String[] players) { Team team = new Team(); team.setName(name); team.setMode((byte) 0); @@ -2490,7 +2498,7 @@ private static Team createPacketTeamRemove(String name) { return team; } - private static Team createPacketTeamUpdate(String name, BaseComponent displayName, BaseComponent prefix, BaseComponent suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire) { + private static Team createPacketTeamUpdate(String name, Either displayName, Either prefix, Either suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire) { Team team = new Team(); team.setName(name); team.setMode((byte) 2); @@ -2543,9 +2551,9 @@ private PlayerListEntry(PlayerListItem.Item item) { @Data static class TeamEntry { - private BaseComponent displayName; - private BaseComponent prefix; - private BaseComponent suffix; + private Either displayName; + private Either prefix; + private Either suffix; private byte friendlyFire; private String nameTagVisibility; private String collisionRule; diff --git a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java index b7bf2c21..82c296ad 100644 --- a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java +++ b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java @@ -40,6 +40,7 @@ import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.Either; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.*; @@ -62,6 +63,7 @@ public class NewTabOverlayHandler implements PacketHandler, TabOverlayHandler { private static final boolean OPTION_ENABLE_CUSTOM_SLOT_UUID_COLLISION_CHECK = true; private static final BaseComponent EMPTY_TEXT_COMPONENT = new TextComponent(); + private static final Either EMPTY_EITHER_TEXT_COMPONENT = Either.right(new TextComponent()); protected static final String[][] EMPTY_PROPERTIES_ARRAY = new String[0][]; private static final ImmutableMap DIMENSION_TO_USED_SLOTS; @@ -686,7 +688,7 @@ private void createTeamsIfNecessary() { hasCreatedCustomTeams = true; for (int i = 0; i < 80; i++) { - sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[i], EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, EMPTY_TEXT_COMPONENT, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[i], CUSTOM_SLOT_USERNAME_SMILEYS[i]})); + sendPacket(createPacketTeamCreate(CUSTOM_SLOT_TEAMNAME[i], EMPTY_EITHER_TEXT_COMPONENT, EMPTY_EITHER_TEXT_COMPONENT, EMPTY_EITHER_TEXT_COMPONENT, "always", "always", 21, (byte) 1, new String[]{CUSTOM_SLOT_USERNAME[i], CUSTOM_SLOT_USERNAME_SMILEYS[i]})); } } } @@ -1251,7 +1253,7 @@ private static String[][] toPropertiesArray(ProfileProperty textureProperty) { } } - private static Team createPacketTeamCreate(String name, BaseComponent displayName, BaseComponent prefix, BaseComponent suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire, String[] players) { + private static Team createPacketTeamCreate(String name, Either displayName, Either prefix, Either suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire, String[] players) { Team team = new Team(); team.setName(name); team.setMode((byte) 0);