diff --git a/commands-core/src/main/java/com/intellectualsites/commands/CommandTree.java b/commands-core/src/main/java/com/intellectualsites/commands/CommandTree.java index 8d485889..8dac77f1 100644 --- a/commands-core/src/main/java/com/intellectualsites/commands/CommandTree.java +++ b/commands-core/src/main/java/com/intellectualsites/commands/CommandTree.java @@ -26,6 +26,7 @@ package com.intellectualsites.commands; import com.intellectualsites.commands.components.CommandComponent; import com.intellectualsites.commands.components.StaticComponent; import com.intellectualsites.commands.context.CommandContext; +import com.intellectualsites.commands.exceptions.ComponentParseException; import com.intellectualsites.commands.exceptions.InvalidSyntaxException; import com.intellectualsites.commands.exceptions.NoPermissionException; import com.intellectualsites.commands.exceptions.NoSuchCommandException; @@ -147,7 +148,10 @@ public class CommandTree { return this.parseCommand(commandContext, commandQueue, child); } } else if (result.getFailure().isPresent()) { - /* TODO: Return error */ + throw new ComponentParseException(result.getFailure().get(), commandContext.getCommandSender(), this.getChain(child) + .stream() + .map(Node::getValue) + .collect(Collectors.toList())); } } } diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java b/commands-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java index cd8cc7fd..c54fd76e 100644 --- a/commands-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java +++ b/commands-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java @@ -133,6 +133,7 @@ public class ByteComponent extends CommandComponent extends CommandComponent< if (value < this.min || value > this.max) { return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max)); } + inputQueue.remove(); return ComponentParseResult.success(value); } catch (final Exception e) { return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max)); diff --git a/commands-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java b/commands-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java new file mode 100644 index 00000000..937232fc --- /dev/null +++ b/commands-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java @@ -0,0 +1,46 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +package com.intellectualsites.commands.exceptions; + +import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.sender.CommandSender; + +import javax.annotation.Nonnull; +import java.util.List; + +public class ComponentParseException extends CommandParseException { + + private final Throwable cause; + + public ComponentParseException(@Nonnull final Throwable throwable, @Nonnull final CommandSender commandSender, @Nonnull final List> currentChain) { + super(commandSender, currentChain); + this.cause = throwable; + } + + @Nonnull + public Throwable getCause() { + return this.cause; + } + +} diff --git a/commands-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java b/commands-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java index 7b66835c..0ae57c6f 100644 --- a/commands-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java +++ b/commands-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.Optional; @@ -61,18 +62,8 @@ class CommandTreeTest { @Test void getSuggestions() { - } - - @Test - void testGetSuggestions() { - } - - @Test - void insertCommand() { - } - - @Test - void verifyAndRegister() { + Assertions.assertFalse(commandManager.getCommandTree().getSuggestions(new CommandContext<>(new TestCommandSender()), new LinkedList<>( + Collections.singletonList("test"))).isEmpty()); } }