diff --git a/SpigotCore_Main/src/de/steamwar/command/CommandNode.java b/SpigotCore_Main/src/de/steamwar/command/CommandNode.java index 359da76..f8dff55 100644 --- a/SpigotCore_Main/src/de/steamwar/command/CommandNode.java +++ b/SpigotCore_Main/src/de/steamwar/command/CommandNode.java @@ -38,7 +38,9 @@ class CommandNode { private final TypeMapper typeMapper; private boolean varArg = false; private List commandNodeList = new ArrayList<>(); + private Method executor; + private List helpMessages = new ArrayList<>(); private Predicate commandSenderPredicate; private Function commandSenderObjectFunction; @@ -62,6 +64,10 @@ class CommandNode { commandSenderObjectFunction = parameter.getType()::cast; } + public void addHelpMessage(String helpMessage) { + this.helpMessages.add(helpMessage); + } + public void setVarArg(boolean varArg) { if (commandNodeList.isEmpty()) { this.varArg = varArg; @@ -71,24 +77,9 @@ class CommandNode { } public List tabComplete(CommandSender commandSender, int index, String[] args) { - try { - if (index == args.length - 1) { - return typeMapper.tabCompletes(commandSender, Arrays.copyOf(args, index), args[args.length - 1]); - } - if (typeMapper.map(commandSender, Arrays.copyOf(args, index), args[index]) == null) { - return Collections.emptyList(); - } - if (varArg) { - return tabComplete(commandSender, index + 1, args); - } else { - return commandNodeList.stream() - .map(commandNode -> commandNode.tabComplete(commandSender, index + 1, args)) - .flatMap(List::stream) - .collect(Collectors.toList()); - } - } catch (Exception e) { - return Collections.emptyList(); - } + return internalTabCompleteAndSuggest((commandSender1, integer, strings) -> { + return typeMapper.tabCompletes(commandSender1, Arrays.copyOf(strings, integer), strings[strings.length - 1]); + }, commandSender, index, args); } public boolean execute(CommandSender commandSender, int index, String[] args, List mappedObjects) { @@ -135,7 +126,32 @@ class CommandNode { .findFirst().orElse(false); } - public List suggest(CommandSender commandSender, int index, String[] args, List mappedObjects) { - return null; + public List suggest(CommandSender commandSender, int index, String[] args) { + return internalTabCompleteAndSuggest((commandSender1, integer, strings) -> helpMessages, commandSender, index, args); + } + + private List internalTabCompleteAndSuggest(TriFunction> returnFunction, CommandSender commandSender, int index, String[] args) { + try { + if (index == args.length - 1) { + return returnFunction.apply(commandSender, index, args); + } + if (typeMapper.map(commandSender, Arrays.copyOf(args, index), args[index]) == null) { + return Collections.emptyList(); + } + if (varArg) { + return internalTabCompleteAndSuggest(returnFunction, commandSender, index + 1, args); + } else { + return commandNodeList.stream() + .map(commandNode -> commandNode.internalTabCompleteAndSuggest(returnFunction, commandSender, index + 1, args)) + .flatMap(List::stream) + .collect(Collectors.toList()); + } + } catch (Exception e) { + return Collections.emptyList(); + } + } + + private interface TriFunction { + O apply(I1 i1, I2 i2, I3 i3); } } diff --git a/SpigotCore_Main/src/de/steamwar/command/CommandPart.java b/SpigotCore_Main/src/de/steamwar/command/CommandPart.java new file mode 100644 index 0000000..27c5981 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/command/CommandPart.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +import java.lang.reflect.Method; +import java.util.Map; + +public class CommandPart { + + public CommandPart(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper) { + + } + +}