28.10.2015, 19:18
@dusk: It's currently not possible to set custom names for your parameters, but you can use the @CommandHelp Annotation as a workaround. After that, you can override the default UsageMessageSupplier to output your custom parameters:
If you return false in a Command, the CommandManager will try to find another matching callback, but if it won't find any, the PlayerCommandEvent will not be interrupted. This way, you can make a "Command not found" message using events:
(It's important to use HandlerPriority.BOTTOM, because otherwise it would not be called at the end)
PHP код:
@Command
@CommandHelp("[myCustomArgumentText] [mySecondCustomArgumentText]")
public boolean givecash(Player p, Player target, int amount)
{
...
}
PHP код:
commandManager.setUsageMessageSupplier((issuer, command, prefix, arguments, help) -> {
if(help != null) //if @CommandHelp has been supplied
return "Correct usage: " + prefix + command + " " + help;
else { //If not, use parameterNames from Java
String paramsString = "";
for(int i = 0; i < arguments.length; i++) {
paramsString += "[" + arguments[i] + "]";
if(i + 1 < arguments.length)
paramsString += " ";
}
return "Correct usage: " + prefix + command + " " + paramsString;
}
});
PHP код:
eventManagerNode.registerHandler(PlayerCommandEvent.class, HandlerPriority.BOTTOM, (e) ->
{
Player player = e.getPlayer();
player.sendMessage(Color.RED, "Unknown command. Type /help to see help.");
e.setProcessed();
});