Search in sources :

Example 1 with PluginChanged

use of net.runelite.client.events.PluginChanged in project runelite by runelite.

the class PluginManager method startPlugin.

public synchronized boolean startPlugin(Plugin plugin) throws PluginInstantiationException {
    if (activePlugins.contains(plugin) || !isPluginEnabled(plugin)) {
        return false;
    }
    activePlugins.add(plugin);
    try {
        // plugins always start in the event thread
        SwingUtilities.invokeAndWait(() -> {
            try {
                plugin.startUp();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        log.debug("Plugin {} is now running", plugin.getClass().getSimpleName());
        regionTileManager.simulateObjectSpawns(plugin);
        eventBus.register(plugin);
        schedule(plugin);
        eventBus.post(new PluginChanged(plugin, true));
    } catch (InterruptedException | InvocationTargetException ex) {
        throw new PluginInstantiationException(ex);
    }
    return true;
}
Also used : PluginChanged(net.runelite.client.events.PluginChanged) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreationException(com.google.inject.CreationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with PluginChanged

use of net.runelite.client.events.PluginChanged in project runelite by runelite.

the class PluginManager method stopPlugin.

public synchronized boolean stopPlugin(Plugin plugin) throws PluginInstantiationException {
    if (!activePlugins.contains(plugin) || isPluginEnabled(plugin)) {
        return false;
    }
    activePlugins.remove(plugin);
    try {
        unschedule(plugin);
        eventBus.unregister(plugin);
        // plugins always stop in the event thread
        SwingUtilities.invokeAndWait(() -> {
            try {
                plugin.shutDown();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        log.debug("Plugin {} is now stopped", plugin.getClass().getSimpleName());
        eventBus.post(new PluginChanged(plugin, false));
    } catch (InterruptedException | InvocationTargetException ex) {
        throw new PluginInstantiationException(ex);
    }
    return true;
}
Also used : PluginChanged(net.runelite.client.events.PluginChanged) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreationException(com.google.inject.CreationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

CreationException (com.google.inject.CreationException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PluginChanged (net.runelite.client.events.PluginChanged)2