dmulloy2 / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
1.03k stars 259 forks source link

createPacket not working on 1.20.4 (and again on 1.20.5/6) ! #2669

Closed Jeppa closed 4 months ago

Jeppa commented 10 months ago

com.comphenix.protocol.ProtocolLibrary.getProtocolManager().createPacket(com.comphenix.protocol.PacketType.Play.Server.SPAWN_ENTITY) throws the following error:

[Server thread/WARN]: java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity [Server thread/WARN]: at java.base/java.util.Objects.requireNonNull(Unknown Source) [Server thread/WARN]: at com.comphenix.protocol.injector.StructureCache.lambda$newPacket$2(StructureCache.java:99) [Server thread/WARN]: at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:103) [Server thread/WARN]: at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:113) [Server thread/WARN]: at com.comphenix.protocol.events.PacketContainer.(PacketContainer.java:117) [Server thread/WARN]: at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:389) [Server thread/WARN]: at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:384)

Version Info Minecraft: Spigot 1.20.4 (8.12.2023) ProtocolLib build #673

Ghost-chu commented 10 months ago

I can also reproduce this issue on Spigot-1.20.4 (3966-Spigot-ce0f71e-cb2ea54) on latest dev build.

dmulloy2 commented 10 months ago

Was able to reproduce this. Looking into it further

dmulloy2 commented 10 months ago

Give the latest build a try: https://ci.dmulloy2.net/job/ProtocolLib/lastBuild/

Shows as failing since not all the tests are passing yet. But it should fix the packet creation issue

Ghost-chu commented 10 months ago

Looks works for me.

Jeppa commented 10 months ago

Seems to be fixed, thanks! ;)

Jeppa commented 10 months ago

Hi again,

It was OK with build #675. Now, with build #676 there is the same error again, and now as well for other packets like: com.comphenix.protocol.PacketType.Play.Server.PLAYER_INFO -> ClientboundPlayerInfoUpdatePacket and com.comphenix.protocol.PacketType.Play.Server.ENTITY_HEAD_ROTATION -> PacketPlayOutEntityHeadRotation (maybe more...)

This seems to be a little random and not every error happes with every serverstart. Sometimes it crashes with the 'ClientboundPlayerInfoUpdatePacket' (PLAYER_INFO), sometimes two packets later with 'PacketPlayOutSpawnEntity' (SPAWN_ENTITY)...

Jeppa commented 10 months ago

OK, Build 677 works again ;)

TheCalypso commented 6 months ago

New problem mention in https://github.com/dmulloy2/ProtocolLib/issues/2856

Jeppa commented 5 months ago

This seems to be broken again (build #686 and MC 1.20.5): java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket

rest is the same as before...

ghost commented 5 months ago

This seems to be broken again (build #686 and MC 1.20.5): java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket

rest is the same as before...

How can you even use 1.20.5? it doesn't work at all

Jeppa commented 5 months ago

This seems to be broken again (build #686 and MC 1.20.5): java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket rest is the same as before...

How can you even use 1.20.5? it doesn't work at all

Spigot 'works' ... paper does not.

seraph-prisons commented 5 months ago

Having the same issue here, can load protocollib with obfuscated version of 1.20.6 as per issue #2900 but still getting the issue with: java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity at java.base/java.util.Objects.requireNonNull(Objects.java:246) ~[?:?] at ProtocolLib.jar/com.comphenix.protocol.injector.StructureCache.lambda$newPacket$2(StructureCache.java:99) ~[ProtocolLib.jar:?] at ProtocolLib.jar/com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:103) ~[ProtocolLib.jar:?] at ProtocolLib.jar/com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:113) ~[ProtocolLib.jar:?] at ProtocolLib.jar/com.comphenix.protocol.events.PacketContainer.(PacketContainer.java:117) ~[ProtocolLib.jar:?] at ProtocolLib.jar/com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:389) ~[ProtocolLib.jar:?] at ProtocolLib.jar/com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:384) ~[ProtocolLib.jar:?]

Jeppa commented 5 months ago

Hi again,

new build 689 now works under Paper again, but still throws errors on packet creation:

e.g. I have two lines of code like this:

com.comphenix.protocol.events.PacketContainer addPlayerPacket = com.comphenix.protocol.ProtocolLibrary.getProtocolManager().createPacket(com.comphenix.protocol.PacketType.Play.Server.PLAYER_INFO);
addPlayerPacket.getPlayerInfoActions().write(0, EnumSet.of(com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction.ADD_PLAYER));

And Spigot still has this error:

java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket - true - com.comphenix.protocol.wrappers.WrappedStreamCodec[handle=net.minecraft.network.codec.StreamCodec$9@286922fc]
    at java.base/java.util.Objects.requireNonNull(Unknown Source)
    at com.comphenix.protocol.injector.StructureCache.lambda$newPacket$4(StructureCache.java:130)
    at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:134)
    at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:144)
    at com.comphenix.protocol.events.PacketContainer.<init>(PacketContainer.java:119)
    at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:389)
    at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:384)

