SteamWar/SpigotCore
Archiviert
13
0

CMDoS because Brigadier

Dieser Commit ist enthalten in:
yoyosource 2021-07-08 22:46:32 +02:00
Ursprung 7e02212680
Commit 66ae2a837c

Datei anzeigen

@ -47,6 +47,29 @@ class SWCommandBrigadier implements SWCommand.SWCommandInterface {
protected SWCommandBrigadier(SWCommand swCommand, String command, String... aliases) { protected SWCommandBrigadier(SWCommand swCommand, String command, String... aliases) {
this.swCommand = swCommand; this.swCommand = swCommand;
this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) {
@Override
public boolean execute(CommandSender sender, String alias, String[] args) {
if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false;
commandHelpList.stream().anyMatch(s -> s.invoke(sender, args));
return false;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
String string = args[args.length - 1].toLowerCase();
return commandList.stream()
.map(s -> s.tabComplete(sender, args))
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(s -> !s.isEmpty())
.filter(s -> s.toLowerCase().startsWith(string))
.collect(Collectors.toList());
}
};
unregister();
register();
SWCommandUtils.createList(swCommand, commandList, commandHelpList, localTypeMapper, this::createSubCommand); SWCommandUtils.createList(swCommand, commandList, commandHelpList, localTypeMapper, this::createSubCommand);
Stream.of(commandList, commandHelpList).flatMap(List::stream).forEach(subCommand -> { Stream.of(commandList, commandHelpList).flatMap(List::stream).forEach(subCommand -> {
register(command, subCommand, command, aliases); register(command, subCommand, command, aliases);
@ -82,10 +105,7 @@ class SWCommandBrigadier implements SWCommand.SWCommandInterface {
} }
argumentBuilder = requiredArgumentBuilder; argumentBuilder = requiredArgumentBuilder;
if (i == current.arguments.length - 1) { if (i == current.arguments.length - 1) {
argumentBuilder.executes(commandContext -> { argumentBuilder.executes(commandContext -> 1);
current.invoke((CommandSender) commandContext.getCommand(), commandContext.getInput().split(" "));
return 0;
});
} }
} }
if (current.varArgType != null) { if (current.varArgType != null) {
@ -117,28 +137,6 @@ class SWCommandBrigadier implements SWCommand.SWCommandInterface {
if (subCommand.argumentNode == null) { if (subCommand.argumentNode == null) {
return; return;
} }
if (subCommand.normalTabCompleteNeeded && command == null) {
this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) {
@Override
public boolean execute(CommandSender sender, String alias, String[] args) {
if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false;
commandHelpList.stream().anyMatch(s -> s.invoke(sender, args));
return false;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
String string = args[args.length - 1].toLowerCase();
return commandList.stream()
.map(s -> s.tabComplete(sender, args))
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(s -> !s.isEmpty())
.filter(s -> s.toLowerCase().startsWith(string))
.collect(Collectors.toList());
}
};
}
literalArgumentBuilder.then(subCommand.argumentNode); literalArgumentBuilder.then(subCommand.argumentNode);
SWCommand.dispatcher.register(literalArgumentBuilder); SWCommand.dispatcher.register(literalArgumentBuilder);
} }