Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bind a command to a item?

Comments in 'Plugin Development' started by Radix, Aug 11, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Is there anyway to bind a command to a item for all players? with implementation of {player}
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Yes
    TigerHix likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I'll add an API for it in Oxidizer (if I ever work on it).
  4. TigerHix
    Offline

    TigerHix Active Member

    Joined:
    May 11, 2015
    Posts:
    61
    Minecraft User:
    TigerHix
    Not sure what you mean by "implementation of {player}", but it is simple; just listen to PlayerInteractEvent and check for the item.

    PHP:
    public function onPlayerInteract(PlayerInteractEvent $event) {
        
    $item $event->getItem();
        if (
    $item->getId() === Item::STICK && ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR || $event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK)) { // If player is holding a stick AND they have just right clicked
            
    $player $event->getPlayer();
            
    // Do something to the player
        
    }
    }
    Remember to register the event handler.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    When player holds item execute command?
  6. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    How would you do that? Code example .. I was thinking of using instance of item?
  7. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    981
    Plugins:
    9
    ...
    TigerHix and Legoboy0215 like this.
  8. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123

Share This Page

Advertisement