With Paper the crash is at 2nd line like this ('EnumChatVisibility' has to be 'ChatVisibility' in unobfuscated Paper ):

java.lang.RuntimeException: Failed to find NMS class: world.entity.player.EnumChatVisibility
    at ProtocolLib(B689).jar/com.comphenix.protocol.utility.MinecraftReflection.lambda$getMinecraftClass$2(MinecraftReflection.java:1386) ~[ProtocolLib(B689).jar:?]
    at java.base/java.util.Optional.orElseThrow(Unknown Source) ~[?:?]
    at ProtocolLib(B689).jar/com.comphenix.protocol.utility.MinecraftReflection.getMinecraftClass(MinecraftReflection.java:1386) ~[ProtocolLib(B689).jar:?]
    at ProtocolLib(B689).jar/com.comphenix.protocol.wrappers.EnumWrappers.initialize(EnumWrappers.java:503) ~[ProtocolLib(B689).jar:?]
    at ProtocolLib(B689).jar/com.comphenix.protocol.wrappers.EnumWrappers.getPlayerInfoActionClass(EnumWrappers.java:670) ~[ProtocolLib(B689).jar:?]
    at ProtocolLib(B689).jar/com.comphenix.protocol.wrappers.EnumWrappers.getPlayerInfoActionConverter(EnumWrappers.java:769) ~[ProtocolLib(B689).jar:?]
    at ProtocolLib(B689).jar/com.comphenix.protocol.events.AbstractStructure.getPlayerInfoActions(AbstractStructure.java:673) ~[ProtocolLib(B689).jar:?]

Strangely Paper does not crash at first line...

Ghost-chu commented 5 months ago

I can reproduce this issue with Spigot 1.20.6:

java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity - true - com.comphenix.protocol.wrappers.WrappedStreamCodec[handle=net.minecraft.network.codec.StreamCodec$9@eb185d3]
        at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]
        at com.comphenix.protocol.injector.StructureCache.lambda$newPacket$4(StructureCache.java:130) ~[?:?]
        at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:134) ~[?:?]
        at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:144) ~[?:?]
        at com.comphenix.protocol.events.PacketContainer.<init>(PacketContainer.java:119) ~[?:?]
        at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:389) ~[?:?]
        at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:384) ~[?:?]
        at com.ghostchu.quickshop.shop.display.virtual.packetfactory.v1_20_R4.createFakeItemSpawnPacket(v1_20_R4.java:56) ~[?:?]

dump-2024-05-07_17.55.58.txt

  PacketContainer fakeItemPacket = manager.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);
LoneDev6 commented 5 months ago

Same issue

seraph-prisons commented 5 months ago

I can reproduce this issue with Spigot 1.20.6:

