ProtocolLib

3M Downloads

ProtocolLibrary.getProtocolManager() is null (1.20)

Kyren223 opened this issue ยท 9 comments

commented
  • This issue is not solved in a development build

Describe the bug
ProtocolLibrary.getProtocolManager() returns null

To Reproduce
Steps to reproduce the behavior:

  1. Make a 1.20 plugin that uses ProtocolLib v5.0.0
  2. Put protocol lib plugin version 5.0.0 on the 1.20 spigot server
  3. Put the plugin created on that same spigot server
  4. Make the plugin invoke a method from ProtocolLibrary.getProtocolManager()
  5. See error (stack trace) in console saying the method cannot be invoked because the instance was null

Expected behavior
The ProtocolLibrary.getProtocolManager() method will return a valid instance of a ProtocolManager class (not null)

Version Info
https://pastebin.com/ETWBRRb8

commented

Maven

commented

You can scope the ProtocolLib dependency as provided in your pom.xml. Like so:

    <dependency>
      <groupId>com.comphenix.protocol</groupId>
      <artifactId>ProtocolLib</artifactId>
      <version>5.1.0-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency>
commented

I know two cases where this could occur.
Please validate that you

  1. Do not access ProtocolLibrary.getProtocolManager() in onLoad()
  2. Do not shade a copy of ProtocolLib into your plugin. In this case, ProtocolLibrary.getProtocolManager() will try to access the shaded copy of ProtocolLib, which will never be initialized because it is not loaded as a plugin.
commented
  1. I access the method in a util function that is called only when a condition is met in a server event
  2. How can I determine if I shade a copy of ProtocolLib? I might be doing it
    Also I was using another plugin (someone else made) that also requires ProtocolLib and it had the same error
commented
  1. Okay, then this should not be the issue.
  2. The easiest way is to open the Jar of your plugin with e.g. WinRAR or 7Zip and check if there is a com/comphenix/ Folder inside. This folder should be only in the ProtocolLib.jar.
commented

Yes the protocol is shaded, how do I build it without it?

commented

Are you using Maven or Gradle?

commented

This doesn't seem to solve my issue, here's the exact exception:
Cannot invoke "com.comphenix.protocol.ProtocolManager.createPacket(com.comphenix.protocol.PacketType)" because "pm" is null
I checked the jar and it now only contains my package (no com package)
And the exact same error seemed to happen to another plugin api for 1.19
I think the issue is running it on 1.20

commented

Please check the log for any other exceptions, especially when protocollib gets enabled.
Also, please check if any other plugin includes the shaded version ProtocolLib and remove it.