ProtocolLib

3M Downloads

IllegalArgumentException on WorldTypeModifier of Respawn Packet

MrKorvic opened this issue · 4 comments

commented

Describe the bug
java.lang.IllegalArgumentException: Unable to find a method that matches {modifiers=[required: 0, banned: 0], params=[{Type: class name of net.minecraft.(\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}.)+\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}, Index: null}, {Type: Exact class java.lang.String, Index: 0}, {Type: Exact class java.lang.String, Index: 1}, {Type: Exact class java.lang.String, Index: 4}], paramCount=5}

When trying to write to the WorldTypeModifier of a PacketType.Play.Server.RESPAWN packet it fails when using the same data style as in previous versions. When removed to see if it's something I can ignore (since in my code the WorldTypeModifier is just whatever WorldTypeModifier the player is currently in) it errors out with an NPE.

IAE: https://pastebin.com/JUAzx0ZE
NPE: https://pastebin.com/QwVAH25G

To Reproduce
Steps to reproduce the behavior:

  1. Get ProtocolManager
  2. Create PacketContainer of type PacketType.Play.Server.RESPAWN
  3. Attempt to write to the packet#getWorldTypeModifier() with fieldIndex of 0 and the player's current world#getWorldType()
  4. Observe IllegalAccessException

Expected behavior
Set the respawn packet's world type modifier data such that the respawn packet can be sent.

Screenshots
Code which errors; https://pastebin.com/nBp3FNR0
See pastebins above for the IllegalAccessException and NullPointerException on removal.

Version Info
https://pastebin.com/7CpbKUG4

commented

Under wiki.vg the only thing that has 'Resource' in it is the Resource Pack packets,

wiki.vg is useful to know what is actually transported over the wire and what the meaning of each of those fields are as explained in the previous post. ResourceKey is only part of the implementation of the Minecraft protocol. The NMS implementation has one class for each packet specified named as PHASE-DIRECTION-NAME (ex: PlayOutRespawn). ProtocolLib doesn't normally send raw packet, but it relies on those classes. Using the SturctureModifier it sets and reads the fields in this class.

I can write to the field 1 (already writing to field 0) of packet#getGameModes(), and I'd presume that would set enumgamemode1 that I'm seeing in here

If you have something like getGamemodes().write(0, ...), it means look at the class for all fields with EnumGamemode and write to the first one of them you can find. As you might already saw there, there are now two gamemode fields. So you need to set both of them.

but there is no packet#getResourceKeys() (or equivalent) as far as I can tell. Is this the issue that you reopened based on your comment, or am I just really dumb here?

Yes, #906 is about that, but you could use the workaround mentioned there. However it's very messy. Nevertheless the first ResourceKey can be set using the dimension modifier with the changes from #903.

commented

Please take a look at the packet definitions in 1.16. It's very helpful to build Spigot yourself and take a look at the fields of the packet classes. In this case something like playoutrespawn.

You could also use wiki.vg for a description of the fields and the data that is actually sent out. There you could see for example that world level type got removed.

However for ProtocolLib the first approach is more useful, because those fields is what ProtocolLib writes to.

In this instance you get NPE, because you forgot the ResourceKey (mentioned in your last ticket) and the previous game mode. The illegal argument exception is caused, because there is no world level type any more.

commented

Sorry, I'm new to NMS and messing with packets as a whole, trying to get a grip on what's changed due to an update and what-not.

Under wiki.vg the only thing that has 'Resource' in it is the Resource Pack packets, which I'm not sure apply in this situation. I'm unsure how I'm supposed to use this. Is there any documentation on it I can look at regarding ResourceKey usage out there? After trying to look it up I haven't been able to find anything on it.

I've got the PacketPlayOutRespawn.java open, but I'm not sure how to handle modifying packets through ProtocolLib based on that. I can write to the field 1 (already writing to field 0) of packet#getGameModes(), and I'd presume that would set enumgamemode1 that I'm seeing in here, but there is no packet#getResourceKeys() (or equivalent) as far as I can tell. Is this the issue that you reopened based on your comment, or am I just really dumb here?

Also, apologies if this isn't the place for getting help with this. Like I said, not sure what's an update, what's a bug, and what's me being dumb, so I figure throwing it here is the best way to hit all three just in case. Thanks for all your insight so far! It means a lot!

commented

Okay, I got it working now with the work-around! Thanks for the help once again, NMS got my mind all brain-problem'd haha