Skip to content

Commit

Permalink
update for latest BungeeCord; see #735
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCrafter47 committed Nov 8, 2023
1 parent aa5ccb9 commit 9c56d1b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,6 +181,8 @@ public abstract class AbstractTabOverlayHandler implements PacketHandler, TabOve
private boolean is119OrLater;
protected boolean active;

private final Either<String, BaseComponent> emptyEither;

public AbstractTabOverlayHandler(Logger logger, Executor eventLoopExecutor, UUID viewerUuid, boolean is18, boolean is13OrLater, boolean is119OrLater) {
this.logger = logger;
this.eventLoopExecutor = eventLoopExecutor;
Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]}));
}
}

Expand All @@ -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++;
Expand Down Expand Up @@ -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]}));
Expand Down Expand Up @@ -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
Expand All @@ -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]);
Expand Down Expand Up @@ -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<String, BaseComponent> displayName, Either<String, BaseComponent> prefix, Either<String, BaseComponent> suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire, String[] players) {
Team team = new Team();
team.setName(name);
team.setMode((byte) 0);
Expand All @@ -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<String, BaseComponent> displayName, Either<String, BaseComponent> prefix, Either<String, BaseComponent> suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire) {
Team team = new Team();
team.setName(name);
team.setMode((byte) 2);
Expand Down Expand Up @@ -2543,9 +2551,9 @@ private PlayerListEntry(PlayerListItem.Item item) {

@Data
static class TeamEntry {
private BaseComponent displayName;
private BaseComponent prefix;
private BaseComponent suffix;
private Either<String, BaseComponent> displayName;
private Either<String, BaseComponent> prefix;
private Either<String, BaseComponent> suffix;
private byte friendlyFire;
private String nameTagVisibility;
private String collisionRule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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<String, BaseComponent> EMPTY_EITHER_TEXT_COMPONENT = Either.right(new TextComponent());
protected static final String[][] EMPTY_PROPERTIES_ARRAY = new String[0][];

private static final ImmutableMap<RectangularTabOverlay.Dimension, BitSet> DIMENSION_TO_USED_SLOTS;
Expand Down Expand Up @@ -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]}));
}
}
}
Expand Down Expand Up @@ -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<String, BaseComponent> displayName, Either<String, BaseComponent> prefix, Either<String, BaseComponent> suffix, String nameTagVisibility, String collisionRule, int color, byte friendlyFire, String[] players) {
Team team = new Team();
team.setName(name);
team.setMode((byte) 0);
Expand Down

0 comments on commit 9c56d1b

Please sign in to comment.