Catching commands

Discussion in 'Plugin Development' started by UltraMC, Jan 26, 2014.

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

    UltraMC

    As far I'm aware commands are overlapping each other: if your plugin uses command /test and mine uses /test one of them will work, right?

    Is there a way to listen for commands like actual events in way:
    - if command is /test
    - pass it to plugin A
    - pass it to plugin B

    So I could cancel other plugin's commands if I wish.
     
  2. Offline

    Th3Br1x

    Code:java
    1. @EventHandler
    2. public void onPlayerChat(PlayerChatEvent evt){
    3. Player p = evt.getPlayer();
    4. if(evt.getMessage().equalsIgnoreCase("/test")){
    5. p.performCommand("test");
    6. //then do, what your plugin do after using the command
    7.  
    8. evt.setCancelled(true);
    9. }
    10. }


    Is this what you're looking for?

    Edit: Added the setCancelled(true)
     
  3. Offline

    TryB4

    UltraMC
    PlayerCommandPreprocessEvent
     
  4. Offline

    Th3Br1x

    I never used this event, but the method i posted before should also work.
     
  5. Offline

    UltraMC

    Th3Br1x

    Never though about catching it as PlayerChat. You are ceancelling it - OK, yet it will still register as command for other plugin, right?
     
Thread Status:
Not open for further replies.

Share This Page