java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity - true - com.comphenix.protocol.wrappers.WrappedStreamCodec[handle=net.minecraft.network.codec.StreamCodec$9@eb185d3]
        at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]
        at com.comphenix.protocol.injector.StructureCache.lambda$newPacket$4(StructureCache.java:130) ~[?:?]
        at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:134) ~[?:?]
        at com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:144) ~[?:?]
        at com.comphenix.protocol.events.PacketContainer.<init>(PacketContainer.java:119) ~[?:?]
        at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:389) ~[?:?]
        at com.comphenix.protocol.injector.PacketFilterManager.createPacket(PacketFilterManager.java:384) ~[?:?]
        at com.ghostchu.quickshop.shop.display.virtual.packetfactory.v1_20_R4.createFakeItemSpawnPacket(v1_20_R4.java:56) ~[?:?]

dump-2024-05-07_17.55.58.txt

  PacketContainer fakeItemPacket = manager.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);

Yeah, same here, tested with both obf and deobf version of paper from gradle build.

LoneDev6 commented 5 months ago

More info here: https://github.com/dmulloy2/ProtocolLib/issues/2917

Ghost-chu commented 5 months ago

Still exists on Paper-77 (1.20.6) with ProtocolLib v5.2.1-SNAPSHOT-689

seraph-prisons commented 5 months ago

Are there any temporary work arounds for now?

EuSouVoce commented 5 months ago

Are there any temporary work arounds for now?

@seraph-prisons Fork, change code, compile, just remember to disable tests, otherwise it'll not compile

Jeppa commented 5 months ago

@seraph-prisons Fork, change code, compile, just remember to disable tests, otherwise it'll not compile

So, you know what to change to fix this bug? (I'm NOT talking about the EnumChatVisibility bug that is also mentioned here...)

Raidware commented 5 months ago

Is this fixed?

Jeppa commented 5 months ago

Is this fixed?

No, it's not !

@dmulloy2 : any progress?

Jeppa commented 4 months ago

@dmulloy2 Build 699: still not fixed!

Spigot throws exact same exception when trying getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO);

Paper does not (with PLAYER_INFO), but throws same exception with getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY);

MusclePr commented 4 months ago

In my case...

Caused by: java.lang.NullPointerException: Unable to create packet instance for class class net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket - true - com.comphenix.protocol.wrappers.WrappedStreamCodec[handle=net.minecraft.network.codec.StreamCodec$5@365fc150]
        at java.base/java.util.Objects.requireNonNull(Unknown Source) ~[?:?]
        at ProtocolLib.jar/com.comphenix.protocol.injector.StructureCache.lambda$newPacket$4(StructureCache.java:130) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:134) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.injector.StructureCache.newPacket(StructureCache.java:144) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.events.PacketContainer.<init>(PacketContainer.java:119) ~[ProtocolLib.jar:?]
        at NickAfkPartyPack-1.0.5-PREVIEW1.jar/ml.noahc3.nickafkpartypack.Packets.WrapperPlayServerPlayerInfo.<init>(WrapperPlayServerPlayerInfo.java:15) ~[NickAfkPartyPack-1.0.5-PREVIEW1.jar:?]      

in my code.

11:    public class WrapperPlayServerPlayerInfo extends AbstractPacket {
12:        public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
13:
14:        public WrapperPlayServerPlayerInfo() {
15:            super(new PacketContainer(TYPE), TYPE);  // <--- NPE on Paper 1.20.6
16:            handle.getModifier().writeDefaults();
17:        }
MusclePr commented 4 months ago

In my case...

  • Paper version 1.20.6-137-master@bd5867a (2024-06-04T21:04:28Z)
  • ProtocolLib v5.3.0-SNAPSHOT-699

Fixed in

Thank you!

dmulloy2 commented 4 months ago

You should be able to create all but MAP_CHUNK, SCOREBOARD_OBJECTIVE, and ENTITY_SOUND. Those 3 require some special handling that still needs to be worked out

Jeppa commented 4 months ago

Looks good again ;) The packets I'm using seem to be ok now.

Thanks!