Skip to content

Instantly share code, notes, and snippets.

@shoghicp
Created October 5, 2014 17:52
Show Gist options
  • Select an option

  • Save shoghicp/a540360b7323f7cc656f to your computer and use it in GitHub Desktop.

Select an option

Save shoghicp/a540360b7323f7cc656f to your computer and use it in GitHub Desktop.

You want to override the tell command, that has also the w and msg aliases by default. The class that will override these commands is MyTellCommand (extends PluginCommand).

To do this, you've to set the original command in a state that allows it to be overriden. Also, aliases will be registered directly, but since all the work was done for the first registration, it's pretty simple.

//We are in the context of a plugin

$commandMap = $this->getServer()->getCommandMap();
$commandToOverride = $commandMap->getCommand("tell");
$commandToOverride->setLabel("tell_disabled"); //This prepares the command for the next step, setting up the Command->nextLabel
$commandToOverride->unregister($commandMap); //This changes the current label

//Now, we can register our command.

$command = new MyTellCommand($this);
$commandMap->register("myfallbackprefix", $command);

//And the aliases
$commandMap->register("myfallbackprefix", $command, "w");
$commandMap->register("myfallbackprefix", $command, "msg");
@iksaku
Copy link

iksaku commented Oct 5, 2014

👍

@iksaku
Copy link

iksaku commented Nov 12, 2014

It's OK if I register the Aliases within the command class?

@dktapps
Copy link

dktapps commented Feb 12, 2019

In modern PM this is quite a bit easier:

$commandMap = $this->getServer()->getCommandMap();
$commandMap->unregister($commandMap->getCommand("tell"));
$commandMap->register(new MyTellCommand());

@dktapps
Copy link

dktapps commented Oct 16, 2025

Sorry for my rude comment in 2019, it's always quite the cringe for me to read my old posts 😬

@iksaku
Copy link

iksaku commented Oct 16, 2025

You just made me go down memory lane... Humble beginnings for many of us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment