Archiviert
1
0

Test fix tablist

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