From a177cc4fafcbe4d5a42214c42ec2c07fa5a3f7b6 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 21 May 2026 09:54:48 +0200 Subject: [PATCH] Fix Tablist Add UpdateTeamsPacketImpl back --- .../velocitycore/tablist/Tablist.java | 2 +- .../tablist/UpdateTeamsPacketImpl.java | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacketImpl.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 8b53a1f9..0fb7b202 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -51,7 +51,7 @@ 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); - public static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacket("zzzzzsw-tab", UpdateTeamsPacket.Mode.CREATE, Component.empty(), Component.empty(), Component.empty(), UpdateTeamsPacket.NameTagVisibility.NEVER, UpdateTeamsPacket.CollisionRule.ALWAYS, 21, (byte) 0x00, Arrays.stream(Tablist.swNames).toList()); + public static final UpdateTeamsPacket createTeamPacket = new UpdateTeamsPacketImpl("zzzzzsw-tab", 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 directTabItems; private final List current = new ArrayList<>(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacketImpl.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacketImpl.java new file mode 100644 index 00000000..998658c5 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/UpdateTeamsPacketImpl.java @@ -0,0 +1,76 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2026 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.velocitycore.tablist; + +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.UpdateTeamsPacket; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; +import io.netty.buffer.ByteBuf; +import net.kyori.adventure.text.Component; + +import java.util.List; + +public class UpdateTeamsPacketImpl extends UpdateTeamsPacket { + + public UpdateTeamsPacketImpl(String name, Mode mode, Component displayName, Component prefix, Component suffix, NameTagVisibility nameTagVisibility, CollisionRule collisionRule, int color, byte friendlyFlags, List players) { + super(name, mode, displayName, prefix, suffix, nameTagVisibility, collisionRule, color, friendlyFlags, players); + } + + @Override + public void encode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { + ProtocolUtils.writeString(byteBuf, name); + byteBuf.writeByte(mode.ordinal()); + + switch (mode) { + case CREATE, UPDATE: + new ComponentHolder(protocolVersion, displayName).write(byteBuf); + if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_13)) { + new ComponentHolder(protocolVersion, prefix).write(byteBuf); + new ComponentHolder(protocolVersion, suffix).write(byteBuf); + } + + byteBuf.writeByte(friendlyFlags); + if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_21_5)) { + ProtocolUtils.writeVarInt(byteBuf, nameTagVisibility.ordinal()); + ProtocolUtils.writeVarInt(byteBuf, collisionRule.ordinal()); + } else { + ProtocolUtils.writeString(byteBuf, nameTagVisibility.getValue()); + ProtocolUtils.writeString(byteBuf, collisionRule.getValue()); + } + if (protocolVersion.greaterThan(ProtocolVersion.MINECRAFT_1_12_2)) { + ProtocolUtils.writeVarInt(byteBuf, color); + new ComponentHolder(protocolVersion, prefix).write(byteBuf); + new ComponentHolder(protocolVersion, suffix).write(byteBuf); + } else { + byteBuf.writeByte((byte) color); + } + // Fallthrough since players are at the end of the packet! + case ADD_PLAYER, REMOVE_PLAYER: + ProtocolUtils.writeVarInt(byteBuf, players.size()); + for (String player : players) { + ProtocolUtils.writeString(byteBuf, player); + } + break; + case REMOVE: + break; + } + } +}