Added some alias support for subcommands
Hmm
This commit is contained in:
parent
cedeca2f61
commit
28e44d5179
2 changed files with 8 additions and 2 deletions
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue