Fix alias support and add tab completion for it

This commit is contained in:
Norbi Peti 2020-10-14 20:40:56 +02:00
parent af0aed65e0
commit 893b24ed5f
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 8 additions and 8 deletions

View file

@ -288,9 +288,8 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
return registerCommand(command, command.getCommandPath(), commandChar); return registerCommand(command, command.getCommandPath(), commandChar);
} }
protected List<SubcommandData<TC>> registerCommand(TC command, String commandPath, @SuppressWarnings("SameParameterValue") char commandChar) { protected List<SubcommandData<TC>> registerCommand(TC command, String path, @SuppressWarnings("SameParameterValue") char commandChar) {
this.commandChar = commandChar; this.commandChar = commandChar;
val path = command.getCommandPath();
int x = path.indexOf(' '); int x = path.indexOf(' ');
val mainPath = commandChar + path.substring(0, x == -1 ? path.length() : x); val mainPath = commandChar + path.substring(0, x == -1 ? path.length() : x);
//var scmdmap = subcommandStrings.computeIfAbsent(mainPath, k -> new HashSet<>()); //Used to display subcommands //var scmdmap = subcommandStrings.computeIfAbsent(mainPath, k -> new HashSet<>()); //Used to display subcommands

View file

@ -228,10 +228,7 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
((PluginCommand) bukkitCommand).setExecutor(this::executeCommand); ((PluginCommand) bukkitCommand).setExecutor(this::executeCommand);
} }
bukkitCommand = oldcmd == null ? new BukkitCommand(mainPath) : oldcmd; bukkitCommand = oldcmd == null ? new BukkitCommand(mainPath) : oldcmd;
/*System.out.println("oldcmd: " + oldcmd);
System.out.println("bukkitCommand: " + bukkitCommand);*/
} }
//System.out.println("Registering to " + command.getPlugin().getName());
if (CommodoreProvider.isSupported()) if (CommodoreProvider.isSupported())
TabcompleteHelper.registerTabcomplete(command, subcmds, bukkitCommand); TabcompleteHelper.registerTabcomplete(command, subcmds, bukkitCommand);
return bukkitCommand; return bukkitCommand;
@ -465,10 +462,14 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
if (shouldRegister.get()) { if (shouldRegister.get()) {
commodore.register(maincmd); commodore.register(maincmd);
//MinecraftArgumentTypes.getByKey(NamespacedKey.minecraft("")) //MinecraftArgumentTypes.getByKey(NamespacedKey.minecraft(""))
var prefixedcmd = new LiteralCommandNode<>(command2MC.getPlugin().getName().toLowerCase() + ":" + path[0], maincmd.getCommand(), maincmd.getRequirement(), maincmd.getRedirect(), maincmd.getRedirectModifier(), maincmd.isFork()); String pluginName = command2MC.getPlugin().getName().toLowerCase();
for (var child : maincmd.getChildren()) var prefixedcmd = LiteralArgumentBuilder.literal(pluginName + ":" + path[0])
prefixedcmd.addChild(child); .redirect(maincmd).build();
commodore.register(prefixedcmd); commodore.register(prefixedcmd);
for (String alias : bukkitCommand.getAliases()) {
commodore.register(LiteralArgumentBuilder.literal(alias).redirect(maincmd).build());
commodore.register(LiteralArgumentBuilder.literal(pluginName + ":" + alias).redirect(maincmd).build());
}
} }
} }
} }