1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Command on Item Tap

Discussion in 'Development' started by Daniel23, Oct 7, 2017.

  1. Daniel23

    Daniel23 Witch

    Messages:
    65
    GitHub:
    daniel23
    Running a command from another Plugin on Item Tap.

    When player interacts with an Item it will
    run a command like /wp [world] on
     
  2. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    dispatchCommand()
     
    jasonwynn10 and Daniel23 like this.
  3. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
    PHP:
    public function handleInteract(PlayerInteractEvent $event){
      
    $items = [Item::BONE => function(Player $player){$player->transfer("127.0.0.1"19133);}, Item::APPLE => function(Player $player){$player->sendMessage("This item not work today. Try in another day! :)");}];
      if(isset(
    $items[$event->getItem()->getId()])){
        
    $items[$event->getItem()->getId()]($event->getPlayer());
      }
    }
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    that doesn't run a command on interact... pretty sure he has the interact part already done.
     
  5. Daniel23

    Daniel23 Witch

    Messages:
    65
    GitHub:
    daniel23
    The Interact part is done, it's just the command
     
  6. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
     
    armagadon159753 and jasonwynn10 like this.
  7. Daniel23

    Daniel23 Witch

    Messages:
    65
    GitHub:
    daniel23
    An example please :D
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Take a look at Server.php :p
     
    jasonwynn10 and iiFlamiinBlaze like this.
  9. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Did you ever find out how to run a command on item interact? If so please help thanks
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    jasonwynn10 and Teamblocket like this.
  11. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  12. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Yes hahahaha
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Perhaps, stop teasing people like this?
     
    jasonwynn10 and R4EVAELRM like this.
  14. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    If you want to run a command when a player holds a certain item:
    PHP:
    public function onItemHeld(PlayerItemHeldEvent $event) {
        
    $player $event->getPlayer();
        
    $item $event->getItem();
        if(
    $item->getId() === 399) { // if the players holds a Nether Star
            
    $player->getInventory()->removeItem(Item::get(399)); // remove the item and run command(s) below
            
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "<command here>"); // runs the command as console
        
    }
    }
    If you want it to run the command only if the interacts with that item, use the PlayerInteractEvent.
     
    Daniel23 likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.