Ive got a system in place where if you type /<channelname> <message> it will shoot a message to another channel, without having to focus your chat to that channel. The last time i made this , i hardcoded the channels into my server, and therefore, hardcoded the aliases into the plugin. However i'm looking for a bit more flexibility this time around, so whenever a channel is created, in its constructor, it grabs the command, and edits and sets the aliases: Code: Command cmd = Mane.instance.getCommand("channel"); List<String> aliases = cmd.getAliases(); aliases.add(quick); aliases.add(channelName); cmd.setAliases(aliases); Unfortunately, this isnt working. debug prints out all aliases, and theyre getting the correct aliases, but the server is still saying its an unrecognized command..
The way bukkit works, only commands specifically defined in your plugin.yml file are sent to the onCommand function of your plugin for processing. You can get around this, by using a PlayerCommandPreprocessEvent listener, which fires for every command entered by a player, even if handled by another plugin or even if an invalid command. @EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) { if (e.getMessage().toLowerCase().startsWith("/mychannel ") { sendToChannel(); // handle it e.setCancelled(true); // if you don't want another plugin to try to process the same command } }
As I said, ALL commands are sent to PlayerCommandPreprocess Whereas only commands defined specifically in plugin.yml are sent to onCommand PlayerCommandPreprocess doesn't need to use the literal string "/mychannel" Rather, it can check dynamically... for (String alias : aliases) if (e.getMessage().toLowerCase().startsWith("/" + alias + " ") { ... }
Oh I see what you're asking, what is the point of even having a setAliases method in the API That, I do not know the answer to
That doesnt seem correct, as any alias i put into "commands: "command": aliases [alias]" will trigger for the parent command name on cmd.getName() if a command "derp" has an alias of "herp" and you type /herp, the command will fire as cmd.getName() == "derp" while String label == "herp"
i have them set into a constructor that technically is firing during onEnable. That said, it really shouldnt matter when you set the aliases.
It seems like if you want to do this, you'd have to use reflection to modify the command's CommandMap. It would probably be easier to just use the PlayerCommandPreprocessEvent.