How to link 2 plugins?

Discussion in 'Plugin Development' started by gyus, Feb 26, 2014.

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

    gyus

    Hi all, a little query here!

    How can i get the main class of a plugin A from a plugin B? Sorry, im noob hehe
     
  2. Offline

    TryB4

    gyus
    Add it as a dependency like you would with bukkit.
     
    Benlewis9000 likes this.
  3. Offline

    tamajpm

    You can import the .jar file from the plugin like the Bukkit jar. After you did that you can make an object in your main class with the main class name of the imported jar file. After that you can access public or public static methods from a B plugin. Like:

    private static BPlugin bPlugin = new BPlugin();
    bPlugin.getManager().registerUser(p.getName());

    This was an example.

    PS: If you don't know the name of the main class from the other plugin you can check the plugin.yml and go to the main variable. The last word after a . is the final main class name.
     
  4. Offline

    MordorKing78

    Simple right-click on your project than: properties>javabuildpath>libaries>addexternaljars> and then add the plugin!
     
  5. Offline

    gyus

    Hmmm maybe i have explained me bad...

    I know how to add my plugin as a library of another project, and i know that i have to declare a variable of "plugin A type". The query is how i get the main instance for him? I've undestrood that when you add a plugin to your server, craftbukkit create an object of the main class for each plugin you have. If i create "by hand" an object of "plugin A" on my plugin, it would create ANOTHER instance of the same plugin that bukkit have already instanced (am i wrong?)

    I just want to know how the get form plugin B the instance of plugin A that bukkit have created first, in order to use plugin A' methods etc etc.


    Or maybe im doing the wrong question.... hehehe

    tamajpm

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  6. Offline

    xTigerRebornx

    gyus You can use Bukkit.getPluginManager().getPlugin(String name) and then use an instanceof check to see if it is your plugin, and then cast it to Plugin A's class that extends JavaPlugin (as you should never use an instance of your plugin not created by Bukkit)
     
  7. Offline

    gyus

Thread Status:
Not open for further replies.

Share This Page