[TUTORIAL] CommandBlock command handling

Discussion in 'Resources' started by Guichaguri, Sep 19, 2013.

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

    Guichaguri

    I never seen something explaining this before, so I wrote this thread.

    It's simple, like Console with ConsoleCommandSender:
    Code:java
    1. if(sender instanceof ConsoleCommandSender) {
    2. // CONSOLE
    3. }


    You can do the same thing with CommandBlocks using BlockCommandSender:
    Code:java
    1. if(sender instanceof BlockCommandSender) {
    2. // COMMAND BLOCK
    3. }


    But if you like to know where is the commandblock:
    Code:java
    1. if(sender instanceof BlockCommandSender) {
    2. BlockCommandSender cmdblock = (BlockCommandSender)sender;
    3. Block block = cmdblock.getBlock();
    4.  
    5. // DO WHATEVER YOU WANT :)
    6. }
    7.  


    It's VERY simple. I found it searching Bukkit API Docs ( http://jd.bukkit.org/rb/apidocs/org/bukkit/command/BlockCommandSender.html ).
     
    Ultimate_n00b likes this.
  2. Offline

    1Achmed1

    Nice tutorial! It seems to be very simple. Me likey. :)
     
Thread Status:
Not open for further replies.

Share This Page