retrooper / packetevents

Precision meets performance—a powerful tool for mastering Minecraft packet manipulation with speed and finesse.
GNU General Public License v3.0
541 stars 152 forks source link

ClassCastException with WrapperPlayClientKeepAlive #346

Closed NoJokeFNA closed 2 years ago

NoJokeFNA commented 2 years ago

Describe the bug An ClassCastException is being thrown after joinin the server.

Code

final PacketReceiveEvent event = packet.getEvent();
final WrapperPlayClientKeepAlive wrapper = new WrapperPlayClientKeepAlive(event);
// Do something with the wrapper
System.out.println(wrapper.getId());

Software brand This server is running NachoSpigot version git-NachoSpigot-"0f63b63" (MC: 1.8.8) (Implementing API version 1.8.8-R0.2-SNAPSHOT) You are 6 version(s) behind Download the new version at: https://nacho.sculas.xyz (Though I can't download the newer version, it's the latest I can get from the given website)

It also happens (most-likely) only on 1.8.8 servers, it doesn't happen on modern server versions [tested: 1.14.4 & 1.18.2]

Plugins Only my testing plugin.

How To Reproduce Steps to reproduce the behavior: (PacketEvents 2.0)

  1. Check if the receiving packet equals PacketType.Client.KEEP_ALIVE
  2. Join the server
  3. See console for errors

Expected behavior Well, the error shouldn't appear

Logs https://sourceb.in/iuirQgExem

Jaren8r commented 2 years ago

Are you using WrapperPlayClientUseItem somewhere else in your code without validating the packet type?

NoJokeFNA commented 2 years ago

That's actually what I thought too, but I'm not using it at all. Also, it doesn't happen on e.g. 1.18.2.

NoJokeFNA commented 2 years ago

After investigating the problem a bit more, it seems to only occur when using a 1.8.x client. It does not occur if you use a client version that is higher. [Tested client-versions: 1.8.8 MysteryMod, 1.8.9, 1.12.2, 1.16.5. 1.18.2]

Jaren8r commented 2 years ago

I can't reproduce this. I'm using NachoSpigot with a 1.8.9 client with only my plugin.

NoJokeFNA commented 2 years ago

Update

Real issue The packet IDs are mixed up. If you try to get the packet ID of e.g. the KeepAlive packet - server is running on 1.8.8 and the client-version is 1.8.9 - you get the ID 47 instead of 33. Therefore, some other packet IDs might also be mixed up and that caused this issue.

MWHunter commented 2 years ago

Fixed by https://github.com/retrooper/packetevents/commit/0f395217503a8a39ba651c8c66d7f93f8b76ac40

Use Item doesn't exist in your version so it had packet ID of 0. Now it has the packet ID of -1 which isn't used.