onCommand - how to event.setCancelled?

Discussion in 'Plugin Development' started by Kr1sc, Jan 15, 2011.

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

    Kr1sc

    Just want to make sure.

    You run setCancelled(true) when the command cannot be used by your method?
    Or do you setCancelled(true) when the command was interpreted by your method?

    And along the same lines, does Bukkit prevent builtin server commands from running?
     
  2. The second one ;) As soon as the command is successfull, then use setCancelled(true)
     
  3. Offline

    Kr1sc

    I thought so, but wanted to be sure because my commands seem to be blocking the built in commands.
     
  4. I am having some trouble with this event too. Is it meant to exit out of the method when you set it to true? It seems that when I set it, it continues to process the rest of the method.

    e.g.
    Code:
    blah blah onCommand(blahblah)
    {
    if (split.length != 2) {
        player.sendMessage("uasge blah blah");
                    event.setCancelled(true);
    }
     
    oh noes i still continue
    }
     
  5. Offline

    apexearth

    Well you should have a return; after your setCancelled.

    And for the other guy, maybe you don't have a super() in there? I'm just guessing that the super might be calling the main handler. Total guess though.
     
  6. Offline

    mindless728

    Code:
    blah blah onCommand(blahblah)
    {
    if (split.length != 2) {
        player.sendMessage("uasge blah blah");
         event.setCancelled(true);
         return;
    }
     
    oh noes i still continue
    }
    is what you would need as even though you are setting the state of the event as canceled, the function will continue until there is a return
     
  7. Of course, so obvious. Thanks
     
Thread Status:
Not open for further replies.

Share This Page