How to attach to other plugins like iConomy?

Discussion in 'Plugin Development' started by retsrif, Feb 27, 2011.

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

    retsrif

    How can I do that? An example that deals with iConomy would preferably be better. :)
     
  2. Offline

    Raphfrk

    You use

    Code:
    Plugin plugin = p.getServer().getPluginManager().getPlugin("<Whatever the name>");
    
    However, you need to do it when your plugin is enabled and also create a server listener

    Code:
            pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Normal, this);
            pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Normal, this);
    
    If your plugin is enabled before the other plugin, then the first method will return false. If your plugin is enabled after the other plugin, then the 2nd method won't work, since you won't have registered the listener before the plugin was started.
     
  3. Offline

    darknesschaos

    that is useless and annoying because of that clause.
     
  4. Offline

    retsrif

    Yeah I've done that, and darkness it's so true! I've figured out the problem lies with iConomy. I get so frustrated when the plugin authors don't even tell you how you can use their API. Is this a good server listener? :
    Code:
     private class Listener extends ServerListener {
    
         public Listener() { }
    
         @Override
         public void onPluginEnabled(PluginEvent event) {
             if(event.getPlugin().getDescription().getName().equals("iConomy")) {
                 MyPlugin.iConomy = (iConomy)event.getPlugin();
                 log.info("[MyPlugin] Attached to iConomy.");
             }
         }
     }
     
  5. Offline

    fullwall

    Yep, looks good, as long as MyPlugin.iConomy is an iConomy plugin object.
     
  6. Offline

    retsrif

    Yeah I don't even have the correct imports, so I can't even know that now. Niji messed up the code and docs... Though thanks for checking my SL now. :)
     
Thread Status:
Not open for further replies.

Share This Page