Solved Calling function of other plugin

Discussion in 'Plugin Development' started by marcelo.mb, Dec 30, 2020.

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

    marcelo.mb

    Hey, I try to call functions of another plugin.
    MAINPLUGIN:
    Code:
    public class EconomyManager extends JavaPlugin implements Listener {
       
        ServerManager serverManager;
       
        public void onEnable() {
            //urpsrünglich this
            serverManager = (ServerManager) getServer().getPluginManager().getPlugin("server_manager");
            serverManager.getServerManagerInstance().sendTest();
        }
    }
    And this MAINPLUGIN should call functions of this SECONDPLUGIN:
    Code:
    public class ServerManager extends JavaPlugin {
       
        public ServerManager serverManager;
       
        public ServerManager getServerManagerInstance() {
            return this.serverManager;
        }
       
        public void onEnable() {
            serverManager = this;
        }
       
        public void sendTest() {
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
        }
    }
    My current problem: It says
    What can I do to fix this? Did I make a stupid mistake anywhere?
    Thanks in advance, Marc
     
  2. Offline

    timtower Administrator Administrator Moderator

    @marcelo.mb You left out a lot of code here didn't you?
     
    marcelo.mb likes this.
  3. Offline

    marcelo.mb

    @timtower Hey, I can not see a link if you sent one, but this code I made with help of a few other posts of this forum. I am basically a Javascript and C# developer and here calling a function of the other plugin feels so complicated. The other thing is that I can not find a cool side with clear examples, for example how to call a function of a other plugins. So I am happy for every help.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @marcelo.mb I did not post a link.
    1. Is this all the code? Or is there more code?
    2. Did you compile everything?
    3. Is everything on the same server?
    4. Do you only have 1 plugin with the name "server_manager"
     
    marcelo.mb likes this.
  5. Offline

    marcelo.mb

    @timtower Thanks for your reply.

    1) There is much more code, but I cut off all the irrelevant functions, which are not important for this issue. This makes the code more clearer for everybody. For this, I only have to call the function sendTest().
    2) Yes everything compiled correctly.
    3) Yes, everything is on the same server.
    4) Yes, there is only one Plugin called server_manager.

    Thanks for your patience and help.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @marcelo.mb Then where does that error come from? Your IDE right?
     
    marcelo.mb likes this.
  7. Offline

    marcelo.mb

    @timtower No, the error happens in the console. I already added the plugin to the IDE Project library. BUT. I am stupid. You were right. There was much other code. And in this code, there was the error. I am so sorry, but I admire and thank you for your help.
    Thank you.
     
Thread Status:
Not open for further replies.

Share This Page