ProtocolLib

3M Downloads

Problem with WrappedDataWatcher$Registry.OPTIONAL_REGISTRY

TheCalypso opened this issue ยท 1 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version (5.3.0-SNAPSHOT-723)
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

API method(s) used

  • WrappedDataWatcher.getEntityWatcher() / getWatchableObject()
  • WrappedDataWatcher.Registry.get()

Error

[13:39:19 WARN]: [GaspeziaNPCs] Plugin GaspeziaNPCs v1.10.0 generated an exception while executing task 105
java.lang.NullPointerException: Cannot invoke "java.util.Map.getOrDefault(Object, Object)" because "com.comphenix.protocol.wrappers.WrappedDataWatcher$Registry.OPTIONAL_REGISTRY" is null
        at ProtocolLib.jar/com.comphenix.protocol.wrappers.WrappedDataWatcher$Registry.get(WrappedDataWatcher.java:1009) ~[ProtocolLib.jar:?]
        at GNPCs-1.10.0.jar/xxxx.SenderPacketsPlayer.getDefaultWatcher(SenderPacketsPlayer.java:70) ~[GNPCs-1.10.0.jar:?]
        at GNPCs-1.10.0.jar/xxxx.SenderPacketsPlayer.sendMetadataPacketsAsync(SenderPacketsPlayer.java:91) ~[GNPCs-1.10.0.jar:?]
        at GNPCs-1.10.0.jar/xxxx.SenderPacketsPlayer.lambda$sendMetadataPackets$1(SenderPacketsPlayer.java:86) ~[GNPCs-1.10.0.jar:?]
        at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.20.6.jar:1.20.6-133-b8f2101]
        at org.bukkit.craftbukkit.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[paper-1.20.6.jar:1.20.6-133-b8f2101]
        at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[paper-1.20.6.jar:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]

Code

protected void getDefaultWatcher(Player player, Pose entityPose) {
        if (watcher == null) {
            watcher = WrappedDataWatcher.getEntityWatcher(player).deepClone();
            var wo3D = watcher.getWatchableObject(index3D);
            wo3D.setValue(value3D);
        }
        if (entityPose != null) {
            watcher.setObject(indexPose, WrappedDataWatcher.Registry.get(EnumWrappers.getEntityPoseClass()), mapPoseToNMS.get(entityPose));
        }
    }

Additional context
The problem occurs when a player connects "too fast", when the server has just "Done". If the player connects a few seconds later the problem does not occur. I'm not sure how I could get around this problem. Is this a bug in the initialization of Protocollibs or in my use?

Thank you for your help.

commented

Observing the same error running this line 2 ticks after a player joins

WrappedDataValue(10, WrappedDataWatcher.Registry.get(java.lang.Integer::class.java), 3)