Override packet types until they are registered at ProtocolLib

Related #1202
This commit is contained in:
games647
2024-05-10 12:07:47 +02:00
parent 9c06401e69
commit 0c64597ff0

View File

@ -32,6 +32,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketFilterManager;
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
@ -112,12 +113,24 @@ public class ProtocolLibListener extends PacketAdapter {
return;
}
plugin.getLog().info("New packet {} from {}", packetEvent.getPacketType(), packetEvent.getPlayer());
Player sender = packetEvent.getPlayer();
PacketType packetType = packetEvent.getPacketType();
if (packetType == START) {
plugin.getLog().info("New packet {} from {}", packetType, sender);
try {
if (packetType.isDynamic()) {
String vanillaName = packetType.getPacketClass().getName();
plugin.getLog().info("Overriding packet type for unregistered packet type to fix ProtocolLib bug");
if (vanillaName.endsWith("ServerboundHelloPacket")) {
packetType = START;
}
if (vanillaName.endsWith("ServerboundKeyPacket")) {
packetType = ENCRYPTION_BEGIN;
}
}
if (packetType == START) {
if (plugin.getFloodgateService() != null) {
boolean success = processFloodgateTasks(packetEvent);
// don't continue execution if the player was kicked by Floodgate
@ -146,8 +159,13 @@ public class ProtocolLibListener extends PacketAdapter {
onLoginStart(packetEvent, sender, username);
break;
}
} else {
} else if (packetType == ENCRYPTION_BEGIN) {
onEncryptionBegin(packetEvent, sender);
} else {
plugin.getLog().warn("Unknown packet type received {}", packetType);
}
} catch (FieldAccessException fieldAccessEx) {
plugin.getLog().error("Failed to parse packet {}", packetEvent.getPacketType(), fieldAccessEx);
}
}
@ -247,7 +265,6 @@ public class ProtocolLibListener extends PacketAdapter {
}
}
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
packetEvent.getAsyncMarker().incrementProcessingDelay();