SteamWar/BungeeCore
Archiviert
13
2

Fix Tablist for 1.21.
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <git-5w3l@lixfel.de>
Dieser Commit ist enthalten in:
Lixfel 2024-07-03 12:00:55 +02:00
Ursprung e7f0e57e9d
Commit 9c8ce57986
2 geänderte Dateien mit 11 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -26,12 +26,11 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.Connections; import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfoPacket; import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfoPacket;
import com.velocitypowered.proxy.protocol.packet.UpdateTeamsPacket;
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfoPacket; import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfoPacket;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import de.steamwar.messages.Chatter;
import de.steamwar.persistent.Storage; import de.steamwar.persistent.Storage;
import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.messages.Chatter;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
@ -41,19 +40,16 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@ChannelHandler.Sharable @ChannelHandler.Sharable
public class Tablist extends ChannelInboundHandlerAdapter { public class Tablist extends ChannelInboundHandlerAdapter {
private static final UUID[] swUuids = IntStream.range(0, 80).mapToObj(i -> UUID.randomUUID()).toArray(UUID[]::new); private static final UUID[] swUuids = IntStream.range(0, 80).mapToObj(i -> UUID.randomUUID()).toArray(UUID[]::new);
private static final String[] swNames = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new); public static final String[] swNames = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new);
private static final String TAB_TEAM = "zzzzzsw-tab"; public static final String TAB_TEAM = "zzzzzsw-tab";
private static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacket(TAB_TEAM, UpdateTeamsPacket.Mode.CREATE, Component.empty(), Component.empty(), Component.empty(), UpdateTeamsPacket.NameTagVisibility.NEVER, UpdateTeamsPacket.CollisionRule.ALWAYS, 21, (byte)0x00, Arrays.stream(swNames).toList());
private final Map<UUID, UpsertPlayerInfoPacket.Entry> directTabItems; private final Map<UUID, UpsertPlayerInfoPacket.Entry> directTabItems;
private final Set<UUID> npcs = new HashSet<>();
private final List<UpsertPlayerInfoPacket.Entry> current = new ArrayList<>(); private final List<UpsertPlayerInfoPacket.Entry> current = new ArrayList<>();
private final Player player; private final Player player;
@ -78,17 +74,11 @@ public class Tablist extends ChannelInboundHandlerAdapter {
global.print(viewer, player, tablist, direct); global.print(viewer, player, tablist, direct);
// NPC handling // NPC handling
List<String> addNpc = new ArrayList<>();
List<String> removeNpc = new ArrayList<>();
List<UpsertPlayerInfoPacket.Entry> update = new ArrayList<>(); List<UpsertPlayerInfoPacket.Entry> update = new ArrayList<>();
Set<UUID> nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
synchronized (directTabItems) { synchronized (directTabItems) {
for (TablistPart.Item item : direct) { for (TablistPart.Item item : direct) {
UpsertPlayerInfoPacket.Entry tabItem = directTabItems.get(item.getUuid()); UpsertPlayerInfoPacket.Entry tabItem = directTabItems.get(item.getUuid());
if(npcs.remove(item.getUuid()))
removeNpc.add(tabItem.getProfile().getName());
if(tabItem == null) { if(tabItem == null) {
tablist.add(0, item); tablist.add(0, item);
} else if(!item.getDisplayName().equals(getDisplayName(tabItem))) { } else if(!item.getDisplayName().equals(getDisplayName(tabItem))) {
@ -97,16 +87,7 @@ public class Tablist extends ChannelInboundHandlerAdapter {
update.add(tabItem); update.add(tabItem);
} }
} }
boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(connection.getServerInfo());
for(UpsertPlayerInfoPacket.Entry item : directTabItems.values()) {
if(playerNotOnTeamserver && !nonNPCs.contains(item.getProfileId()) && !npcs.contains(item.getProfileId()) && !player.getUniqueId().equals(item.getProfileId())) {
npcs.add(item.getProfileId());
addNpc.add(item.getProfile().getName());
}
}
} }
sendNpcPacket(addNpc, false);
sendNpcPacket(removeNpc, true);
// Main list handling // Main list handling
int i = 0; int i = 0;
@ -153,9 +134,7 @@ public class Tablist extends ChannelInboundHandlerAdapter {
injection(); injection();
synchronized (directTabItems) { synchronized (directTabItems) {
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getProfile().getName()).toList(), true);
directTabItems.clear(); directTabItems.clear();
npcs.clear();
} }
} }
@ -169,16 +148,11 @@ public class Tablist extends ChannelInboundHandlerAdapter {
pipeline.remove("steamwar-tablist"); pipeline.remove("steamwar-tablist");
pipeline.addBefore(Connections.HANDLER, "steamwar-tablist", this); pipeline.addBefore(Connections.HANDLER, "steamwar-tablist", this);
sendPacket(player, createTeamPacket);
} }
public void disable() { public void disable() {
sendTabPacket(current, null); sendTabPacket(current, null);
current.clear(); current.clear();
synchronized (directTabItems) {
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getProfile().getName()).toList(), true);
npcs.clear();
}
if(connection != null) if(connection != null)
connection.getConnection().getChannel().pipeline().remove(this); connection.getConnection().getChannel().pipeline().remove(this);
@ -226,15 +200,11 @@ public class Tablist extends ChannelInboundHandlerAdapter {
} }
} }
} else if(msg instanceof RemovePlayerInfoPacket packet) { } else if(msg instanceof RemovePlayerInfoPacket packet) {
List<String> names = new ArrayList<>();
for(UUID uuid : packet.getProfilesToRemove()) { for(UUID uuid : packet.getProfilesToRemove()) {
synchronized (directTabItems) { synchronized (directTabItems) {
UpsertPlayerInfoPacket.Entry directItem = directTabItems.remove(uuid); directTabItems.remove(uuid);
if(npcs.remove(uuid))
names.add(directItem.getProfile().getName());
} }
} }
sendNpcPacket(names, true);
} }
ctx.fireChannelRead(msg); ctx.fireChannelRead(msg);
@ -255,16 +225,6 @@ public class Tablist extends ChannelInboundHandlerAdapter {
)); ));
} }
private void sendNpcPacket(List<String> names, boolean remove) {
if(!names.isEmpty()) {
UpdateTeamsPacket packet = new UpdateTeamsPacket();
packet.setName(TAB_TEAM);
packet.setMode(remove ? UpdateTeamsPacket.Mode.REMOVE_PLAYER : UpdateTeamsPacket.Mode.ADD_PLAYER);
packet.setPlayers(names);
sendPacket(player, packet);
}
}
private Component header(Chatter p, int seconds) { private Component header(Chatter p, int seconds) {
int phase = (seconds % 10) / 5; int phase = (seconds % 10) / 5;
if (phase == 0) if (phase == 0)
@ -292,7 +252,7 @@ public class Tablist extends ChannelInboundHandlerAdapter {
return displayName.getComponent(); return displayName.getComponent();
} }
private static void sendPacket(Player player, MinecraftPacket packet) { public static void sendPacket(Player player, MinecraftPacket packet) {
((ConnectedPlayer) player).getConnection().write(packet); ((ConnectedPlayer) player).getConnection().write(packet);
} }
} }

