Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having problem with protocolManager is null #2927

Open
khangdh5200 opened this issue May 13, 2024 · 1 comment
Open

having problem with protocolManager is null #2927

khangdh5200 opened this issue May 13, 2024 · 1 comment

Comments

@khangdh5200
Copy link

  1. I am creating plugin in version 1.20.4 paper (bukkit),
  2. version dependencies:

    com.comphenix.protocol
    ProtocolLib
    5.1.0
  3. I added ProtocolLib.jar to my library, the specific version is v5.2.0-SNAPSHOT-679

4. Here my code:

 private ProtocolManager protocolManager;
     @Override
     public void onEnable() {
         if(getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
             getLogger().severe("ProtocolLib not found");
             getServer().getPluginManager().disablePlugin(this);
             return;
         }
         protocolManager = ProtocolLibrary.getProtocolManager();
         protocolManager.addPacketListener(new PacketAdapter(this, PacketType.Handshake.Client.SET_PROTOCOL) {
             @Override
             public void onPacketReceiving(PacketEvent event) {
                 if(event.getPacketType() == PacketType.Handshake.Client.SET_PROTOCOL) {
                     int clientVersion = event.getPacket().getIntegers().read(0);
                     getLogger().info("Player " + event.getPlayer().getName() + " is using client version: " + clientVersion);
                 }
             }
         });
     }

5. This is an error on the console:

 Error occurred while enabling TempProtocol v1.0-Beta (Is it up to date?)
java.lang.NullPointerException: Cannot invoke "com.comphenix.protocol.ProtocolManager.addPacketListener(com.comphenix.protocol.events.PacketListener)" because "this.protocolManager" is null
        at kanci.gamer.tempprotocol.TempProtocol.onEnable(TempProtocol.java:31) ~[TempProtocol-1.0-Beta.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:287) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:188) ~[paper-1.20.4.jar:git-Paper-496]

6. This is the line that reports the error in the code, as I understand it:

protocolManager.addPacketListener(new PacketAdapter(this, PacketType.Handshake.Client.SET_PROTOCOL) {}

Please guide me how to fix this error. I'm new to programming minecraft plugins, please guide me. Thank people!

@khangdh5200
Copy link
Author

Because I'm trying to connect dependencies with Protocol, my code is just that simple, it has all the libraries added (it doesn't error libraries or codes). I just declare a ProtocolManager and run it in onEnable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant