Block commands for other plugins

Discussion in 'Plugin Development' started by fabe, Jan 23, 2011.

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

    fabe

    Hey,
    I want to block commands for other plugins. I have set following:

    Code:
    getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Monitor, this); // MonitorMode just to try if a other plugin uses a high priority!
    
    public void onPlayerCommand(PlayerChatEvent event) {
    event.setMessage("");
    event.setCancelled(true);
    }
    
    And still a other plugin recognizes the command first, then my plugin.
    Whats wrong?!
     
  2. Offline

    MadMichi

    Hmm... might be the following:
    As you can see here it is recommended by the author that you do
    Code:
    @Override
        public void onPlayerCommand(PlayerChatEvent event)
        {
            if (event.isCancelled()) return; // IMPORTANT: Don't process any further if the command has already been cancelled!
    [...]
    
    So if someone does not ask for event.isCancelled() his code will still be executed... i think... ;)
     
  3. Offline

    Chuck Lieb

    Also, you really shouldn't be altering the event, with setCancelled or anything, in a MONITOR priority, as MONITOR is intended to see the results of the various plugins actions relating to the event. This MIGHT be part of your problem. I have a feeling that other plugins will be using the next highest priority, so you may still have issues if you place your code at that level.

    It goes like this:
    Lowest <-- These go first
    Low
    Normal
    High
    Highest <-- These go last! They have the final say in the final state of the event. They can override any previous priorities!
    Monitor <-- These are to be considered read-only! Monitor is for checking the final outcome of an event ONLY! Trying to change the outcome of an event here may have unexpected consequences, and/or lead to loss of life or limb!

    Suggestions:
    1) Set your priority to HIGHEST instead of MONITOR.
    2) Use .isCancelled to see if you even need to cancel anything... You may not!
    3) You might looks and see if that chat hook is happening before the command hook!
    4) You are still going to be fighting for control of HIGHEST priority. It's inevitable that people are going to want their plugin to have the final say. This is why there are, as of yet, no universal permission plugins.
     
  4. Offline

    fabe

    Thanks! The solution for this is to set the priortity to Lowest!
     
Thread Status:
Not open for further replies.

Share This Page