From 8ae25521ddb1602ffc6088f7f4f5d3920ccda068 Mon Sep 17 00:00:00 2001 From: AlexDev_ <56083016+alexdev03@users.noreply.github.com> Date: Sat, 16 Sep 2023 11:53:50 +0200 Subject: [PATCH] Fix encode error on 1.20.1 (#90) * Added test debug * Fix issue https://github.com/WiIIiam278/Velocitab/issues/89 * Removed ViaVersion problem message * Re-Added final keyword on plugin parameter in UpdateTeamsPacket --- .../velocitab/packet/Protocol340Adapter.java | 26 ------------------- .../velocitab/packet/Protocol403Adapter.java | 26 ------------------- .../velocitab/packet/Protocol48Adapter.java | 25 ------------------ .../velocitab/packet/ScoreboardManager.java | 18 ++++++------- .../velocitab/packet/TeamsPacketAdapter.java | 2 -- .../velocitab/packet/UpdateTeamsPacket.java | 17 ++---------- 6 files changed, 11 insertions(+), 103 deletions(-) diff --git a/src/main/java/net/william278/velocitab/packet/Protocol340Adapter.java b/src/main/java/net/william278/velocitab/packet/Protocol340Adapter.java index 87027c5..a21d588 100644 --- a/src/main/java/net/william278/velocitab/packet/Protocol340Adapter.java +++ b/src/main/java/net/william278/velocitab/packet/Protocol340Adapter.java @@ -39,32 +39,6 @@ public class Protocol340Adapter extends TeamsPacketAdapter { super(Set.of(ProtocolVersion.MINECRAFT_1_12_2)); } - @Override - public void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) { - packet.teamName(ProtocolUtils.readString(byteBuf)); - UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte()); - if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) { - return; - } - if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) { - packet.displayName(ProtocolUtils.readString(byteBuf)); - packet.prefix(ProtocolUtils.readString(byteBuf)); - packet.suffix(ProtocolUtils.readString(byteBuf)); - packet.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte())); - packet.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf))); - packet.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf))); - packet.color(byteBuf.readByte()); - } - if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) { - int entityCount = ProtocolUtils.readVarInt(byteBuf); - List entities = new ArrayList<>(entityCount); - for (int j = 0; j < entityCount; j++) { - entities.add(ProtocolUtils.readString(byteBuf)); - } - packet.entities(entities); - } - } - @Override public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) { ProtocolUtils.writeString(byteBuf, packet.teamName().substring(0, Math.min(packet.teamName().length(), 16))); diff --git a/src/main/java/net/william278/velocitab/packet/Protocol403Adapter.java b/src/main/java/net/william278/velocitab/packet/Protocol403Adapter.java index 5e0d113..4dd339a 100644 --- a/src/main/java/net/william278/velocitab/packet/Protocol403Adapter.java +++ b/src/main/java/net/william278/velocitab/packet/Protocol403Adapter.java @@ -47,32 +47,6 @@ public class Protocol403Adapter extends TeamsPacketAdapter { )); } - @Override - public void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) { - packet.teamName(ProtocolUtils.readString(byteBuf)); - UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte()); - if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) { - return; - } - if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) { - packet.displayName(ProtocolUtils.readString(byteBuf)); - packet.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte())); - packet.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf))); - packet.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf))); - packet.color(byteBuf.readByte()); - packet.prefix(ProtocolUtils.readString(byteBuf)); - packet.suffix(ProtocolUtils.readString(byteBuf)); - } - if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) { - int entityCount = ProtocolUtils.readVarInt(byteBuf); - List entities = new ArrayList<>(entityCount); - for (int j = 0; j < entityCount; j++) { - entities.add(ProtocolUtils.readString(byteBuf)); - } - packet.entities(entities); - } - } - @Override public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) { ProtocolUtils.writeString(byteBuf, packet.teamName()); diff --git a/src/main/java/net/william278/velocitab/packet/Protocol48Adapter.java b/src/main/java/net/william278/velocitab/packet/Protocol48Adapter.java index fc9b166..121db9b 100644 --- a/src/main/java/net/william278/velocitab/packet/Protocol48Adapter.java +++ b/src/main/java/net/william278/velocitab/packet/Protocol48Adapter.java @@ -39,31 +39,6 @@ public class Protocol48Adapter extends TeamsPacketAdapter { super(Set.of(ProtocolVersion.MINECRAFT_1_8)); } - @Override - public void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) { - packet.teamName(ProtocolUtils.readString(byteBuf)); - UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte()); - if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) { - return; - } - if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) { - packet.displayName(ProtocolUtils.readString(byteBuf)); - packet.prefix(ProtocolUtils.readString(byteBuf)); - packet.suffix(ProtocolUtils.readString(byteBuf)); - packet.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte())); - packet.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf))); - packet.color(byteBuf.readByte()); - } - if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) { - int entityCount = ProtocolUtils.readVarInt(byteBuf); - List entities = new ArrayList<>(entityCount); - for (int j = 0; j < entityCount; j++) { - entities.add(ProtocolUtils.readString(byteBuf)); - } - packet.entities(entities); - } - } - @Override public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) { ProtocolUtils.writeString(byteBuf, packet.teamName().substring(0, Math.min(packet.teamName().length(), 16))); diff --git a/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java b/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java index 511cdca..cc0ae2c 100644 --- a/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java +++ b/src/main/java/net/william278/velocitab/packet/ScoreboardManager.java @@ -124,15 +124,15 @@ public class ScoreboardManager { .direction(ProtocolUtils.Direction.CLIENTBOUND) .packetSupplier(() -> new UpdateTeamsPacket(plugin)) .stateRegistry(StateRegistry.PLAY) - .mapping(0x3E, MINECRAFT_1_8, false) - .mapping(0x44, MINECRAFT_1_12_2, false) - .mapping(0x47, MINECRAFT_1_13, false) - .mapping(0x4B, MINECRAFT_1_14, false) - .mapping(0x4C, MINECRAFT_1_15, false) - .mapping(0x55, MINECRAFT_1_17, false) - .mapping(0x58, MINECRAFT_1_19_1, false) - .mapping(0x56, MINECRAFT_1_19_3, false) - .mapping(0x5A, MINECRAFT_1_19_4, false); + .mapping(0x3E, MINECRAFT_1_8, true) + .mapping(0x44, MINECRAFT_1_12_2, true) + .mapping(0x47, MINECRAFT_1_13, true) + .mapping(0x4B, MINECRAFT_1_14, true) + .mapping(0x4C, MINECRAFT_1_15, true) + .mapping(0x55, MINECRAFT_1_17, true) + .mapping(0x58, MINECRAFT_1_19_1, true) + .mapping(0x56, MINECRAFT_1_19_3, true) + .mapping(0x5A, MINECRAFT_1_19_4, true); packetRegistration.register(); } catch (Throwable e) { plugin.log(Level.ERROR, "Failed to register UpdateTeamsPacket", e); diff --git a/src/main/java/net/william278/velocitab/packet/TeamsPacketAdapter.java b/src/main/java/net/william278/velocitab/packet/TeamsPacketAdapter.java index 7004865..a20b31a 100644 --- a/src/main/java/net/william278/velocitab/packet/TeamsPacketAdapter.java +++ b/src/main/java/net/william278/velocitab/packet/TeamsPacketAdapter.java @@ -35,8 +35,6 @@ public abstract class TeamsPacketAdapter { private final Set protocolVersions; - public abstract void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet); - public abstract void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet); @NotNull diff --git a/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java b/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java index ea3dcef..1db675b 100644 --- a/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java +++ b/src/main/java/net/william278/velocitab/packet/UpdateTeamsPacket.java @@ -29,7 +29,6 @@ import lombok.experimental.Accessors; import net.william278.velocitab.Velocitab; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.slf4j.event.Level; import java.util.Arrays; import java.util.List; @@ -44,8 +43,6 @@ import java.util.stream.Collectors; @Accessors(fluent = true) public class UpdateTeamsPacket implements MinecraftPacket { - private static final String PACKET_ADAPTION_ERROR = "Something went wrong while %s a UpdateTeamsPacket, if your " + - "server is on 1.8.x and you are using ViaVersion, please disable 'auto-team' in the config.yml and reload."; private final Velocitab plugin; private String teamName; @@ -96,26 +93,16 @@ public class UpdateTeamsPacket implements MinecraftPacket { @Override public void decode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { - final Optional optionalManager = plugin.getScoreboardManager(); - if (optionalManager.isEmpty()) { - return; - } - if (mode == null) { - plugin.log(Level.ERROR, String.format(PACKET_ADAPTION_ERROR, "decoding")); - } - - optionalManager.get().getPacketAdapter(protocolVersion).decode(byteBuf, this); + throw new UnsupportedOperationException("Operation not supported"); } @Override public void encode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { final Optional optionalManager = plugin.getScoreboardManager(); + if (optionalManager.isEmpty()) { return; } - if (mode == null) { - plugin.log(Level.ERROR, String.format(PACKET_ADAPTION_ERROR, "encoding")); - } optionalManager.get().getPacketAdapter(protocolVersion).encode(byteBuf, this); }