07.04.2016, 19:33
@dusk: Yes, of course, this is possible. You add your dependency to your target projects as usual, and then you need to add a little bit of code. Of course, only one plugin will be loaded at a time, and that means that one of your two plugins will load after your first one, which means that one will lack the required dependency at the onEnable() method. To fix this, you can use the ResourceLoadedEvent. I made a little example for you:
You will need to add this code to both of your plugins (I didn't test this, but it SHOULD work
).
PHP код:
@Override
protected void onEnable() throws Throwable {
eventManager = getEventManager();
//Replace Plugin.class with your target plugin
Plugin plugin = ResourceManager.get().getPlugin(Plugin.class); //Try to get the instance of the target plugin.
if(plugin != null) myPluginLoaded(plugin); //If the plugin was found, trigger a custom event (not necessarily needed)
else { //If the plugin was not found, because this plugin is loaded before, then:
EventManagerNode resourceLoadNode = eventManager.createChildNode(); //Make a temporary EventManager
resourceLoadNode.registerHandler(ResourceLoadEvent.class, e -> { //Register the ResourceLoadEvent
if(e.getResource().getClass() == Plugin.class) { //If the loaded resource is of type Plugin (<-- change)
myPluginLoaded((Plugin) e.getResource()); //Trigger callback method (this is not necessarily needed)
resourceLoadNode.destroy(); //Destroy the temporary EventManager because it will not be neaded
}
});
}
}
private void myPluginLoaded(Plugin plugin) {
//Interact with the loaded event, maybe assign it to a variable.
}
).

