Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.6 - EnumWrappers.PlayerDigType null #2917

Open
LoneDev6 opened this issue May 8, 2024 · 3 comments
Open

1.20.6 - EnumWrappers.PlayerDigType null #2917

LoneDev6 opened this issue May 8, 2024 · 3 comments

Comments

@LoneDev6
Copy link

LoneDev6 commented May 8, 2024

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

@LoneDev6
Copy link
Author

LoneDev6 commented May 8, 2024

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.

@LoneDev6
Copy link
Author

LoneDev6 commented May 8, 2024

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.

@LoneDev6
Copy link
Author

LoneDev6 commented May 8, 2024

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

@LoneDev6 LoneDev6 closed this as not planned Won't fix, can't repro, duplicate, stale May 8, 2024
@LoneDev6 LoneDev6 reopened this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant