Hello, i want to add a command to an item that when they "tap" on ground, the "test" command will execute. Here is my code, it doesnt work PHP: public function onInteraction(PlayerInteractEvent $event){ if($event->getItem()->getId()==347){ $command = "test"; $this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command); } }
Don't just say "it doesnt work", tell us some info and errors so we can understand the problem more, Did you register events listener by PHP: $this->getServer()->getPluginManager()->registerEvents($this, $this); Is there more code, maybe the problem is with that code, who knows
I tried to add the code to MSpawns on command hub so when the player did /hub, they will be given clock and when they interact to it, the UI will popup.
Did you register the events listener? Are you sure the "test" command works? your code seems fine to me, i really don't know whats the problem
PHP: <?php/* * MSpawns (v1.5) by EvolSoft * Developer: EvolSoft (Flavius12) * Website: http://www.evolsoft.tk * Date: 27/12/2014 01:26 PM (UTC) * Copyright & License: (C) 2014-2017 EvolSoft * Licensed under MIT (https://github.com/EvolSoft/MSpawns/blob/master/LICENSE) */namespace MSpawns\Commands;use pocketmine\Player;use pocketmine\Server;use pocketmine\command\Command;use pocketmine\command\CommandExecutor;use pocketmine\command\CommandSender;use pocketmine\level\Level;use pocketmine\level\Position;use pocketmine\math\Vector3;use pocketmine\permission\Permission;use pocketmine\plugin\PluginBase;use pocketmine\utils\Config;use pocketmine\utils\TextFormat;use pocketmine\item\Item;use pocketmine\event\player\PlayerInteractEvent;use MSpawns\Main;class Hub extends PluginBase implements CommandExecutor{ public function __construct(Main $plugin){ $this->plugin = $plugin; } public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args): bool{ switch(strtolower($cmd->getName())){ case "hub": if($sender instanceof Player){ if($sender->hasPermission("mspawns.hub")){ $this->plugin->teleportToHub($sender); $sender->getInventory()->setItem(0, Item::get(347, 0, 1)); return true; } else{ $sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command")); return true; } }else{ $sender->sendMessage($this->plugin->translateColors("&", Main::pREFIX . "&cYou can only perform this command as a player")); return true; } break; } return true; } } function onInteraction(PlayerInteractEvent $event){ if($event->getItem()->getId()==347){ $command = "test"; $this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command); } }
Wait wait,, ill explain, I made an UI (Custom UI) and there is a command to popup the UI and that is "test", now ,i want players to have a clock (Server selector) so when they "/hub" and when they tap the ground using the clock, the clock will execute a command to popup the UI
in the plugin yml PHP: commands: test: permission: cui.commandpermissions: cui.command: default: true Now lets stop spamming... ask questions that are important
yes,,its on my plugin.yml , but it doesnt work,,and when i try "/cui test" in a non-op player, they have no permission even ive already add a perm to them
WAS IT /CUI TEST THE WHOLE TIME? dude I suggest you think about the problem before making a thread, and start explaining deeper, because i wont help you next time PHP: $command = "cui test";$this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command); If that doesn't work i will stop helping you until you explain EVERYTHING (errors, code, etc..)
the "test" command i show you is just an example or TEST, its not the real command.. the real command is "cui test". now, my thread is about the "PlayerInteractEvent" that the clock is not executing the command even the code is PHP: public function onInteraction(PlayerInteractEvent $event){ if($event->getItem()->getId()==347){ $command = "cui test"; $this->owner->getServer()->getCommandMap()->dispatch($event->getPlayer(), $command); } } but when i tap on ground using the clock, its not working..