eventLoopGroupFactory) {
this.name = name;
this.serverSocketChannelFactory = serverSocketChannelFactory;
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java
index 154a8f3f5..8f479cdac 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java
@@ -20,6 +20,7 @@ package com.velocitypowered.proxy.network.packet;
import static com.velocitypowered.proxy.network.PluginMessageUtil.transformLegacyToModernChannel;
import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.buffer.TypedDefaultByteBufHolder;
@@ -60,18 +61,14 @@ public abstract class AbstractPluginMessagePacket {
static PacketReader
method(final Supplier
factory) {
return (buf, version) -> {
final P packet = factory.get();
- packet.decode(buf, null, version);
+ packet.decode(buf, version);
return packet;
};
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java
index 259dfd4d4..8005c993d 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java
@@ -37,7 +37,6 @@ import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -84,7 +83,7 @@ public class ClientboundAvailableCommandsPacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) {
+ public void decode(ByteBuf buf, ProtocolVersion protocolVersion) {
int commands = ProtocolUtils.readVarInt(buf);
WireNode[] wireNodes = new WireNode[commands];
for (int i = 0; i < commands; i++) {
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java
index d31faf043..f792808f6 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java
@@ -21,7 +21,6 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -109,7 +108,7 @@ public class ClientboundBossBarPacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
this.uuid = ProtocolUtils.readUuid(buf);
this.action = ProtocolUtils.readVarInt(buf);
switch (action) {
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java
index 0208e7049..9b72311ec 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java
@@ -21,60 +21,40 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
+import net.kyori.adventure.identity.Identity;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundChatPacket implements Packet {
- public static final PacketReader DECODER = PacketReader.method(ClientboundChatPacket::new);
- public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode();
+ public static final PacketReader DECODER = PacketReader.unsupported();
+ public static final PacketWriter ENCODER = (out, packet, version) -> {
+ ProtocolUtils.writeString(out, packet.message);
+ if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
+ out.writeByte(packet.type);
+ if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
+ ProtocolUtils.writeUuid(out, packet.sender.uuid());
+ }
+ }
+ };
public static final byte CHAT_TYPE = (byte) 0;
public static final byte SYSTEM_TYPE = (byte) 1;
public static final byte GAME_INFO_TYPE = (byte) 2;
- private @Nullable String message;
+ private String message;
private byte type;
- private @Nullable UUID sender;
+ private Identity sender;
- private ClientboundChatPacket() {
- }
-
- public ClientboundChatPacket(String message, byte type, UUID sender) {
+ public ClientboundChatPacket(String message, byte type, Identity sender) {
this.message = message;
this.type = type;
this.sender = sender;
}
- @Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
- message = ProtocolUtils.readString(buf);
- if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
- type = buf.readByte();
- if (version.gte(ProtocolVersion.MINECRAFT_1_16)) {
- sender = ProtocolUtils.readUuid(buf);
- }
- }
- }
-
- @Override
- public void encode(ByteBuf buf, ProtocolVersion version) {
- if (message == null) {
- throw new IllegalStateException("Message is not specified");
- }
- ProtocolUtils.writeString(buf, message);
- if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
- buf.writeByte(type);
- if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
- ProtocolUtils.writeUuid(buf, sender);
- }
- }
- }
-
@Override
public boolean handle(PacketHandler handler) {
return handler.handle(this);
@@ -91,10 +71,6 @@ public class ClientboundChatPacket implements Packet {
return type;
}
- public UUID getSenderUuid() {
- return sender;
- }
-
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java
index 95054d742..08fe4f4f1 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java
@@ -23,7 +23,6 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -54,7 +53,7 @@ public class ClientboundEncryptionRequestPacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
this.serverId = ProtocolUtils.readString(buf, 20);
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java
index bce9a5806..e027a851e 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java
@@ -24,7 +24,6 @@ import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -35,6 +34,9 @@ import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.ListBinaryTag;
import org.checkerframework.checker.nullness.qual.Nullable;
+// TODO: This class is in dire need of a refactor. Suppressing the warning is only done as an
+// implicit acknowledgement that this code is very bad.
+@SuppressWarnings("WarnAway")
public class ClientboundJoinGamePacket implements Packet {
public static final PacketReader DECODER = PacketReader.method(ClientboundJoinGamePacket::new);
public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode();
@@ -188,7 +190,7 @@ public class ClientboundJoinGamePacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
this.entityId = buf.readInt();
if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) {
this.isHardcore = buf.readBoolean();
@@ -196,7 +198,7 @@ public class ClientboundJoinGamePacket implements Packet {
} else {
this.gamemode = buf.readByte();
this.isHardcore = (this.gamemode & 0x08) != 0;
- this.gamemode &= ~0x08;
+ this.gamemode &= (short) (this.gamemode & ~0x08);
}
String dimensionIdentifier = null;
String levelName = null;
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java
index c2b6c343d..9945d0b81 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java
@@ -84,7 +84,7 @@ public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder im
if (this == other) {
return true;
}
- if (other == null || this.getClass() != other.getClass()) {
+ if (!(other instanceof ClientboundLoginPluginMessagePacket)) {
return false;
}
final ClientboundLoginPluginMessagePacket that = (ClientboundLoginPluginMessagePacket) other;
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java
index 088bb2fdf..0c3a5fcf5 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java
@@ -18,13 +18,13 @@
package com.velocitypowered.proxy.network.packet.clientbound;
import com.google.common.base.MoreObjects;
+import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -65,7 +65,7 @@ public class ClientboundPlayerListItemPacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
action = ProtocolUtils.readVarInt(buf);
int length = ProtocolUtils.readVarInt(buf);
@@ -121,7 +121,9 @@ public class ClientboundPlayerListItemPacket implements Packet {
ProtocolUtils.writeVarInt(buf, items.size());
for (Item item : items) {
UUID uuid = item.getUuid();
- assert uuid != null : "UUID-less entry serialization attempt - 1.7 component!";
+ if (uuid == null) {
+ throw new VerifyException("UUID-less entry serialization attempt - 1.7 component!");
+ }
ProtocolUtils.writeUuid(buf, uuid);
switch (action) {
@@ -189,7 +191,7 @@ public class ClientboundPlayerListItemPacket implements Packet {
public static class Item {
- private final UUID uuid;
+ private final @Nullable UUID uuid;
private String name = "";
private List properties = ImmutableList.of();
private int gameMode;
@@ -200,7 +202,7 @@ public class ClientboundPlayerListItemPacket implements Packet {
uuid = null;
}
- public Item(UUID uuid) {
+ public Item(@Nullable UUID uuid) {
this.uuid = uuid;
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java
index d48a4c5ed..c66b1e096 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java
@@ -23,14 +23,17 @@ import com.velocitypowered.proxy.connection.registry.DimensionData;
import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.BinaryTagIO;
import net.kyori.adventure.nbt.CompoundBinaryTag;
+import org.checkerframework.checker.nullness.qual.Nullable;
+// TODO: This class is in dire need of a refactor. Suppressing the warning is only done as an
+// implicit acknowledgement that this code is very bad.
+@SuppressWarnings("WarnAway")
public class ClientboundRespawnPacket implements Packet {
public static final PacketReader DECODER = PacketReader.method(ClientboundRespawnPacket::new);
public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode();
@@ -49,13 +52,14 @@ public class ClientboundRespawnPacket implements Packet {
}
public ClientboundRespawnPacket(int dimension, long partialHashedSeed, short difficulty, short gamemode,
- String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo,
- short previousGamemode, DimensionData currentDimensionData) {
+ @Nullable String levelType, boolean shouldKeepPlayerData,
+ DimensionInfo dimensionInfo, short previousGamemode,
+ DimensionData currentDimensionData) {
this.dimension = dimension;
this.partialHashedSeed = partialHashedSeed;
this.difficulty = difficulty;
this.gamemode = gamemode;
- this.levelType = levelType;
+ this.levelType = levelType == null ? "" : levelType;
this.shouldKeepPlayerData = shouldKeepPlayerData;
this.dimensionInfo = dimensionInfo;
this.previousGamemode = previousGamemode;
@@ -119,7 +123,7 @@ public class ClientboundRespawnPacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
String dimensionIdentifier = null;
String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java
index 40b785c71..5a1d9200a 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java
@@ -35,20 +35,12 @@ public class ClientboundStatusResponsePacket implements Packet {
public static final PacketWriter ENCODER = (buf, packet, version) ->
ProtocolUtils.writeString(buf, packet.status);
- private final @Nullable CharSequence status;
+ private final CharSequence status;
public ClientboundStatusResponsePacket(CharSequence status) {
this.status = status;
}
- @Override
- public void encode(ByteBuf buf, ProtocolVersion version) {
- if (status == null) {
- throw new IllegalStateException("Status is not specified");
- }
- ProtocolUtils.writeString(buf, status);
- }
-
@Override
public boolean handle(PacketHandler handler) {
return handler.handle(this);
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java
index 0f9ab6e63..98115e591 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java
@@ -21,7 +21,6 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -69,7 +68,7 @@ public class ClientboundTabCompleteResponsePacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
this.transactionId = ProtocolUtils.readVarInt(buf);
this.start = ProtocolUtils.readVarInt(buf);
@@ -146,7 +145,7 @@ public class ClientboundTabCompleteResponsePacket implements Packet {
if (this == o) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (!(o instanceof Offer)) {
return false;
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java
index 7cdba5d85..76f7edd1b 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java
@@ -21,7 +21,6 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -54,7 +53,7 @@ public class ServerboundClientSettingsPacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
this.locale = ProtocolUtils.readString(buf, 16);
this.viewDistance = buf.readByte();
this.chatVisibility = ProtocolUtils.readVarInt(buf);
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java
index 029c9f2fe..b1f54613b 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java
@@ -87,12 +87,12 @@ public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder i
if (this == other) {
return true;
}
- if (other == null || this.getClass() != other.getClass()) {
+ if (!(other instanceof ServerboundLoginPluginResponsePacket)) {
return false;
}
final ServerboundLoginPluginResponsePacket that = (ServerboundLoginPluginResponsePacket) other;
return this.id == that.id
- && Objects.equals(this.success, that.success)
+ && this.success == that.success
&& super.equals(other);
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java
index 97b8bbfc7..1a68ef0b7 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java
@@ -52,7 +52,7 @@ public class ServerboundResourcePackResponsePacket implements Packet {
@Override
public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
if (protocolVersion.lte(ProtocolVersion.MINECRAFT_1_9_4)) {
- ProtocolUtils.writeString(buf, hash);
+ ProtocolUtils.writeString(buf, hash == null ? "" : hash);
}
ProtocolUtils.writeVarInt(buf, status.ordinal());
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java
index 973ca4d48..f09e19601 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java
@@ -25,7 +25,6 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
-import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
@@ -88,7 +87,7 @@ public class ServerboundTabCompleteRequestPacket implements Packet {
}
@Override
- public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
+ public void decode(ByteBuf buf, ProtocolVersion version) {
if (version.gte(MINECRAFT_1_13)) {
this.transactionId = ProtocolUtils.readVarInt(buf);
this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN);
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java
index e2cdb8345..03f9ff73a 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java
@@ -27,7 +27,7 @@ class VarintByteDecoder implements ByteProcessor {
@Override
public boolean process(byte k) {
- readVarint |= (k & 0x7F) << bytesRead++ * 7;
+ readVarint |= (k & 0x7F) << (bytesRead++ * 7);
if (bytesRead > 3) {
result = DecodeResult.TOO_BIG;
return false;
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/registry/packet/RegularPacketRegistryMap.java b/proxy/src/main/java/com/velocitypowered/proxy/network/registry/packet/RegularPacketRegistryMap.java
index 0203acc0b..65291592b 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/registry/packet/RegularPacketRegistryMap.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/registry/packet/RegularPacketRegistryMap.java
@@ -27,7 +27,6 @@ import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
-import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -85,7 +84,7 @@ public class RegularPacketRegistryMap implements PacketRegistryMap {
@Override
public @Nullable Class extends Packet> lookupPacket(int id) {
- for (Entry> entry : this.classesById.object2IntEntrySet()) {
+ for (Object2IntMap.Entry> entry : this.classesById.object2IntEntrySet()) {
if (entry.getIntValue() == id) {
return (Class extends Packet>) entry.getKey();
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/registry/protocol/VersionSpecificProtocolRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/network/registry/protocol/VersionSpecificProtocolRegistry.java
index f8db927b3..41b9ca24a 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/registry/protocol/VersionSpecificProtocolRegistry.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/registry/protocol/VersionSpecificProtocolRegistry.java
@@ -19,6 +19,7 @@ package com.velocitypowered.proxy.network.registry.protocol;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.PacketDirection;
+import com.velocitypowered.proxy.network.registry.packet.EmptyPacketRegistryMap;
import com.velocitypowered.proxy.network.registry.packet.PacketRegistryMap;
import java.util.EnumMap;
import java.util.EnumSet;
@@ -49,9 +50,9 @@ public class VersionSpecificProtocolRegistry implements ProtocolRegistry {
@Override
public PacketRegistryMap lookup(PacketDirection direction, ProtocolVersion version) {
if (direction == PacketDirection.SERVERBOUND) {
- return this.serverboundByVersion.get(version);
+ return this.serverboundByVersion.getOrDefault(version, EmptyPacketRegistryMap.INSTANCE);
} else if (direction == PacketDirection.CLIENTBOUND) {
- return this.clientboundByVersion.get(version);
+ return this.clientboundByVersion.getOrDefault(version, EmptyPacketRegistryMap.INSTANCE);
} else {
throw new NullPointerException("direction");
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/registry/state/PlayPacketRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/network/registry/state/PlayPacketRegistry.java
index 5cd4810b8..6abece2df 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/registry/state/PlayPacketRegistry.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/registry/state/PlayPacketRegistry.java
@@ -311,6 +311,7 @@ class PlayPacketRegistry implements ProtocolRegistry {
public final PacketRegistry clientbound;
public final PacketRegistry serverbound;
+ @Override
public PacketRegistryMap lookup(PacketDirection direction,
ProtocolVersion version) {
return (direction == PacketDirection.SERVERBOUND ? this.serverbound : this.clientbound)
@@ -319,24 +320,21 @@ class PlayPacketRegistry implements ProtocolRegistry {
public static class PacketRegistry {
- private final PacketDirection direction;
- private final Map versions;
+ private final Map versions;
PacketRegistry(PacketDirection direction) {
- this.direction = direction;
-
- Map mutableVersions = new EnumMap<>(ProtocolVersion.class);
+ Map mutableVersions = new EnumMap<>(ProtocolVersion.class);
for (ProtocolVersion version : ProtocolVersion.values()) {
if (!version.isLegacy() && !version.isUnknown()) {
- mutableVersions.put(version, new ProtocolRegistry(version));
+ mutableVersions.put(version, new InternalRegistryMap(version, direction));
}
}
this.versions = mutableVersions;
}
- ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) {
- ProtocolRegistry registry = versions.get(version);
+ InternalRegistryMap getProtocolRegistry(final ProtocolVersion version) {
+ InternalRegistryMap registry = versions.get(version);
if (registry == null) {
throw new IllegalArgumentException("Could not find data for protocol version " + version);
}
@@ -364,7 +362,7 @@ class PlayPacketRegistry implements ProtocolRegistry {
if (protocol == to && next != current) {
break;
}
- ProtocolRegistry registry = this.versions.get(protocol);
+ InternalRegistryMap registry = this.versions.get(protocol);
if (registry == null) {
throw new IllegalArgumentException("Unknown protocol version "
+ current.protocolVersion);
@@ -391,8 +389,12 @@ class PlayPacketRegistry implements ProtocolRegistry {
}
public void compact() {
- ProtocolRegistry last = this.versions.get(MINIMUM_VERSION);
- for (Entry entry : this.versions
+ InternalRegistryMap last = this.versions.get(MINIMUM_VERSION);
+ if (last == null) {
+ return;
+ }
+
+ for (Map.Entry entry : this.versions
.entrySet()) {
if (entry.getValue() == last) {
continue;
@@ -406,73 +408,79 @@ class PlayPacketRegistry implements ProtocolRegistry {
}
}
}
+ }
- public class ProtocolRegistry implements PacketRegistryMap {
+ public static class InternalRegistryMap implements PacketRegistryMap {
- private final ProtocolVersion version;
- final IntObjectMap> packetIdToReader =
- new IntObjectHashMap<>(16, 0.5f);
- final Object2IntMap> packetClassToId =
- new Object2IntOpenHashMap<>(16, 0.5f);
- final Map, PacketWriter extends Packet>> packetClassToWriter =
- new HashMap<>(16, 0.5f);
+ private final ProtocolVersion version;
+ final IntObjectMap> packetIdToReader =
+ new IntObjectHashMap<>(16, 0.5f);
+ final Object2IntMap> packetClassToId =
+ new Object2IntOpenHashMap<>(16, 0.5f);
+ final Map, PacketWriter extends Packet>> packetClassToWriter =
+ new HashMap<>(16, 0.5f);
+ private final PacketDirection direction;
- ProtocolRegistry(final ProtocolVersion version) {
- this.version = version;
- this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE);
- }
+ InternalRegistryMap(final ProtocolVersion version,
+ PacketDirection direction) {
+ this.version = version;
+ this.direction = direction;
+ this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE);
+ }
- /**
- * Attempts to create a packet from the specified {@code id}.
- *
- * @param id the packet ID
- * @param buf the bytebuf
- * @return the packet instance, or {@code null} if the ID is not registered
- */
- public @Nullable Packet readPacket(final int id, ByteBuf buf, ProtocolVersion version) {
- final PacketReader extends Packet> decoder = this.packetIdToReader.get(id);
- if (decoder == null) {
- return null;
- }
- return decoder.read(buf, version);
- }
-
- /**
- * Attempts to serialize the specified {@code packet}.
- *
- * @param packet the packet
- * @param buf the bytebuf
- */
- public void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
- final int id = this.packetClassToId.getInt(packet.getClass());
- if (id == Integer.MIN_VALUE) {
- throw new IllegalArgumentException(String.format(
- "Unable to find id for packet of type %s in %s protocol %s",
- packet.getClass().getName(), PacketRegistry.this.direction, this.version
- ));
- }
-
- @SuppressWarnings("rawtypes")
- // Safe because all registering actions are type-safe.
- final PacketWriter encoder = this.packetClassToWriter.get(packet.getClass());
-
- assert encoder != null : "Couldn't look up encoder - shouldn't happen!";
-
- ProtocolUtils.writeVarInt(buf, id);
- //noinspection unchecked
- encoder.write(buf, packet, version);
- }
-
- @Override
- public @Nullable Class extends Packet> lookupPacket(int id) {
- for (Object2IntMap.Entry> entry : this.packetClassToId
- .object2IntEntrySet()) {
- if (entry.getIntValue() == id) {
- return entry.getKey();
- }
- }
+ /**
+ * Attempts to create a packet from the specified {@code id}.
+ *
+ * @param id the packet ID
+ * @param buf the bytebuf
+ * @return the packet instance, or {@code null} if the ID is not registered
+ */
+ @Override
+ public @Nullable Packet readPacket(final int id, ByteBuf buf, ProtocolVersion version) {
+ final PacketReader extends Packet> decoder = this.packetIdToReader.get(id);
+ if (decoder == null) {
return null;
}
+ return decoder.read(buf, version);
+ }
+
+ /**
+ * Attempts to serialize the specified {@code packet}.
+ *
+ * @param packet the packet
+ * @param buf the bytebuf
+ */
+ @Override
+ public void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
+ final int id = this.packetClassToId.getInt(packet.getClass());
+ if (id == Integer.MIN_VALUE) {
+ throw new IllegalArgumentException(String.format(
+ "Unable to find id for packet of type %s in %s protocol %s",
+ packet.getClass().getName(), this.direction, this.version
+ ));
+ }
+
+ @SuppressWarnings("rawtypes")
+ // Safe because all registering actions are type-safe.
+ final PacketWriter encoder = this.packetClassToWriter.get(packet.getClass());
+ if (encoder == null) {
+ throw new IllegalStateException("Couldn't look up encoder - shouldn't happen!");
+ }
+
+ ProtocolUtils.writeVarInt(buf, id);
+ //noinspection unchecked
+ encoder.write(buf, packet, version);
+ }
+
+ @Override
+ public @Nullable Class extends Packet> lookupPacket(int id) {
+ for (Object2IntMap.Entry> entry : this.packetClassToId
+ .object2IntEntrySet()) {
+ if (entry.getIntValue() == id) {
+ return entry.getKey();
+ }
+ }
+ return null;
}
}
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java b/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java
index 0346eb27c..0cc0a0b6c 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java
@@ -35,13 +35,14 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public final class SeparatePoolInetNameResolver extends InetNameResolver {
private final ExecutorService resolveExecutor;
private final InetNameResolver delegate;
private final Cache> cache;
- private AddressResolverGroup resolverGroup;
+ private @MonotonicNonNull AddressResolverGroup resolverGroup;
/**
* Creates a new instance of {@code SeparatePoolInetNameResolver}.
diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java
index af87d2019..20d6e2667 100644
--- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java
+++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java
@@ -60,7 +60,7 @@ public class VelocityPluginManager implements PluginManager {
private static final Logger logger = LogManager.getLogger(VelocityPluginManager.class);
private final Map plugins = new LinkedHashMap<>();
- private final Map