dmulloy2 / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

1.20.6 - EnumWrappers.PlayerDigType null

LoneDev6 opened this issue · comments

This code returns null.

EnumWrappers.PlayerDigType status = packet.getPlayerDigTypes().read(0);

This is the registered packet listener:

new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.BLOCK_DIG)
//.....
> version protocollib
[12:43:48 INFO]: ProtocolLib version 5.2.1-SNAPSHOT-689
[12:43:48 INFO]: Provides read/write access to the Minecraft protocol.
[12:43:48 INFO]: Authors: dmulloy2 and comphenix
> version
[12:43:49 INFO]: Checking version, please wait...
[12:43:50 INFO]: This server is running Paper version git-Paper-49 (MC: 1.20.6) (Implementing API version 1.20.6-R0.1-SNAPSHOT) (Git: ac3a547)
You are 3 version(s) behind
Download the new version at: https://papermc.io/downloads/paper
Previous version: git-Paper-32 (MC: 1.20.6)

image

Doing some tests, this code works fine:

Class clazz = PacketType.Play.Client.BLOCK_DIG.getPacketClass();
int index = 1;
if (clazz == null) {
    // not supported in the current version
    return null;
}

List<Field> enumFields = FuzzyReflection.fromClass(clazz, true).getFieldListByType(Enum.class);
if (enumFields.size() <= index) {
    // also probably not supported
    ProtocolLogger.debug("Enum field not found at index {0} of {1}", index, clazz);
    return null;
}

Class digTypeClazz = enumFields.get(index).getType();
StructureModifier modifier = e.getPacket().structureModifier.withType(digTypeClazz, new EnumWrappers.AliasedEnumConverter(digTypeClazz, EnumWrappers.PlayerDigType.class));
modifier.read(0);

I got it by checking the ProtocoLib repository:
https://github.com/dmulloy2/ProtocolLib/blob/master/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java#L524

https://github.com/dmulloy2/ProtocolLib/blob/master/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java#L615C9-L615C104

So the Enum field is correctly found by the ProtocolLib code, but EnumWrappers.PLAYER_DIG_TYPE_CLASS is null (checked using a debugger).
All static vars "_CLASS" in EnumWrappers seems to be null for some reason.
I have no idea why ProtocolLib fails to set these variables but I can clearly copy and paste (with some little edits to make it work in the debugger window) the same code and it correctly find the stuff needed.

Attaching a debugger, pausing the execution and running this code will fix the issue (dirty fix just to test).

EnumWrappers.PLAYER_DIG_TYPE_CLASS = EnumWrappers.getEnum(com.comphenix.protocol.PacketType.Play.Client.BLOCK_DIG.getPacketClass(), 1);

So for some reason something is resetting the EnumWrappers.PLAYER_DIG_TYPE_CLASS and all other cached static variables of EnumWrappers class.

It's probably due to "Failed to find NMS class: world.entity.player.EnumChatVisibility" error which makes the whole initialize method fail and skip the initializations.
#2913