Pocketmine-mp: Allow us to unregister default commands via plugins

Created on 22 Jul 2017  路  9Comments  路  Source: pmmp/PocketMine-MP

I think default commands should be able to be unregistered

$map = $this->getServer()->getCommandMap(); foreach(["help", "me"] as $name){ $cmd = $map->getCommand($name); $cmd->unregister($map); }

That does nothing, but it should unregister that command? This method works for plugin registered commands, why not defaults?

Right now I just // comment the lines out that register them in my source code because I really don't want them registered. And if I do want to override them I don't want to have to do it all in one spot in my plugin, as that just looks ugly. I wanna register it where I want to in my plugin.

API Implemented

Most helpful comment

I would like to remove the commands without having to do all this hacky stuff. I don't want the commands appearing in the command list, and I don't want to have to override them with another command. I want to completely remove these commands.

All 9 comments

He probably meant to literally unregister it (without overriding).

I would like to remove the commands without having to do all this hacky stuff. I don't want the commands appearing in the command list, and I don't want to have to override them with another command. I want to completely remove these commands.

I know it isn't a code fix, but on production machines that I don't want these on I just remove them from the simple command map.

@MattWAnderson Why?

Simple way to remove it from the command listings and disallow use without coding something to overwrite, or allows me to use it for other reasons in my plugins for custom banning tied to mysql db of player accounts, and banning with logging of who and for what reason.

@MattWAnderson I just use this:

private function setupCommands() {
        $commandMap = $this->getServer()->getCommandMap();  
        $this->unregisterCommands([
            "ban",
            "version"
        ]);
        $commandMap->registerAll("example", [
            new CommandVersion($this),
            new CommandBan($this)
        ]);
    }

    private function unregisterCommands(array $names) {
        $commandMap = $this->getServer()->getCommandMap();
        foreach($names as $name) {
            $command = $commandMap->getCommand($name);
            $command->setLabel($name . "_disabled");
            $command->unregister($commandMap);
        }
    }

Ignore the bad indenting

@mal0ne-23 Might not be the solution your looking for, but what I did to do this is add to my custom Player::class under sendCommandData() check if the command name is in an array of disabled commands, if so, unset the command from the packet, therefore the disabled command doesn't appear to the client.

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Muqsit picture Muqsit  路  3Comments

HipsterAF picture HipsterAF  路  3Comments

L3ice picture L3ice  路  3Comments

jasonwynn10 picture jasonwynn10  路  3Comments

JoshuaACasey picture JoshuaACasey  路  3Comments