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.protocol.MinecraftPacket;
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.chat.ComponentHolder;
import de.steamwar.messages.Chatter;
import de.steamwar.persistent.Storage;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.messages.Chatter;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@ -41,19 +40,16 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ChannelHandler.Sharable
public class Tablist extends ChannelInboundHandlerAdapter {
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);
private 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());
public static final String[] swNames = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new);
public static final String TAB_TEAM = "zzzzzsw-tab";
private final Map<UUID, UpsertPlayerInfoPacket.Entry> directTabItems;
private final Set<UUID> npcs = new HashSet<>();
private final List<UpsertPlayerInfoPacket.Entry> current = new ArrayList<>();
private final Player player;
@ -78,17 +74,11 @@ public class Tablist extends ChannelInboundHandlerAdapter {
global.print(viewer, player, tablist, direct);
// NPC handling
List<String> addNpc = new ArrayList<>();
List<String> removeNpc = new ArrayList<>();
List<UpsertPlayerInfoPacket.Entry> update = new ArrayList<>();
Set<UUID> nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
synchronized (directTabItems) {
for (TablistPart.Item item : direct) {
UpsertPlayerInfoPacket.Entry tabItem = directTabItems.get(item.getUuid());
if(npcs.remove(item.getUuid()))
removeNpc.add(tabItem.getProfile().getName());
if(tabItem == null) {
tablist.add(0, item);
} else if(!item.getDisplayName().equals(getDisplayName(tabItem))) {
@ -97,16 +87,7 @@ public class Tablist extends ChannelInboundHandlerAdapter {
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
int i = 0;
@ -153,9 +134,7 @@ public class Tablist extends ChannelInboundHandlerAdapter {
injection();
synchronized (directTabItems) {
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getProfile().getName()).toList(), true);
directTabItems.clear();
npcs.clear();
}
}
@ -169,16 +148,11 @@ public class Tablist extends ChannelInboundHandlerAdapter {
pipeline.remove("steamwar-tablist");
pipeline.addBefore(Connections.HANDLER, "steamwar-tablist", this);
sendPacket(player, createTeamPacket);
}
public void disable() {
sendTabPacket(current, null);
current.clear();
synchronized (directTabItems) {
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getProfile().getName()).toList(), true);
npcs.clear();
}
if(connection != null)
connection.getConnection().getChannel().pipeline().remove(this);
@ -226,15 +200,11 @@ public class Tablist extends ChannelInboundHandlerAdapter {
}
}
} else if(msg instanceof RemovePlayerInfoPacket packet) {
List<String> names = new ArrayList<>();
for(UUID uuid : packet.getProfilesToRemove()) {
synchronized (directTabItems) {
UpsertPlayerInfoPacket.Entry directItem = directTabItems.remove(uuid);
if(npcs.remove(uuid))
names.add(directItem.getProfile().getName());
directTabItems.remove(uuid);
}
}
sendNpcPacket(names, true);
}
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) {
int phase = (seconds % 10) / 5;
if (phase == 0)
@ -292,7 +252,7 @@ public class Tablist extends ChannelInboundHandlerAdapter {
return displayName.getComponent();
}
private static void sendPacket(Player player, MinecraftPacket packet) {
public static void sendPacket(Player player, MinecraftPacket 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.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.proxy.protocol.packet.UpdateTeamsPacket;
import de.steamwar.persistent.Servertype;
import de.steamwar.persistent.Storage;
import de.steamwar.persistent.Subserver;
import de.steamwar.velocitycore.VelocityCore;
import de.steamwar.velocitycore.listeners.BasicListener;
import de.steamwar.network.packets.common.FightInfoPacket;
import net.kyori.adventure.text.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class TablistManager extends BasicListener {
@ -47,6 +46,8 @@ public class TablistManager extends BasicListener {
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 int seconds = 0;
@ -60,6 +61,7 @@ public class TablistManager extends BasicListener {
@Subscribe
public void onJoin(PostLoginEvent event) {
Tablist.sendPacket(event.getPlayer(), createTeamPacket);
synchronized (tablists) {
tablists.put(event.getPlayer(), new Tablist(event.getPlayer()));
}