Calling method from other plugin

Discussion in 'Plugin Development' started by johnnyD, Feb 10, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    johnnyD

    Having a problem with calling a method from another plugin. I have added it as a library.


    Main class of the plugin that I want to call it to
    Code:
    public BlockGen rgb;
     
        @Override
        public void onEnable() {
         
            Bukkit.getServer().getPluginManager().registerEvents(new HandlerEvents(), this);
         
            rgb = (BlockGen)Bukkit.getPluginManager().getPlugin("RandomBlockGen");
         
         
            if(rgb == null) {
                Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "RANDOMBLOCKGEN NOT WORK");
            }
    
    Events class calling the method
    Code:
    Handler.getInstance().rgb.GenBlocks();

    If you want me to post the code of the class of the plugin being inherited let me know, but its just a general method that does nothing but broadcast a method..

    ALSO heres the error I get in console, ive done my best to try to read through it but I have had no luck with this one.

    STACK:
    Code:
    [21:23:40 ERROR]: Could not pass event PlayerInteractEvent to ArenaHandler v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:724) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_251]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_251]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
    Caused by: java.lang.NullPointerException
            at me.Jake.ArenaHandler.HandlerEvents.onSign(HandlerEvents.java:53) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_251]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot1.8.jar:git-Spigot-c3c767f-33d5de3]
            ... 16 more
    
    Thanks
     
  2. Offline

    Kars

    Post this class:
    me.Jake.ArenaHandler.HandlerEvents.onSign
     
  3. Offline

    johnnyD

    Thats not a class, its a method and it works fine before I place in
    Code:
    Handler.getInstance().rgb.GenBlocks();

    I can post full method if you want? but like i said it works completely fine without that line of code.
     
  4. Offline

    Kars

    @johnnyD right, please show how you export/import the class.
     
  5. Offline

    johnnyD

    Ive imported the class if thats what you're asking. I exported the imported plugin with the plugin this time and I dont get the error in console, but it still doesnt work.
    Code:
    public BlockGen rgb;
    
    @Override
    public void onEnable() {
    
    Bukkit.getServer().getPluginManager().registerEvents(new HandlerEvents(), this);
    
    rgb = (BlockGen)Bukkit.getPluginManager().getPlugin("RandomBlockGen");
    
    
    if(rgb == null) {
    Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "RANDOMBLOCKGEN NOT WORK");
    }
    
    EDIT: now my whole sign event doesnt work.(After exporting with imported plugin)
     
  6. Offline

    Kars

    @johnnyD how are you importing it though?
    You should probably use PluginManager#getPlugin.
     
    Last edited: Feb 12, 2021
  7. Offline

    johnnyD

    My code above shows im using PluginManager.getplugin, I added it as a build path, even imported it as well and still doesnt work..
     
  8. Offline

    Kars

    @johnnyD did you add the plugin to the depend list in plugin.yml?
     
  9. Offline

    johnnyD

    Yea :/
     
  10. Offline

    Kars

    @johnnyD try exposing a singleton instance of the main class that you are importing.
    Something like this:
    PHP:
    // In the main class of the imported plugin
    private static ImportedClass instance;

    @
    Override
    public void onEnable() {
        
    instance this;
    }

    public static 
    ImportedClass getInstance() {
        return 
    instance;
    }
    And then get the instance with that method.
     
    Last edited: Feb 13, 2021
  11. Offline

    johnnyD

    hey thanks a lot, this worked
     
Thread Status:
Not open for further replies.

Share This Page