uhh im trying to add permission to a nickui command but it doesnt seem to work help pls! function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{ if($sender instanceof Player){ if($command->getName() === "nick"){ if($player->hasPermission)("nick.use")){ $this->openNickUI($sender); } } return true; }
Also replace $player with $sender, because $player isn't defined anywhere. PHP: function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{ if($command->getName() === "nick"){ if($sender instanceof Player){ if($sender->hasPermission("nick.use")){ $this->openNickUI($sender); } } } return true;}
it doesnt work heres the full php file the problem says its at line 96 PHP: <?phpnamespace matze;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\event\Listener;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\utils\Config;use jojoe77777\FormAPI;use jojoe77777\FormAPI\SimpleForm;use jojoe77777\FormAPI\CustomForm;use pocketmine\utils\TextFormat as C;class nickui extends PluginBase implements Listener{ function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{ if($sender instanceof Player){ if($command->getName() === "nick"){ if($sender->hasPermission("nick.use")){ $this->openNickUI($sender); } } return true; } function openNickUI($player){ $form = new SimpleForm(function (Player $player, $data){ $result = $data; if($result === null){ return true; } switch ($result){ case 0: break; case 1: if($this->getConfig()->get("random-nick") === true){ $this->randomNick($player); } elseif($this->getConfig()->get("custom-nick") === true){ $this->openCustomNickUI($player); } break; case 2: if($this->getConfig()->get("custom-nick") === true){ $this->openCustomNickUI($player); } } }); $form->setTitle($this->getConfig()->get("Main-Title")); $form->addButton($this->getConfig()->get("Main-Button-Close")); if($this->getConfig()->get("random-nick") === true){ $form->addButton($this->getConfig()->get("Main-Button-RandomNick")); } if($this->getConfig()->get("custom-nick") === true){ $form->addButton($this->getConfig()->get("Main-Button-CustomNick")); } $form->sendToPlayer($player); return $form; } function randomNick(Player $player){ $zahl = mt_rand(0, count($this->getConfig()->get("random-nicks")) -1 ); $player->setDisplayName($this->getConfig()->get("random-nicks")[$zahl]); $player->setNameTag($this->getConfig()->get("random-nicks")[$zahl]); $message = $this->getConfig()->get("nick-set"); $player->sendMessage(str_replace("{nick}", $this->getConfig()->get("random-nicks")[$zahl], $message)); } function openCustomNickUI($player){ $form = new CustomForm(function (Player $player, $data){ if($data[0] === null){ return true; } if($data[0] !== null){ $config = $this->getConfig(); $config = $config->getAll(); if(!in_array($data[0], $config["not-allow-custom-nicks"])){ $player->setDisplayName($data[0]); $player->setNameTag($data[0]); $message = $this->getConfig()->get("nick-set"); $player->sendMessage(str_replace("{nick}", $data[0], $message)); } else { $player->sendMessage($this->getConfig()->get("not-allowed-nick")); } } }); $form->setTitle($this->getConfig()->get("CustomNick-Title")); $form->addInput("Nick", "Nick", "Nick"); $form->sendToPlayer($player); return $form; }}
it still didnt work herea the updated version PHP: <?phpnamespace matze;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\event\Listener;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\utils\Config;use jojoe77777\FormAPI;use jojoe77777\FormAPI\SimpleForm;use jojoe77777\FormAPI\CustomForm;use pocketmine\utils\TextFormat as C;class nickui extends PluginBase implements Listener{ function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } if($command->getName() === "nick"){ if($sender instanceof Player){ if($sender->hasPermission("nick.use")){ $this->openNickUI($sender); } } } return true;} function openNickUI($player){ $form = new SimpleForm(function (Player $player, $data){ $result = $data; if($result === null){ return true; } switch ($result){ case 0: break; case 1: if($this->getConfig()->get("random-nick") === true){ $this->randomNick($player); } elseif($this->getConfig()->get("custom-nick") === true){ $this->openCustomNickUI($player); } break; case 2: if($this->getConfig()->get("custom-nick") === true){ $this->openCustomNickUI($player); } } }); $form->setTitle($this->getConfig()->get("Main-Title")); $form->addButton($this->getConfig()->get("Main-Button-Close")); if($this->getConfig()->get("random-nick") === true){ $form->addButton($this->getConfig()->get("Main-Button-RandomNick")); } if($this->getConfig()->get("custom-nick") === true){ $form->addButton($this->getConfig()->get("Main-Button-CustomNick")); } $form->sendToPlayer($player); return $form; } function randomNick(Player $player){ $zahl = mt_rand(0, count($this->getConfig()->get("random-nicks")) -1 ); $player->setDisplayName($this->getConfig()->get("random-nicks")[$zahl]); $player->setNameTag($this->getConfig()->get("random-nicks")[$zahl]); $message = $this->getConfig()->get("nick-set"); $player->sendMessage(str_replace("{nick}", $this->getConfig()->get("random-nicks")[$zahl], $message)); } function openCustomNickUI($player){ $form = new CustomForm(function (Player $player, $data){ if($data[0] === null){ return true; } if($data[0] !== null){ $config = $this->getConfig(); $config = $config->getAll(); if(!in_array($data[0], $config["not-allow-custom-nicks"])){ $player->setDisplayName($data[0]); $player->setNameTag($data[0]); $message = $this->getConfig()->get("nick-set"); $player->sendMessage(str_replace("{nick}", $data[0], $message)); } else { $player->sendMessage($this->getConfig()->get("not-allowed-nick")); } } }); $form->setTitle($this->getConfig()->get("CustomNick-Title")); $form->addInput("Nick", "Nick", "Nick"); $form->sendToPlayer($player); return $form; }}
Are you trolling me? You completely missed the onCommand part. Please have at least the most basic understanding of programming before attempting to create a plugin.