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

Executing command AS player

Discussion in 'Development' started by Zuruki, Apr 13, 2017.

  1. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    How can I make a player execute a command using PlayerInteractEvent when tapping an iron ingot on the floor?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    Code:
    Server::dispatchCommand(CommandSender $sender, string $commandLabel)
    
     
    HimbeersaftLP and Zuruki like this.
  3. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    Can you provide more specific? Like example of actual code
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    yes that's all you need to know
     
    Primus likes this.
  5. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    PHP:
    public function onUseItem(PlayerInteractEvent $event){
      
    $player $event->getPlayer();
      
    $item $event->getItem();

      if(
    $item->getId() == 256){
        
    $this->getServer()->dispatchCommand($player"command");
      }
    }
    is it right ?
     
  6. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    This will execute a command named 'Kohi' on the player interact?
    PHP:
    elseif ($item->getName() == C::BOLD C::GREEN "Kohi"){
           
    $this->MainItems($player);
           
    $this->getServer()->dispatchCommand($player"kohi");
            }
     
  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.