Disable a plugin

Discussion in 'Plugin Development' started by vildaberper, Apr 1, 2011.

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

    vildaberper

    I can easily disable a plugin by:
    Code:
    this.getPluginLoader().disablePlugin(plugin);
    
    But the problem is that theyre not getting disabled fully.
    It disables the commands, but the events are still there (bukkit still calls the listeners).
    Is it possible to fully disable a plugin?

    Oh, and unload would be cool too, but I guess thats impossible.
     
  2. Offline

    willurd

    I was wondering about this myself. When I first started out I was fully prepared to unregister all of my events in onDisable, but was surprised to not find an unregisterEvent method of some kind in PluginManager (to match registerEvent). I figured PluginManager did that privately in disablePlugin, but I guess I was wrong. I've been thinking about adding that and submitting a pull request. Would look like this:

    Code:
    public void onEnable() {
        pm = getServer().getPluginManager();
        playerListener = new YourPlayerListener(this);
        pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
    }
    
    @Override
    public void onDisable() {
        pm.unregisterEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
        pm.unregisterEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
    }
    

    To answer your question, I have no idea. But I think an unregister method would at least give developers control over that.

    Also, it looks like calling PluginManager.disablePlugin over PluginLoader.disablePlugin might be a better idea anyway, as PluginManager.disablePlugin calls PluginLoader.disablePlugin as well as canceling all of that plugin's running tasks:

    Code:
    public void disablePlugin(final Plugin plugin) {
        if (plugin.isEnabled()) {
            plugin.getPluginLoader().disablePlugin(plugin);
            server.getScheduler().cancelTasks(plugin);
        }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page