diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java b/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java index 7c54cd06..5b3f3b76 100644 --- a/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java +++ b/cloud-core/src/main/java/cloud/commandframework/CommandHelpHandler.java @@ -34,6 +34,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Set; public final class CommandHelpHandler { @@ -73,8 +74,8 @@ public final class CommandHelpHandler { public @NonNull List<@NonNull String> getLongestSharedChains() { final List chains = new ArrayList<>(); this.commandManager.getCommandTree().getRootNodes().forEach(node -> - chains.add(node.getValue() - .getName() + this.commandManager.getCommandSyntaxFormatter() + chains.add(Objects.requireNonNull(node.getValue()) + .getName() + this.commandManager.getCommandSyntaxFormatter() .apply(Collections .emptyList(), node))); @@ -216,7 +217,11 @@ public final class CommandHelpHandler { if (index < queryFragments.length) { /* We might still be able to match an argument */ for (final CommandTree.Node> child : head.getChildren()) { + @SuppressWarnings("unchecked") final StaticArgument childArgument = (StaticArgument) child.getValue(); + if (childArgument == null) { + continue; + } for (final String childAlias : childArgument.getAliases()) { if (childAlias.equalsIgnoreCase(queryFragments[index])) { head = child; @@ -253,6 +258,7 @@ public final class CommandHelpHandler { * * @param Command sender type */ + @SuppressWarnings("unused") public interface HelpTopic { } diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java index 1c2841e8..18dcbf0e 100644 --- a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java +++ b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java @@ -73,7 +73,6 @@ import java.util.function.Function; * * @param Command sender type */ -@SuppressWarnings("unused") public abstract class CommandManager { private final Map, BiConsumer> exceptionHandlers = new HashMap<>(); @@ -371,7 +370,7 @@ public abstract class CommandManager { * @return Flag builder */ public CommandFlag.@NonNull Builder flagBuilder(final @NonNull String name) { - return CommandFlag.newBuilder(name); + return CommandFlag.newBuilder(name); } /** @@ -580,6 +579,7 @@ public abstract class CommandManager { * @param setting Setting to set * @param value Value */ + @SuppressWarnings("unused") public void setSetting(final @NonNull ManagerSettings setting, final boolean value) { if (value) { diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java index 5f35c4ae..458122c1 100644 --- a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java +++ b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java @@ -85,8 +85,6 @@ import java.util.stream.Collectors; */ public final class CommandTree { - private static final @Nullable Exception NULL_EXCEPTION = null; - private final Object commandLock = new Object(); private final Node> internalTree = new Node<>(null); @@ -144,6 +142,7 @@ public final class CommandTree { commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -169,6 +168,7 @@ public final class CommandTree { .apply(parsedArguments, root), commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -179,6 +179,7 @@ public final class CommandTree { .apply(parsedArguments, root), commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -219,6 +220,7 @@ public final class CommandTree { commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -230,6 +232,7 @@ public final class CommandTree { .apply(parsedArguments, root), commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -252,6 +255,7 @@ public final class CommandTree { commandContext.getSender(), this.getChain(child) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect( Collectors.toList()))); @@ -273,6 +277,7 @@ public final class CommandTree { commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -287,6 +292,7 @@ public final class CommandTree { .getArguments(), child), commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect( Collectors.toList()))); @@ -301,6 +307,7 @@ public final class CommandTree { commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -312,6 +319,7 @@ public final class CommandTree { .apply(parsedArguments, root), commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -336,6 +344,7 @@ public final class CommandTree { .apply(parsedArguments, child), commandContext.getSender(), this.getChain(root) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect( Collectors.toList()))); @@ -349,6 +358,7 @@ public final class CommandTree { result.getFailure().get(), commandContext.getSender(), this.getChain(child) .stream() + .filter(node -> node.getValue() != null) .map(Node::getValue) .collect(Collectors.toList()))); } @@ -429,7 +439,8 @@ public final class CommandTree { commandContext.store(child.getValue().getName(), result.getParsedValue().get()); return this.getSuggestions(commandContext, commandQueue, child); } else if (result.getFailure().isPresent()) { - return child.getValue().getSuggestionsProvider().apply(commandContext, commandQueue.peek()); + final String value = commandQueue.peek() == null ? "" : commandQueue.peek(); + return child.getValue().getSuggestionsProvider().apply(commandContext, value); } } } @@ -606,7 +617,10 @@ public final class CommandTree { if (child.getValue() != null && !child.getValue().isRequired() && size > 1) { throw new AmbiguousNodeException(node.getValue(), child.getValue(), - node.getChildren().stream().map(Node::getValue).collect(Collectors.toList())); + node.getChildren() + .stream() + .filter(n -> n.getValue() != null) + .map(Node::getValue).collect(Collectors.toList())); } } node.children.forEach(this::checkAmbiguity); diff --git a/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/PaperBrigadierListener.java b/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/PaperBrigadierListener.java index 8f9c79a0..a51c16bd 100644 --- a/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/PaperBrigadierListener.java +++ b/cloud-minecraft/cloud-paper/src/main/java/cloud/commandframework/paper/PaperBrigadierListener.java @@ -60,7 +60,7 @@ class PaperBrigadierListener implements Listener { private final PaperCommandManager paperCommandManager; private final String nmsVersion; - PaperBrigadierListener(@Nonnull final PaperCommandManager paperCommandManager) throws Exception { + PaperBrigadierListener(@Nonnull final PaperCommandManager paperCommandManager) { this.paperCommandManager = paperCommandManager; this.brigadierManager = new CloudBrigadierManager<>(this.paperCommandManager, () -> new CommandContext<>(