Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
129e41cb77
Commit
cc01a4132d
@ -81,11 +81,14 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
||||
List<String> addNpc = new ArrayList<>();
|
||||
List<String> removeNpc = 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) {
|
||||
if(npcs.remove(item.getUuid()))
|
||||
removeNpc.add(directTabItems.get(item.getUuid()).getUsername());
|
||||
|
||||
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())) {
|
||||
@ -93,17 +96,18 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
sendNpcPacket(addNpc, false);
|
||||
sendNpcPacket(removeNpc, true);
|
||||
|
||||
// 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();
|
||||
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();
|
||||
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);
|
||||
|
||||
synchronized (directTabItems) {
|
||||
directTabItems.put(item.getUuid(), item);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REMOVE_PLAYER:
|
||||
for(PlayerListItem.Item item : list.getItems()) {
|
||||
synchronized (directTabItems) {
|
||||
directTabItems.remove(item.getUuid());
|
||||
}
|
||||
npcs.remove(item.getUuid());
|
||||
}
|
||||
break;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren