SteamWar/BungeeCore
Archiviert
13
2

Test fix tablist
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2022-06-18 16:07:06 +02:00
Ursprung 129e41cb77
Commit cc01a4132d

Datei anzeigen

@ -81,11 +81,14 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
List<String> addNpc = new ArrayList<>(); List<String> addNpc = new ArrayList<>();
List<String> removeNpc = new ArrayList<>(); List<String> removeNpc = new ArrayList<>();
List<PlayerListItem.Item> update = new ArrayList<>(); List<PlayerListItem.Item> update = new ArrayList<>();
Set<UUID> nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
synchronized (directTabItems) {
for (TablistPart.Item item : direct) { for (TablistPart.Item item : direct) {
if(npcs.remove(item.getUuid()))
removeNpc.add(directTabItems.get(item.getUuid()).getUsername());
PlayerListItem.Item tabItem = directTabItems.get(item.getUuid()); PlayerListItem.Item tabItem = directTabItems.get(item.getUuid());
if(npcs.remove(item.getUuid()))
removeNpc.add(tabItem.getUsername());
if(tabItem == null) { if(tabItem == null) {
tablist.add(0, item); tablist.add(0, item);
} else if(!tabItem.getDisplayName().equals(item.getDisplayName())) { } else if(!tabItem.getDisplayName().equals(item.getDisplayName())) {
@ -93,17 +96,18 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
update.add(tabItem); update.add(tabItem);
} }
} }
Set<UUID> nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
for(PlayerListItem.Item item : directTabItems.values()) { for(PlayerListItem.Item item : directTabItems.values()) {
if(!nonNPCs.contains(item.getUuid()) && !npcs.contains(item.getUuid())) if(!nonNPCs.contains(item.getUuid()) && !npcs.contains(item.getUuid()))
addNpc.add(item.getUsername()); addNpc.add(item.getUsername());
} }
}
sendNpcPacket(addNpc, false); sendNpcPacket(addNpc, false);
sendNpcPacket(removeNpc, true); sendNpcPacket(removeNpc, true);
// Main list handling // Main list handling
int i = 0; int i = 0;
List<PlayerListItem.Item> add = new ArrayList<>(); List<PlayerListItem.Item> add = new ArrayList<>();
List<PlayerListItem.Item> remove = new ArrayList<>();
for (; i < tablist.size() && i < 80; i++) { for (; i < tablist.size() && i < 80; i++) {
PlayerListItem.Item tabItem; PlayerListItem.Item tabItem;
if(current.size() > i) { if(current.size() > i) {
@ -119,6 +123,8 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
TablistPart.Item item = tablist.get(i); TablistPart.Item item = tablist.get(i);
if(!Arrays.equals(tabItem.getProperties(), item.getProperties())) { if(!Arrays.equals(tabItem.getProperties(), item.getProperties())) {
if(tabItem.getProperties() != null)
remove.add(tabItem);
tabItem.setProperties(item.getProperties()); tabItem.setProperties(item.getProperties());
tabItem.setDisplayName(item.getDisplayName()); tabItem.setDisplayName(item.getDisplayName());
add.add(tabItem); add.add(tabItem);
@ -127,21 +133,22 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
update.add(tabItem); update.add(tabItem);
} }
} }
sendTabPacket(add, PlayerListItem.Action.ADD_PLAYER);
sendTabPacket(update, PlayerListItem.Action.UPDATE_DISPLAY_NAME); sendTabPacket(update, PlayerListItem.Action.UPDATE_DISPLAY_NAME);
// Excess removal // Excess removal
List<PlayerListItem.Item> remove = new ArrayList<>();
while(i < current.size()) { while(i < current.size()) {
remove.add(current.remove(i)); remove.add(current.remove(i));
} }
sendTabPacket(remove, PlayerListItem.Action.REMOVE_PLAYER); sendTabPacket(remove, PlayerListItem.Action.REMOVE_PLAYER);
sendTabPacket(add, PlayerListItem.Action.ADD_PLAYER);
} }
public void onServerSwitch() { public void onServerSwitch() {
connection = (ServerConnection) player.getServer(); connection = (ServerConnection) player.getServer();
synchronized (directTabItems) {
directTabItems.clear(); directTabItems.clear();
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true); sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
}
npcs.clear(); npcs.clear();
if(connection != null) { if(connection != null) {
@ -153,7 +160,9 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
public void disable() { public void disable() {
sendTabPacket(current, PlayerListItem.Action.REMOVE_PLAYER); sendTabPacket(current, PlayerListItem.Action.REMOVE_PLAYER);
current.clear(); current.clear();
synchronized (directTabItems) {
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true); sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
}
npcs.clear(); npcs.clear();
if(connection != null) if(connection != null)
@ -194,12 +203,16 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3) if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3)
item.setGamemode(1); item.setGamemode(1);
synchronized (directTabItems) {
directTabItems.put(item.getUuid(), item); directTabItems.put(item.getUuid(), item);
} }
}
break; break;
case REMOVE_PLAYER: case REMOVE_PLAYER:
for(PlayerListItem.Item item : list.getItems()) { for(PlayerListItem.Item item : list.getItems()) {
synchronized (directTabItems) {
directTabItems.remove(item.getUuid()); directTabItems.remove(item.getUuid());
}
npcs.remove(item.getUuid()); npcs.remove(item.getUuid());
} }
break; break;