aadnk / ProtocolLib

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

Failed to find NMS class: DataWatcherRegistry #166

Open rmue11er opened 5 years ago

rmue11er commented 5 years ago

Hello, I get this error on my spigot 1.8.8 server whenever is use a Plugin that uses ProtocolLib.

RuntimeException: Failed to find NMS class: DataWatcherRegistry

ProtocolLib itself loads without an error. the error occurs for example when I do the following:

acketContainer packet = protocolManager.createPacket(PacketType.Play.Server.SPAWN_ENTITY);

        WrapperPlayServerEntityMetadata packet2 = new WrapperPlayServerEntityMetadata();
        // Set the entity to associate the packet with, which in this case is the client-side entity we created before.
        packet2.setEntityId(78);
        // Create a ProtocolLib WrappedDataWatcher from the entity's current metadata.
        WrappedDataWatcher dataWatcher = new WrappedDataWatcher(packet2.getEntityMetadata());
        WrappedDataWatcher.WrappedDataWatcherObject isInvisibleIndex = new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class));
        dataWatcher.setObject(isInvisibleIndex, (byte) 0x20);
        WrappedDataWatcher.WrappedDataWatcherObject nameValue = new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(String.class));
        WrappedDataWatcher.WrappedDataWatcherObject nameVisible = new WrappedDataWatcher.WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class));

        dataWatcher.setObject(nameValue, "§aHello, " + p.getDisplayName() + "!");
        dataWatcher.setObject(nameVisible, true);
        packet2.setEntityMetadata(dataWatcher.getWatchableObjects());
        packet2.sendPacket(p);

Full error:

Caused by: java.lang.RuntimeException: Failed to find NMS class: DataWatcherRegistry
at com.comphenix.protocol.utility.MinecraftReflection.lambda$getMinecraftClass$1(MinecraftReflection.java:2025) ~[?:?]
at java.util.Optional.orElseThrow(Optional.java:290) ~[?:1.8.0_212]
at com.comphenix.protocol.utility.MinecraftReflection.getMinecraftClass(MinecraftReflection.java:2025) ~[?:?]
at com.comphenix.protocol.utility.MinecraftReflection.getDataWatcherRegistryClass(MinecraftReflection.java:1372) ~[?:?]
at com.comphenix.protocol.wrappers.WrappedDataWatcher$Registry.initialize(WrappedDataWatcher.java:994) ~[?:?]
at com.comphenix.protocol.wrappers.WrappedDataWatcher$Registry.get(WrappedDataWatcher.java:932) ~[?:?]
at de.krextiv.test.modules.connect.JoinQuitEvent.rankDisplay(JoinQuitEvent.java:48) ~[?:?]
at de.krextiv.test.modules.connect.JoinQuitEvent.onJoin(JoinQuitEvent.java:117) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_212]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_212]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_212]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_212]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[server.jar:git-Spigot-21fe707-e1ebe52]
... 14 more

using the latest protocollib version available for download that says that it is for 1.8 version.

dmulloy2 commented 5 years ago

Yeah so you have to use the old data watcher setup without the registry on 1.8. should be examples around but I'm on mobile

Ultra03 commented 4 years ago

@dmulloy2 Sorry to bring up a relatively old issue, but where can I find these examples? I've been searching around for a while but haven't found anything.

dmulloy2 commented 4 years ago

@Ultra03 it looks like the old examples have vanished (likely to do with curse forge redoing their website). The gist of it is that the old API was a lot simpler than the new one -- you don't have to worry about the watcher registry or anything like that. Take a look at the WrappedDataWatcher and the WrappedWatchableObject docs