cancel command

Discussion in 'Plugin Development' started by goodstuff20, Mar 31, 2013.

Thread Status:
Not open for further replies.
  1. hi guys,
    i wanted to know how to cancel commands that do not exist in the own plugin and apply them to the opponent
    thx - all help apreciated!

    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e) {
    Player player = (Player)e.getPlayer();
    if(player.performCommand("ban Tomy_567")) {
    //?
    }
    }
     
  2. Offline

    ZeusAllMighty11

    lmao when would that ever belong in playerinteractevent?

    Put that code inside a PlayerCommandPreprocessEvent


    Wait, what? Please rephrase your post and take your time!
     
  3. i dont want to argue - i just would like some help

    so how do you cancel the command the player performes (even if its a command from a other plugin like essentials)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    ZeusAllMighty11

    You cancel the event . . .
     
  5. i thought that just cancells the event from my plugin and not the command the player performs
     
  6. Offline

    ZeusAllMighty11

    goodstuff20

    If you check for a command in PlayerCommandPreprocessEvent, and cancel it, it will cancel the command that you checked for >_>
     
    justcool393 likes this.
  7. ok thx - sry wasnt thinking ^^

    so e.setCancelled(true);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  8. Offline

    ZeusAllMighty11

    ... The question is unclear.
     
  9. the question is if e.setCancelled(true); cancelles a event or something else
     
  10. what is the class e?
     
  11. The playercommandpreprosessevent

    it dosent work :(

    @EventHandler
    public void onPlayerCommandPreprosess(PlayerCommandPreprocessEvent e) {
    Player player = (Player)e.getPlayer();
    if(player.performCommand("ban Tomy_567")) {
    e.setCancelled(true);
    }
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  12. Looks good to me.

    You did not mention that you registered the event listener. So I guess you didn't. Google Bukkit Events.
     
  13. Offline

    Tirelessly

    goodstuff20 player.performCommand makes the player do that command. You want e.getMessage(). Also, why are you trying to make yourself unbannable?
     
    ZeusAllMighty11 likes this.
  14. Offline

    ZeusAllMighty11


    That is completely wrong.

    You checked a performing function.
    You put a space in it.
    You need to use e.getMessage()

    Your posts need to be in
    Code:
     or [SYNTAX=JAVA] blocks because it's hard to read
     
  15. Mtihc i did Register - thx though
    Tirelessly i want to make my self unbannable because on my server were trying something out - nothing to do with bukkit

    Thx but the e.setCancelled(true); is correct or?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  16. Offline

    justcool393

    Try this
    Code:java
    1.  
    2. @EventHandler
    3. public void onCommand(PlayerCommandPreProcessEvent e) {
    4. if (e.getMessage() == "/commandyouwanttoblockhere") e.setCancelled(true);
    5. }
    6.  


    I wrote this here, hopefully it works :)
     
  17. Ok thx - sry for the stupid questions guys - feel stupid - but thx anyway (I'm on the iPad often when I ask the questions)
     
  18. Offline

    justcool393

    Glad I could help :D
     
    goodstuff20 likes this.
  19. sry doesnt work :(
     
  20. You might need to remove the slash / in the command?

    I'm just guessing though.
     
  21. Hmmm I don't think so because its message and a message can also be without command
     
  22. Offline

    justcool393

    Oh right, I have this bad habit of doing
    Code:java
    1. if (e.getMessage() == "/whatever")
    instead of
    Code:java
    1. if (e.getMessage().equals("/whatever"))


    Hopefully, that is it. Try changing that part.
     
  23. Thx

    I found other ways already though for example
    Code:
    String m = e.getMessage();
    m.startsWith("/command"); .. And .endsWith
    
    Thx allot though

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
    justcool393 likes this.
Thread Status:
Not open for further replies.

Share This Page