Make players run a command when they right click with certain item

Discussion in 'Plugin Development' started by ComeFme, Sep 8, 2015.

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

    ComeFme

    Hey all! I wonder how to force a player run a command when they right click with a specialized item in hand.
    For example, when a player right click with a bone, it makes him run a command /suicide.
     
  2. Offline

    RandomHashTags

    Just created a plugin that does so. If you want any more commands to be added just ask.
    Download : <Edit by Moderator: Redacted not allowed paid resource url>
    Just click the download button.

    If you want to customize your commands, click here for a plugin.
     
    Last edited by a moderator: Dec 5, 2016
  3. Use the PlayerInteractEvent and check if the action is RIGHT_CLICK_AIR or RIGHT_CLICK_BLOCK
     
    CodePlaysMinecraft likes this.
  4. Offline

    ComeFme

    Yes,but how can i make them run commands that I wanted them to run after they right clicked?
     
  5. Offline

    DoggyCode™

    @ComeFme You can use
    Player#chat("/command (args...)");

    even though this not be the best idea, because if you want the player to run a specific command that the player usually don't have permission to, then this wouldn't work. But I know there is a method that you can make a player execute a command as a console (with all permissions, so the command won't return null whenever you type it if the player don't have permission to it).

    I know that you also can use
    Player#performCommand("/command (args....)");

    But again the scenario above would happen. Hmm, not sure if Bukkit still actually supports this, but you can try:
    Bukkit.getServer().dispatchCommand(Player, "command (args...)"); //CommandSender, String cmd

    In that method you wouldn't use the "/" ^
     
Thread Status:
Not open for further replies.

Share This Page