Added some alias support for subcommands

Hmm
This commit is contained in:
Norbi Peti 2020-09-02 03:12:07 +02:00
parent cedeca2f61
commit 28e44d5179
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 8 additions and 2 deletions

View file

@ -37,7 +37,7 @@ public final class ChromaUtils {
/**
* May return null.
*
* @return The full name that can be used to uniquely indentify the user.
* @return The full name that can be used to uniquely identify the user.
*/
String getFancyFullName();
}
@ -77,7 +77,7 @@ public final class ChromaUtils {
*
* @param what What to do
* @param def Default if async
* @return The event cancelled state or false if async.
* @return The value supplied by the action or def if async.
*/
public static <T> T doItAsync(Supplier<T> what, T def) {
if (Bukkit.isPrimaryThread())

View file

@ -67,6 +67,8 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
* Used to be "tbmc.admin". The {@link #MOD_GROUP} is provided to use with this.
*/
String permGroup() default "";
String[] aliases() default {};
}
@Target(ElementType.PARAMETER)
@ -318,6 +320,8 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
ht = getParameterHelp(method, ht, subcommand, params);
var sd = new SubcommandData<>(method, command, params, ht);
subcommands.put(subcommand, sd); //Result of the above (def) is that it will show the help text
for (String alias : ann.aliases())
subcommands.put(commandChar + path + alias, sd);
addedSubcommands.add(sd);
scmdHelpList.add(subcommand);
nosubs = false;
@ -401,6 +405,8 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
if (ann == null) continue;
val subcommand = commandChar + path + getCommandPath(method.getName(), ' ');
subcommands.remove(subcommand);
for (String alias : ann.aliases())
subcommands.remove(alias);
}
}