Update about menu, minor code cleanup

This commit is contained in:
William278 2023-09-13 10:06:44 +03:00
parent 02dca8ba3f
commit c1682aeda9
8 changed files with 100 additions and 98 deletions

View File

@ -43,10 +43,11 @@ public final class VelocitabCommand {
.credits("Author",
AboutMenu.Credit.of("William278").description("Click to visit website").url("https://william278.net"))
.credits("Contributors",
AboutMenu.Credit.of("Ironboundred").description("Coding"),
AboutMenu.Credit.of("Emibergo02").description("Coding"),
AboutMenu.Credit.of("FreeMonoid").description("Coding"),
AboutMenu.Credit.of("4drian3d").description("Coding"))
AboutMenu.Credit.of("AlexDev03").description("Code"),
AboutMenu.Credit.of("Ironboundred").description("Code"),
AboutMenu.Credit.of("Emibergo02").description("Code"),
AboutMenu.Credit.of("FreeMonoid").description("Code"),
AboutMenu.Credit.of("4drian3d").description("Code"))
.buttons(
AboutMenu.Link.of("https://william278.net/docs/velocitab").text("Docs").icon(""),
AboutMenu.Link.of("https://discord.gg/tVYhJfyDWG").text("Discord").icon("").color(TextColor.color(0x6773f5)),

View File

@ -25,13 +25,11 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry;
import io.netty.util.collection.IntObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.william278.velocitab.Velocitab;
import org.jetbrains.annotations.NotNull;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

View File

@ -23,11 +23,15 @@ package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.12.2
*/
@SuppressWarnings("DuplicatedCode")
public class Protocol340Adapter extends TeamsPacketAdapter {
@ -36,20 +40,20 @@ public class Protocol340Adapter extends TeamsPacketAdapter {
}
@Override
public void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
updateTeamsPacket.teamName(ProtocolUtils.readString(byteBuf));
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) {
updateTeamsPacket.displayName(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.prefix(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.suffix(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
updateTeamsPacket.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
updateTeamsPacket.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf)));
updateTeamsPacket.color(byteBuf.readByte());
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);
@ -57,29 +61,29 @@ public class Protocol340Adapter extends TeamsPacketAdapter {
for (int j = 0; j < entityCount; j++) {
entities.add(ProtocolUtils.readString(byteBuf));
}
updateTeamsPacket.entities(entities);
packet.entities(entities);
}
}
@Override
public void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.teamName().substring(0, Math.min(updateTeamsPacket.teamName().length(), 16)));
UpdateTeamsPacket.UpdateMode mode = updateTeamsPacket.mode();
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
ProtocolUtils.writeString(byteBuf, packet.teamName().substring(0, Math.min(packet.teamName().length(), 16)));
UpdateTeamsPacket.UpdateMode mode = packet.mode();
byteBuf.writeByte(mode.id());
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
return;
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.displayName());
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.prefix());
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.suffix());
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(updateTeamsPacket.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.nameTagVisibility().id());
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.collisionRule().id());
byteBuf.writeByte(updateTeamsPacket.color());
ProtocolUtils.writeString(byteBuf, packet.displayName());
ProtocolUtils.writeString(byteBuf, packet.prefix());
ProtocolUtils.writeString(byteBuf, packet.suffix());
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, packet.nameTagVisibility().id());
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
byteBuf.writeByte(packet.color());
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
List<String> entities = updateTeamsPacket.entities();
List<String> entities = packet.entities();
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
for (String entity : entities != null ? entities : new ArrayList<String>()) {
ProtocolUtils.writeString(byteBuf, entity);

View File

@ -23,11 +23,15 @@ package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.13+
*/
@SuppressWarnings("DuplicatedCode")
public class Protocol403Adapter extends TeamsPacketAdapter {
@ -44,20 +48,20 @@ public class Protocol403Adapter extends TeamsPacketAdapter {
}
@Override
public void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
updateTeamsPacket.teamName(ProtocolUtils.readString(byteBuf));
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) {
updateTeamsPacket.displayName(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
updateTeamsPacket.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
updateTeamsPacket.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf)));
updateTeamsPacket.color(byteBuf.readByte());
updateTeamsPacket.prefix(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.suffix(ProtocolUtils.readString(byteBuf));
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);
@ -65,29 +69,29 @@ public class Protocol403Adapter extends TeamsPacketAdapter {
for (int j = 0; j < entityCount; j++) {
entities.add(ProtocolUtils.readString(byteBuf));
}
updateTeamsPacket.entities(entities);
packet.entities(entities);
}
}
@Override
public void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.teamName());
UpdateTeamsPacket.UpdateMode mode = updateTeamsPacket.mode();
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
ProtocolUtils.writeString(byteBuf, packet.teamName());
UpdateTeamsPacket.UpdateMode mode = packet.mode();
byteBuf.writeByte(mode.id());
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
return;
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
ProtocolUtils.writeString(byteBuf, getChatString(updateTeamsPacket.displayName()));
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(updateTeamsPacket.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.nameTagVisibility().id());
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.collisionRule().id());
byteBuf.writeByte(updateTeamsPacket.color());
ProtocolUtils.writeString(byteBuf, getChatString(updateTeamsPacket.prefix()));
ProtocolUtils.writeString(byteBuf, getChatString(updateTeamsPacket.suffix()));
ProtocolUtils.writeString(byteBuf, getChatString(packet.displayName()));
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, packet.nameTagVisibility().id());
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
byteBuf.writeByte(packet.color());
ProtocolUtils.writeString(byteBuf, getChatString(packet.prefix()));
ProtocolUtils.writeString(byteBuf, getChatString(packet.suffix()));
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
List<String> entities = updateTeamsPacket.entities();
List<String> entities = packet.entities();
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
for (String entity : entities != null ? entities : new ArrayList<String>()) {
ProtocolUtils.writeString(byteBuf, entity);

View File

@ -23,11 +23,15 @@ package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.8.x
*/
@SuppressWarnings("DuplicatedCode")
public class Protocol48Adapter extends TeamsPacketAdapter {
@ -36,19 +40,19 @@ public class Protocol48Adapter extends TeamsPacketAdapter {
}
@Override
public void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
updateTeamsPacket.teamName(ProtocolUtils.readString(byteBuf));
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) {
updateTeamsPacket.displayName(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.prefix(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.suffix(ProtocolUtils.readString(byteBuf));
updateTeamsPacket.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
updateTeamsPacket.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
updateTeamsPacket.color(byteBuf.readByte());
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);
@ -56,28 +60,28 @@ public class Protocol48Adapter extends TeamsPacketAdapter {
for (int j = 0; j < entityCount; j++) {
entities.add(ProtocolUtils.readString(byteBuf));
}
updateTeamsPacket.entities(entities);
packet.entities(entities);
}
}
@Override
public void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.teamName().substring(0, Math.min(updateTeamsPacket.teamName().length(), 16)));
UpdateTeamsPacket.UpdateMode mode = updateTeamsPacket.mode();
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
ProtocolUtils.writeString(byteBuf, packet.teamName().substring(0, Math.min(packet.teamName().length(), 16)));
UpdateTeamsPacket.UpdateMode mode = packet.mode();
byteBuf.writeByte(mode.id());
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
return;
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.displayName());
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.prefix());
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.suffix());
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(updateTeamsPacket.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.nameTagVisibility().id());
byteBuf.writeByte(updateTeamsPacket.color());
ProtocolUtils.writeString(byteBuf, packet.displayName());
ProtocolUtils.writeString(byteBuf, packet.prefix());
ProtocolUtils.writeString(byteBuf, packet.suffix());
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, packet.nameTagVisibility().id());
byteBuf.writeByte(packet.color());
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
List<String> entities = updateTeamsPacket.entities();
List<String> entities = packet.entities();
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
for (String entity : entities != null ? entities : new ArrayList<String>()) {
ProtocolUtils.writeString(byteBuf, entity);

View File

@ -55,15 +55,12 @@ public class ScoreboardManager {
versions.add(new Protocol48Adapter());
}
public TeamsPacketAdapter getPacketAdapter(ProtocolVersion protocolVersion) {
@NotNull
public TeamsPacketAdapter getPacketAdapter(@NotNull ProtocolVersion version) {
return versions.stream()
.filter(version -> version.getProtocolVersions().contains(protocolVersion))
.filter(adapter -> adapter.getProtocolVersions().contains(version))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No version found for protocol version " + protocolVersion));
}
public void sendProtocolError(String message) {
plugin.log(Level.ERROR, message);
.orElseThrow(() -> new IllegalArgumentException("No adapter found for protocol version " + version));
}
public void resetCache(@NotNull Player player) {
@ -98,7 +95,10 @@ public class ScoreboardManager {
.entrySet().stream()
.filter((entry) -> List.of(playerNames).contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
.forEach((playerName, oldRole) -> dispatchPacket(UpdateTeamsPacket.removeFromTeam(plugin, oldRole, playerName), player));
.forEach((playerName, oldRole) -> dispatchPacket(
UpdateTeamsPacket.removeFromTeam(plugin, oldRole, playerName),
player
));
dispatchPacket(UpdateTeamsPacket.addToTeam(plugin, role, playerNames), player);
roleMappings.computeIfAbsent(player.getUniqueId(), k -> new HashMap<>()).put(player.getUsername(), role);
}

View File

@ -35,9 +35,9 @@ public abstract class TeamsPacketAdapter {
private final Set<ProtocolVersion> protocolVersions;
public abstract void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket);
public abstract void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet);
public abstract void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket);
public abstract void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet);
@NotNull
protected String getChatString(@NotNull String string) {

View File

@ -29,6 +29,7 @@ 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;
@ -43,6 +44,8 @@ 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;
@ -56,7 +59,7 @@ public class UpdateTeamsPacket implements MinecraftPacket {
private String suffix;
private List<String> entities;
public UpdateTeamsPacket(Velocitab plugin) {
public UpdateTeamsPacket(@NotNull Velocitab plugin) {
this.plugin = plugin;
}
@ -93,40 +96,28 @@ public class UpdateTeamsPacket implements MinecraftPacket {
@Override
public void decode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
Optional<ScoreboardManager> scoreboardManagerOptional = plugin.getScoreboardManager();
if (scoreboardManagerOptional.isEmpty()) {
final Optional<ScoreboardManager> optionalManager = plugin.getScoreboardManager();
if (optionalManager.isEmpty()) {
return;
}
ScoreboardManager scoreboardManager = scoreboardManagerOptional.get();
if (mode == null) {
scoreboardManager.sendProtocolError("Something went wrong while decoding 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 it.");
plugin.log(Level.ERROR, String.format(PACKET_ADAPTION_ERROR, "decoding"));
}
scoreboardManager.getPacketAdapter(protocolVersion).decode(byteBuf, this);
optionalManager.get().getPacketAdapter(protocolVersion).decode(byteBuf, this);
}
@Override
public void encode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
Optional<ScoreboardManager> scoreboardManagerOptional = plugin.getScoreboardManager();
if (scoreboardManagerOptional.isEmpty()) {
final Optional<ScoreboardManager> optionalManager = plugin.getScoreboardManager();
if (optionalManager.isEmpty()) {
return;
}
ScoreboardManager scoreboardManager = scoreboardManagerOptional.get();
if (mode == null) {
scoreboardManager.sendProtocolError("Something went wrong while encoding 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 it.");
plugin.log(Level.ERROR, String.format(PACKET_ADAPTION_ERROR, "encoding"));
}
scoreboardManager.getPacketAdapter(protocolVersion).encode(byteBuf, this);
optionalManager.get().getPacketAdapter(protocolVersion).encode(byteBuf, this);
}
@Override