I know how to run command on PlayerInteractEvent but how do i make it run command such as givemoney {player} 10000 Any help are highly appreciated!
just a simple command without {player} like /time set day edit: public function onInteract(PlayerInteractEvent $event){ $p = $event->getPlayer(); $item = $event->getItem(); if($item->getId() === 339) { $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "time set day"); $p->getInventory()->removeItem(Item::get(339)); There! I just dont know how to use with {player} :/
Oh, you're almost there. Suppose this is your command: PHP: $cmd = "setgroup {player} Admin"; And you'd like to replace {player} with the player's name... You can use str_replace here. PHP: $player = $p->getName();$cmd = str_replace("{player}", $player, $cmd); Or a one liner... PHP: $cmd = str_replace("{player}", $p->getName(), "setgroup {player} Admin"); P.S. You might want to read this: Players with space in their username!