diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 26a59d80..066b4eb6 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -15,7 +15,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'temurin'
- java-version: '19'
+ java-version: '21'
cache: 'gradle'
- name: Run gradle build lifecycle
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index b0f9adc9..12ca758b 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -26,7 +26,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'temurin'
- java-version: '19'
+ java-version: '21'
cache: 'gradle'
- name: Initialize CodeQL
diff --git a/build.gradle b/build.gradle
index fae984ae..06a3f19e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -33,7 +33,7 @@ repositories {
}
dependencies {
- implementation 'net.bytebuddy:byte-buddy:1.14.9'
+ implementation 'net.bytebuddy:byte-buddy:1.14.14'
compileOnly 'org.spigotmc:spigot-api:1.20.5-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT'
compileOnly 'io.netty:netty-all:4.0.23.Final'
@@ -69,6 +69,9 @@ shadowJar {
test {
useJUnitPlatform()
+ testLogging {
+ exceptionFormat = 'full'
+ }
}
processResources {
diff --git a/src/main/java/com/comphenix/protocol/PacketType.java b/src/main/java/com/comphenix/protocol/PacketType.java
index 0b9cd1eb..e4b39e50 100644
--- a/src/main/java/com/comphenix/protocol/PacketType.java
+++ b/src/main/java/com/comphenix/protocol/PacketType.java
@@ -5,8 +5,17 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import java.util.*;
-import java.util.function.Consumer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.BiConsumer;
+
+import org.apache.commons.lang.WordUtils;
+import org.bukkit.Bukkit;
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
import com.comphenix.protocol.events.ConnectionSide;
@@ -17,9 +26,6 @@ import com.comphenix.protocol.utility.MinecraftVersion;
import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Iterables;
-
-import org.apache.commons.lang.WordUtils;
-import org.bukkit.Bukkit;
/**
* Represents the type of a packet in a specific protocol.
*
@@ -101,7 +107,7 @@ public class PacketType implements Serializable, Cloneable, Comparable onDynamicCreate = x -> {};
+ static BiConsumer onDynamicCreate = (type, className) -> {};
+ static BiConsumer onIdMismatch = (type, newId) -> {};
/**
* Retrieve a packet type from a protocol, sender, ID, and class for 1.8+
@@ -1019,7 +1071,7 @@ public class PacketType implements Serializable, Cloneable, Comparable map, String clazz) {
- PacketType ret = map.get(clazz);
+ private static PacketType find(Map map, Class> packetClass) {
+ String className = packetClass.getName();
+ PacketType ret = map.get(className);
if (ret != null) {
return ret;
}
@@ -1044,7 +1099,7 @@ public class PacketType implements Serializable, Cloneable, Comparable aliases = check.getClassNames();
if (aliases.size() > 1) {
for (String alias : aliases) {
- if (alias.equals(clazz)) {
+ if (alias.equals(className) || alias.equals(packetClass.getSimpleName())) {
// We have a match!
return check;
}
@@ -1174,6 +1229,9 @@ public class PacketType implements Serializable, Cloneable, Comparable HANDSHAKE_CLIENT = new IntegerMap<>();
@@ -27,6 +28,8 @@ class PacketTypeLookup {
public final IntegerMap STATUS_SERVER = new IntegerMap<>();
public final IntegerMap LOGIN_CLIENT = new IntegerMap<>();
public final IntegerMap LOGIN_SERVER = new IntegerMap<>();
+ public final IntegerMap CONFIGURATION_CLIENT = new IntegerMap<>();
+ public final IntegerMap CONFIGURATION_SERVER = new IntegerMap<>();
/**
* Retrieve the correct integer map for a specific protocol and sender.
@@ -44,6 +47,8 @@ class PacketTypeLookup {
return sender == Sender.CLIENT ? STATUS_CLIENT : STATUS_SERVER;
case LOGIN:
return sender == Sender.CLIENT ? LOGIN_CLIENT : LOGIN_SERVER;
+ case CONFIGURATION:
+ return sender == Sender.CLIENT ? CONFIGURATION_CLIENT : CONFIGURATION_SERVER;
default:
throw new IllegalArgumentException("Unable to find protocol " + protocol);
}
@@ -87,11 +92,6 @@ class PacketTypeLookup {
}
}
- // Packet IDs from 1.6.4 and below
- private final IntegerMap legacyLookup = new IntegerMap<>();
- private final IntegerMap serverLookup = new IntegerMap<>();
- private final IntegerMap clientLookup = new IntegerMap<>();
-
// Packets for 1.7.2
private final ProtocolSenderLookup idLookup = new ProtocolSenderLookup();
@@ -123,9 +123,11 @@ class PacketTypeLookup {
* Retrieve a packet type from a legacy (1.6.4 and below) packet ID.
* @param packetId - the legacy packet ID.
* @return The corresponding packet type, or NULL if not found.
+ * @deprecated no longer works and will always return null
*/
+ @Deprecated
public PacketType getFromLegacy(int packetId) {
- return legacyLookup.get(packetId);
+ return null;
}
/**
@@ -142,20 +144,11 @@ class PacketTypeLookup {
* @param packetId - the legacy packet ID.
* @param preference - which packet type to look for first.
* @return The corresponding packet type, or NULL if not found.
+ * @deprecated no longer works and will always return null
*/
- public PacketType getFromLegacy(int packetId, Sender preference) {
- if (preference == Sender.CLIENT)
- return getFirst(packetId, clientLookup, serverLookup);
- else
- return getFirst(packetId, serverLookup, clientLookup);
- }
-
- // Helper method for looking up in two sets
- private T getFirst(int packetId, IntegerMap first, IntegerMap second) {
- if (first.containsKey(packetId))
- return first.get(packetId);
- else
- return second.get(packetId);
+ @Deprecated
+ public PacketType getFromLegacy(int packetId, Sender preference) {
+ return null;
}
/**
diff --git a/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/src/main/java/com/comphenix/protocol/events/PacketContainer.java
index db7d2af3..aebcb8cd 100644
--- a/src/main/java/com/comphenix/protocol/events/PacketContainer.java
+++ b/src/main/java/com/comphenix/protocol/events/PacketContainer.java
@@ -34,6 +34,7 @@ import java.util.function.Function;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.injector.StructureCache;
+import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.ObjectWriter;
import com.comphenix.protocol.reflect.StructureModifier;
@@ -56,6 +57,7 @@ import com.comphenix.protocol.utility.MinecraftMethods;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.Converters;
+import com.comphenix.protocol.wrappers.WrappedStreamCodec;
import com.google.common.collect.Sets;
import io.netty.buffer.ByteBuf;
import io.netty.util.ReferenceCountUtil;
@@ -345,6 +347,11 @@ public class PacketContainer extends AbstractStructure implements Serializable {
}
Function