3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Convert ClientboundLoginPluginMessagePacket encoding to PacketWriter

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-05-27 16:26:09 -04:00
Ursprung c00ffea161
Commit 063a208f5f

Datei anzeigen

@ -42,27 +42,21 @@ public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder im
}
return new ClientboundLoginPluginMessagePacket(id, channel, data);
};
public static final PacketWriter<ClientboundLoginPluginMessagePacket> ENCODER = PacketWriter.deprecatedEncode();
public static final PacketWriter<ClientboundLoginPluginMessagePacket> ENCODER = (out, packet, version) -> {
ProtocolUtils.writeVarInt(out, packet.id);
ProtocolUtils.writeString(out, packet.channel);
out.writeBytes(packet.content());
};
private final int id;
private final @Nullable String channel;
private final String channel;
public ClientboundLoginPluginMessagePacket(int id, @Nullable String channel, ByteBuf data) {
public ClientboundLoginPluginMessagePacket(int id, String channel, ByteBuf data) {
super(data);
this.id = id;
this.channel = channel;
}
@Override
public void encode(ByteBuf buf, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, id);
if (channel == null) {
throw new IllegalStateException("Channel is not specified!");
}
ProtocolUtils.writeString(buf, channel);
buf.writeBytes(content());
}
@Override
public boolean handle(PacketHandler handler) {
return handler.handle(this);
@ -73,9 +67,6 @@ public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder im
}
public String getChannel() {
if (channel == null) {
throw new IllegalStateException("Channel is not specified!");
}
return channel;
}