Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCrafter47 committed Jan 21, 2024
2 parents 160520d + 1d49f7b commit c3850cb
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
import lombok.val;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter;
import org.bstats.bungeecord.Metrics;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;
Expand Down Expand Up @@ -185,19 +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 #1671");
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 #1671");
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 #1671");
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 #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 @@ -572,7 +572,7 @@ protected <T> void addActiveKey(DataKey<T> key) {
try {
synchronized (this) {
Server connection = getConnection();
if (connection != null) {
if (connection != null && connection.isConnected()) {
if (!requestedDataKeys.contains(key)) {
requestedDataKeys.add(key);
ByteArrayDataOutput data = ByteStreams.newDataOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import lombok.AllArgsConstructor;
import lombok.val;
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 @@ -248,7 +250,7 @@ private void removeEntry(UUID uuid, String player) {
PlayerListItem.Item item = new PlayerListItem.Item();
item.setUuid(uuid);
item.setUsername(player);
item.setDisplayName(player);
item.setDisplayName(new TextComponent(player));
item.setPing(9999);
pli.setItems(new PlayerListItem.Item[]{item});
pli.setAction(PlayerListItem.Action.REMOVE_PLAYER);
Expand Down Expand Up @@ -312,7 +314,7 @@ void onActivated() {
for (val entry : serverPlayerList.object2IntEntrySet()) {
PlayerListItem pli = new PlayerListItem();
PlayerListItem.Item item = new PlayerListItem.Item();
item.setDisplayName(entry.getKey());
item.setDisplayName(new TextComponent(entry.getKey()));
item.setPing(entry.getIntValue());
pli.setItems(new PlayerListItem.Item[]{item});
pli.setAction(PlayerListItem.Action.ADD_PLAYER);
Expand Down Expand Up @@ -432,17 +434,12 @@ private void updateSize() {
Team t = new Team();
t.setName(slotID[index]);
t.setMode((byte) 0);
t.setPrefix(tabOverlay.text0[index]);
t.setDisplayName("");
t.setSuffix(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");
if (is13OrLater) {
t.setDisplayName(EMPTY_JSON_TEXT);
t.setPrefix("{\"text\":\"" + tabOverlay.text0[index] + "\"}");
t.setSuffix("{\"text\":\"" + tabOverlay.text1[index] + "\"}");
}
sendPacket(t);
}
} else {
Expand All @@ -464,7 +461,7 @@ private void updateSlot(CustomTabOverlay tabOverlay, int index) {
item.setUuid(slotUUID[index]);
item.setUsername(slotID[index]);
Property119Handler.setProperties(item, EMPTY_PROPERTIES);
item.setDisplayName(slotID[index]);
item.setDisplayName(new TextComponent(slotID[index]));
item.setPing(tabOverlay.ping[index]);
pli.setItems(new PlayerListItem.Item[]{item});
pli.setAction(PlayerListItem.Action.ADD_PLAYER);
Expand All @@ -476,16 +473,11 @@ private void updateText(CustomTabOverlay tabOverlay, int index) {
Team packet = new Team();
packet.setName(slotID[index]);
packet.setMode((byte) 2);
packet.setPrefix(tabOverlay.text0[index]);
packet.setDisplayName("");
packet.setSuffix(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");
if (is13OrLater) {
packet.setDisplayName(EMPTY_JSON_TEXT);
packet.setPrefix("{\"text\":\"" + tabOverlay.text0[index] + "\"}");
packet.setSuffix("{\"text\":\"" + tabOverlay.text1[index] + "\"}");
}
sendPacket(packet);
}
}
Expand Down Expand Up @@ -828,7 +820,7 @@ public boolean isValid() {
*/
private static String getName(PlayerListItem.Item item) {
if (item.getDisplayName() != null) {
return item.getDisplayName();
return item.getDisplayName().toLegacyText();
} else if (item.getUsername() != null) {
return item.getUsername();
} else {
Expand Down
Loading

0 comments on commit c3850cb

Please sign in to comment.