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

Solved run command if i hold an item?

Comments in 'Plugin Development' started by cake23, May 19, 2016.

  1. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Hey! How can I run a command if I hold a stick or something else?
    For example if a hold the stick, the command /help will be run.
    Does something like $this->getServer()->runCommand()...exist? :rolleyes:
    Thanks!
    PaulchenHD likes this.
  2. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    PHP:
    public function holdItem(PlayerItemHeldEvent $event) {
        if(
    $event->getItem() instanceof Stick) {
             
    // Command Time!
             
    $this->getServer()->getCommandMap()->dispatch($event->getPlayer(), "help");
        }
    }
    Last edited: May 19, 2016
    cake23 and PaulchenHD like this.
  3. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Thank you very much, I will try it out! <3
  4. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Check the edit, that was some mistake!
    cake23 likes this.

Share This Page

Advertisement