forked from Upstream/Velocitab
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
This commit is contained in:
parent
90a26f15eb
commit
8ae25521dd
@ -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<String> 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)));
|
||||
|
@ -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<String> 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());
|
||||
|
@ -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<String> 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)));
|
||||
|
@ -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);
|
||||
|
@ -35,8 +35,6 @@ public abstract class TeamsPacketAdapter {
|
||||
|
||||
private final Set<ProtocolVersion> protocolVersions;
|
||||
|
||||
public abstract void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet);
|
||||
|
||||
public abstract void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet);
|
||||
|
||||
@NotNull
|
||||
|
@ -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<ScoreboardManager> 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<ScoreboardManager> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user