Hey! I want to make a command on the item, but it's not good for something. (Maybe bind a command to item?) "Item Code": PHP: }elseif($item->getCustomName() == "§eTeleporter"){ $name = $sender->getName(); $this->getServer()->dispatchCommand(new ConsoleCommandSender("teleport $name")); Thanks for the help! Bye
}elseif($item->getCustomName() == "§eTeleporter"){ $name = $sender->getName(); $this->getServer()->dispatchCommand(new ConsoleCommandSender("teleport ". $name ." ".$x." ".$y." ".$z)); But where did you wright this code? You need to wright in a PlayerInteractEvent function
PHP: }elseif($item->getCustomName() == "§eTeleporter"){ $name = $sender->getName(); $where = new \pocketmine\math\Vector3($x, $y, $z); // Replace x y z variables with your xyz coords. $sender->teleport($where);
You can use PlayerInteractEvent PHP: public function onInteract(PlayerInteractEvent $ev){ $player = $ev->getPlayer(); $item = $player->getItem(); if($item->getCustomName() === "§aTeleporter" && ($ev->getAction() === PlayerInteractEvent::LEFT_CLICK_BLOCK || $ev->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK)) { $this->getServer()->getCommandMap()->dispatch(new ConsoleCommandSender(),"tp " . $player->getName() . $x . " " . $y . " " . $z/*You have to define $x, $y & $z*/); }}