CMDoS because Brigadier
Dieser Commit ist enthalten in:
Ursprung
834969959a
Commit
bc966247a8
@ -24,54 +24,33 @@ import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.server.v1_15_R1.CommandListenerWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.IntPredicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class SWCommandBrigadier implements SWCommand.SWCommandInterface {
|
||||
|
||||
private final String command;
|
||||
private final String[] aliases;
|
||||
|
||||
private final SWCommand swCommand;
|
||||
private Command command;
|
||||
private final List<SubCommand> commandList = new ArrayList<>();
|
||||
private final List<SubCommand> commandHelpList = new ArrayList<>();
|
||||
private final Map<String, TypeMapper<?>> localTypeMapper = new HashMap<>();
|
||||
|
||||
protected SWCommandBrigadier(SWCommand swCommand, String command, String... aliases) {
|
||||
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;
|
||||
}
|
||||
this.command = command;
|
||||
this.aliases = aliases;
|
||||
|
||||
@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());
|
||||
}
|
||||
};
|
||||
this.swCommand = swCommand;
|
||||
SWCommandUtils.createList(swCommand, commandList, commandHelpList, localTypeMapper, this::createSubCommand);
|
||||
Stream.of(commandList, commandHelpList).flatMap(List::stream).forEach(subCommand -> {
|
||||
register(this.command.getName(), subCommand);
|
||||
for (String s : this.command.getAliases()) {
|
||||
register(command, subCommand);
|
||||
for (String s : aliases) {
|
||||
register(s, subCommand);
|
||||
}
|
||||
});
|
||||
@ -105,7 +84,7 @@ class SWCommandBrigadier implements SWCommand.SWCommandInterface {
|
||||
argumentBuilder = requiredArgumentBuilder;
|
||||
}
|
||||
if (current.varArgType != null) {
|
||||
// TODO: UNSUPORTED
|
||||
// TODO: UNSUPPORTED
|
||||
/*Parameter parameter = parameters[parameters.length - 1];
|
||||
Class<?> parameterType = parameter.getType();
|
||||
TypeMapper<?> typeMapper = arguments[arguments.length - 1];
|
||||
@ -154,17 +133,15 @@ class SWCommandBrigadier implements SWCommand.SWCommandInterface {
|
||||
|
||||
@Override
|
||||
public void unregister() {
|
||||
SWCommandUtils.knownCommandMap.remove(command.getName());
|
||||
command.getAliases().forEach(SWCommandUtils.knownCommandMap::remove);
|
||||
command.unregister(SWCommandUtils.commandMap);
|
||||
SWCommandUtils.knownCommandMap.remove(command);
|
||||
Arrays.stream(aliases).forEach(SWCommandUtils.knownCommandMap::remove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
SWCommandUtils.commandMap.register("steamwar", this.command);
|
||||
Stream.of(commandList, commandHelpList).flatMap(List::stream).forEach(subCommand -> {
|
||||
register(command.getName(), subCommand);
|
||||
for (String s : command.getAliases()) {
|
||||
register(command, subCommand);
|
||||
for (String s : aliases) {
|
||||
register(s, subCommand);
|
||||
}
|
||||
});
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren