SteamWar/BungeeCore
Archiviert
13
2

Tablist #411

Zusammengeführt
Lixfel hat 13 Commits von tablist nach master 2022-06-18 15:31:48 +02:00 zusammengeführt
2 geänderte Dateien mit 14 neuen und 9 gelöschten Zeilen
Nur Änderungen aus Commit f7fbefec82 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bungeecore.tablist;
import de.steamwar.bungeecore.Storage;
import de.steamwar.messages.ChatSender;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
@ -48,7 +49,7 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
private static final String TAB_TEAM = "»SW-Tab";
private static final Team teamPacket = new Team(TAB_TEAM, (byte) 0, ComponentSerializer.toString(TextComponent.fromLegacyText("")), ComponentSerializer.toString(TextComponent.fromLegacyText("")), ComponentSerializer.toString(TextComponent.fromLegacyText("")), "never", "never", 21, (byte)0x00, names);
private final Map<UUID, PlayerListItem.Item> directlySent = new HashMap<>(); //TODO Persist over softreload
private final Map<UUID, PlayerListItem.Item> directTabItems;
private final Set<UUID> npcs = new HashSet<>();
private final List<PlayerListItem.Item> current = new ArrayList<>();
@ -59,6 +60,7 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
public Tablist(ProxiedPlayer player) {
this.player = player;
this.viewer = ChatSender.of(player);
this.directTabItems = Storage.directTabItems.computeIfAbsent(player, p -> new HashMap<>());
onServerSwitch();
}
@ -81,9 +83,9 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
List<PlayerListItem.Item> update = new ArrayList<>();
for (TablistPart.Item item : direct) {
if(npcs.remove(item.getUuid()))
removeNpc.add(directlySent.get(item.getUuid()).getUsername());
removeNpc.add(directTabItems.get(item.getUuid()).getUsername());
PlayerListItem.Item tabItem = directlySent.get(item.getUuid());
PlayerListItem.Item tabItem = directTabItems.get(item.getUuid());
if(tabItem == null) {
tablist.add(0, item);
} else if(!tabItem.getDisplayName().equals(item.getDisplayName())) {
@ -92,7 +94,7 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
}
}
Set<UUID> nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
for(PlayerListItem.Item item : directlySent.values()) {
for(PlayerListItem.Item item : directTabItems.values()) {
if(!nonNPCs.contains(item.getUuid()) && !npcs.contains(item.getUuid()))
addNpc.add(item.getUsername());
}
@ -138,8 +140,8 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
public void onServerSwitch() {
connection = (ServerConnection) player.getServer();
directlySent.clear();
sendNpcPacket(npcs.stream().map(npc -> directlySent.get(npc).getUsername()).collect(Collectors.toList()), true);
directTabItems.clear();
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
npcs.clear();
if(connection != null) {
@ -151,7 +153,7 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
public void remove() {
sendTabPacket(current, PlayerListItem.Action.REMOVE_PLAYER);
current.clear();
sendNpcPacket(npcs.stream().map(npc -> directlySent.get(npc).getUsername()).collect(Collectors.toList()), true);
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
npcs.clear();
}
@ -189,12 +191,12 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3)
item.setGamemode(1);
directlySent.put(item.getUuid(), item);
directTabItems.put(item.getUuid(), item);
}
break;
case REMOVE_PLAYER:
for(PlayerListItem.Item item : list.getItems()) {
directlySent.remove(item.getUuid());
directTabItems.remove(item.getUuid());
npcs.remove(item.getUuid());
}
break;

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bungeecore.tablist;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Storage;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.listeners.BasicListener;
import de.steamwar.network.packets.common.FightInfoPacket;
@ -56,6 +57,7 @@ public class TablistManager extends BasicListener {
@EventHandler
public void onJoin(PostLoginEvent event) {
synchronized (tablists) {
Storage.directTabItems.put(event.getPlayer(), new HashMap<>());
tablists.put(event.getPlayer(), new Tablist(event.getPlayer()));
}
}
@ -71,6 +73,7 @@ public class TablistManager extends BasicListener {
public void onLeave(PlayerDisconnectEvent event) {
synchronized (tablists) {
tablists.remove(event.getPlayer());
Storage.directTabItems.remove(event.getPlayer());
}
}