geforkt von SteamWar/BungeeCore
Make Tablist softreloadable
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
616062354f
Commit
f7fbefec82
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.tablist;
|
package de.steamwar.bungeecore.tablist;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.Storage;
|
||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.ChatSender;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
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 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 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 Set<UUID> npcs = new HashSet<>();
|
||||||
private final List<PlayerListItem.Item> current = new ArrayList<>();
|
private final List<PlayerListItem.Item> current = new ArrayList<>();
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
|||||||
public Tablist(ProxiedPlayer player) {
|
public Tablist(ProxiedPlayer player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.viewer = ChatSender.of(player);
|
this.viewer = ChatSender.of(player);
|
||||||
|
this.directTabItems = Storage.directTabItems.computeIfAbsent(player, p -> new HashMap<>());
|
||||||
onServerSwitch();
|
onServerSwitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,9 +83,9 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
|||||||
List<PlayerListItem.Item> update = new ArrayList<>();
|
List<PlayerListItem.Item> update = new ArrayList<>();
|
||||||
for (TablistPart.Item item : direct) {
|
for (TablistPart.Item item : direct) {
|
||||||
if(npcs.remove(item.getUuid()))
|
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) {
|
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())) {
|
||||||
@ -92,7 +94,7 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<UUID> nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
|
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()))
|
if(!nonNPCs.contains(item.getUuid()) && !npcs.contains(item.getUuid()))
|
||||||
addNpc.add(item.getUsername());
|
addNpc.add(item.getUsername());
|
||||||
}
|
}
|
||||||
@ -138,8 +140,8 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
|||||||
|
|
||||||
public void onServerSwitch() {
|
public void onServerSwitch() {
|
||||||
connection = (ServerConnection) player.getServer();
|
connection = (ServerConnection) player.getServer();
|
||||||
directlySent.clear();
|
directTabItems.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();
|
npcs.clear();
|
||||||
|
|
||||||
if(connection != null) {
|
if(connection != null) {
|
||||||
@ -151,7 +153,7 @@ public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
|||||||
public void remove() {
|
public void remove() {
|
||||||
sendTabPacket(current, PlayerListItem.Action.REMOVE_PLAYER);
|
sendTabPacket(current, PlayerListItem.Action.REMOVE_PLAYER);
|
||||||
current.clear();
|
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();
|
npcs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,12 +191,12 @@ 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);
|
||||||
|
|
||||||
directlySent.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()) {
|
||||||
directlySent.remove(item.getUuid());
|
directTabItems.remove(item.getUuid());
|
||||||
npcs.remove(item.getUuid());
|
npcs.remove(item.getUuid());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -21,6 +21,7 @@ package de.steamwar.bungeecore.tablist;
|
|||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
import de.steamwar.bungeecore.Servertype;
|
import de.steamwar.bungeecore.Servertype;
|
||||||
|
import de.steamwar.bungeecore.Storage;
|
||||||
import de.steamwar.bungeecore.Subserver;
|
import de.steamwar.bungeecore.Subserver;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||||
import de.steamwar.network.packets.common.FightInfoPacket;
|
import de.steamwar.network.packets.common.FightInfoPacket;
|
||||||
@ -56,6 +57,7 @@ public class TablistManager extends BasicListener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PostLoginEvent event) {
|
public void onJoin(PostLoginEvent event) {
|
||||||
synchronized (tablists) {
|
synchronized (tablists) {
|
||||||
|
Storage.directTabItems.put(event.getPlayer(), new HashMap<>());
|
||||||
tablists.put(event.getPlayer(), new Tablist(event.getPlayer()));
|
tablists.put(event.getPlayer(), new Tablist(event.getPlayer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,6 +73,7 @@ public class TablistManager extends BasicListener {
|
|||||||
public void onLeave(PlayerDisconnectEvent event) {
|
public void onLeave(PlayerDisconnectEvent event) {
|
||||||
synchronized (tablists) {
|
synchronized (tablists) {
|
||||||
tablists.remove(event.getPlayer());
|
tablists.remove(event.getPlayer());
|
||||||
|
Storage.directTabItems.remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren