Hello ppl! i have a configuration files to allow my plugin register selected commands. for example fly command, i make it to false (disable), see my config below : Code: fly-mode: false and this is my plugin code : PHP: public function registerCommands() {if ($this->getSetting("fly-mode") !== false) $this->getCommand("fly")->setExecutor(new FlyCommand($this));} and after that, 'fly' command has been disabled, but player still can use 'fly' command with output "usage: /fly" my question is, how to prevent player from output message : usage /fly ? thanks
i have an alternative way, i removed usage: /fly on plugin.yml config. is it the best way to solve my problem?
Just add return true; at the end of your code of the command. Removing the usage is like the worst way, the command might not even show up in for example /help
depends on usage if you want to fully disable it means no one can use it you should not register it if you wish to limit it without fall back to returning usage try sandertv method also add the specifyed check to prevent restricted user from using it
well i dont really know then i dont have mention issue but my command listener is not as same as how you do it maybe return void aka return; will do it? no clue just assumptions
Can you show all your code? You don't show other parts of your main plugin, or how you declared the /fly command in the first place, or whether getSettings() works. Assuming getSettings() works, and you declared the /fly command plugin.yml: Your /fly command is declared in plugin.yml, which would create an instance of PluginCommand that sets your plugin main as the executor. If you don't set the executor of the command (if your if-statement is false), it will remain using your plugin main as the executor. You mentioned that you put return true at the end of every command (actually you didn't define any commands! You only defined command executors!), but you most likely missed out the main class. It is a command executor too, and in this case the main class is used as the command executor if you did not register the commands. Therefore, the solution is as simple as adding this function in the main class: PHP: public function onCommand(CommandSender $sender, Command $c, $l, array $a){ $sender->sendMessage("This command is disabled!"); return true;}
False! It will show up in /help. But this is not the right way of fixing problems. You cut the town gas supply from the beginning when there is a leakage, but this doesn't completely fix the problem of gas leakage!
My Main plugin and that code related to command i want to disabled : PHP: public function onEnable(){ $this->getLogger()->info($this->b . "§l§8Var§4Craft §eCore§f enabled!"); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this),$this); $this->loadConfigs(); $this->saveConfig(); $this->registerCommands(); } public function registerCommands() { if ($this->getSetting("fly-mode") !== false) $this->getCommand("fly")->setExecutor(new FlyCommand($this)); } public function loadConfigs() { $this->config = new cfg($this->getDataFolder() . "config.yml", cfg::YAML, [ "fly-mode" => true ]); } here is FlyCommand class : PHP: public function __construct(a $own) { $this->own = $own; } public function onCommand(cs $p, c $c, $l, array $args) { if ($c->getName("fly")) { //code return true; } }
The critical problem is that you didn't show where you declared the command. The best way to do so is to not declare the commands in plugin.yml, but truly register command classes instead of command executor classes.