How to make a Sign execute a command?

Discussion in 'Plugin Development' started by Quantas, Jun 18, 2012.

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

    Quantas

    Hi there!

    I'm started to develop bukkit plugins for myself, and now I would like to create a plugin, which executes a command, if the player right clicks on it. So my question would be this: How can i make a sign execute a command (jcommands.spawn, or /spawn for example [ some kind of teleport command, is what I need]) on right click? Sorry for the question, but this is my...um...2nd plugin (The 1st one doesn't even work lol...)
     
  2. Offline

    Ammar Askar

    Listen to PlayerInteractEvent and check if action is right click and clicked block is sign, if so cast the block.getState() to Sign and scan the lines for spawn. If it is present cast the player to CommandSender and use the dispatchCommand method in the Server like so
    Code:java
    1.  
    2. Bukkit.getServer().dispatchCommand(((CommandSender)event.getPlayer()), "spawn");
    3.  
     
    Quantas likes this.
  3. ^This

    You probably don't even need to cast the player instance.
     
    Quantas likes this.
  4. Offline

    Ammar Askar

    Yeah, seems that the casting isn't necessary. Sorry!
     
    Quantas likes this.
  5. Offline

    Quantas

    Thanks for the answers! I hope i can make it! :) (Liked both of you)
     
  6. Offline

    -_Husky_-

    If you need any more help, im here
     
Thread Status:
Not open for further replies.

Share This Page