Datei anzeigen

@ -25,17 +25,16 @@ import com.velocitypowered.api.event.connection.PostLoginEvent;
import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.proxy.protocol.packet.UpdateTeamsPacket;
import de.steamwar.persistent.Servertype; import de.steamwar.persistent.Servertype;
import de.steamwar.persistent.Storage; import de.steamwar.persistent.Storage;
import de.steamwar.persistent.Subserver; import de.steamwar.persistent.Subserver;
import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.velocitycore.listeners.BasicListener; import de.steamwar.velocitycore.listeners.BasicListener;
import de.steamwar.network.packets.common.FightInfoPacket; import de.steamwar.network.packets.common.FightInfoPacket;
import net.kyori.adventure.text.Component;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class TablistManager extends BasicListener { public class TablistManager extends BasicListener {
@ -47,6 +46,8 @@ public class TablistManager extends BasicListener {
fightInfos.keySet().removeIf(serverInfo -> serverInfo.getPlayersConnected().isEmpty()); fightInfos.keySet().removeIf(serverInfo -> serverInfo.getPlayersConnected().isEmpty());
} }
private static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacket(Tablist.TAB_TEAM, UpdateTeamsPacket.Mode.CREATE, Component.empty(), Component.empty(), Component.empty(), UpdateTeamsPacket.NameTagVisibility.NEVER, UpdateTeamsPacket.CollisionRule.ALWAYS, 21, (byte)0x00, Arrays.stream(Tablist.swNames).toList());
private final Map<Player, Tablist> tablists = new HashMap<>(); private final Map<Player, Tablist> tablists = new HashMap<>();
private int seconds = 0; private int seconds = 0;
@ -60,6 +61,7 @@ public class TablistManager extends BasicListener {
@Subscribe @Subscribe
public void onJoin(PostLoginEvent event) { public void onJoin(PostLoginEvent event) {
Tablist.sendPacket(event.getPlayer(), createTeamPacket);
synchronized (tablists) { synchronized (tablists) {
tablists.put(event.getPlayer(), new Tablist(event.getPlayer())); tablists.put(event.getPlayer(), new Tablist(event.getPlayer()));
} }