diff --git a/commands-bukkit/pom.xml b/cloud-bukkit/pom.xml similarity index 60% rename from commands-bukkit/pom.xml rename to cloud-bukkit/pom.xml index fa1f61fa..13aa4da3 100644 --- a/commands-bukkit/pom.xml +++ b/cloud-bukkit/pom.xml @@ -1,4 +1,30 @@ + + @@ -9,7 +35,7 @@ 4.0.0 - commands-bukkit + cloud-bukkit @@ -27,7 +53,7 @@ com.intellectualsites - commands-core + cloud-core 1.0-SNAPSHOT diff --git a/commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java b/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java similarity index 100% rename from commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java rename to cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java diff --git a/commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java b/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java similarity index 100% rename from commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java rename to cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java diff --git a/commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandSender.java b/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandSender.java similarity index 100% rename from commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandSender.java rename to cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandSender.java diff --git a/commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitConsoleSender.java b/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitConsoleSender.java similarity index 100% rename from commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitConsoleSender.java rename to cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitConsoleSender.java diff --git a/commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitPlayerSender.java b/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPlayerSender.java similarity index 100% rename from commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitPlayerSender.java rename to cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPlayerSender.java diff --git a/commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java b/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java similarity index 100% rename from commands-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java rename to cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java diff --git a/commands-core/pom.xml b/cloud-core/pom.xml similarity index 94% rename from commands-core/pom.xml rename to cloud-core/pom.xml index 2861f788..1c8e1020 100644 --- a/commands-core/pom.xml +++ b/cloud-core/pom.xml @@ -29,13 +29,13 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - Commands + cloud com.intellectualsites 1.0-SNAPSHOT 4.0.0 - commands-core + cloud-core diff --git a/commands-core/src/main/java/com/intellectualsites/commands/Command.java b/cloud-core/src/main/java/com/intellectualsites/commands/Command.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/Command.java rename to cloud-core/src/main/java/com/intellectualsites/commands/Command.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/CommandManager.java b/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java similarity index 90% rename from commands-core/src/main/java/com/intellectualsites/commands/CommandManager.java rename to cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java index 05a8e800..ae62ea97 100644 --- a/commands-core/src/main/java/com/intellectualsites/commands/CommandManager.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java @@ -25,7 +25,8 @@ package com.intellectualsites.commands; import com.intellectualsites.commands.components.CommandSyntaxFormatter; import com.intellectualsites.commands.components.StandardCommandSyntaxFormatter; -import com.intellectualsites.commands.context.CommandContext; +import com.intellectualsites.commands.context.CommandContextFactory; +import com.intellectualsites.commands.context.StandardCommandContextFactory; import com.intellectualsites.commands.execution.CommandExecutionCoordinator; import com.intellectualsites.commands.execution.CommandResult; import com.intellectualsites.commands.internal.CommandRegistrationHandler; @@ -46,13 +47,15 @@ import java.util.function.Function; */ public abstract class CommandManager { + private final CommandContextFactory commandContextFactory = new StandardCommandContextFactory<>(); + private final CommandExecutionCoordinator commandExecutionCoordinator; private final CommandRegistrationHandler commandRegistrationHandler; private final CommandTree commandTree; private CommandSyntaxFormatter commandSyntaxFormatter = new StandardCommandSyntaxFormatter<>(); - protected CommandManager(@Nonnull final Function, CommandExecutionCoordinator> commandExecutionCoordinator, + public CommandManager(@Nonnull final Function, CommandExecutionCoordinator> commandExecutionCoordinator, @Nonnull final CommandRegistrationHandler commandRegistrationHandler) { this.commandTree = CommandTree.newTree(this, commandRegistrationHandler); this.commandExecutionCoordinator = commandExecutionCoordinator.apply(commandTree); @@ -68,8 +71,7 @@ public abstract class CommandManager { */ @Nonnull public CompletableFuture executeCommand(@Nonnull final C commandSender, @Nonnull final String input) { - final CommandContext context = new CommandContext<>(commandSender); - return this.commandExecutionCoordinator.coordinateExecution(context, tokenize(input)); + return this.commandExecutionCoordinator.coordinateExecution(this.commandContextFactory.create(commandSender), tokenize(input)); } /** @@ -82,8 +84,7 @@ public abstract class CommandManager { */ @Nonnull public List suggest(@Nonnull final C commandSender, @Nonnull final String input) { - final CommandContext context = new CommandContext<>(commandSender); - return this.commandTree.getSuggestions(context, tokenize(input)); + return this.commandTree.getSuggestions(this.commandContextFactory.create(commandSender), tokenize(input)); } @Nonnull diff --git a/commands-core/src/main/java/com/intellectualsites/commands/CommandTree.java b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java similarity index 98% rename from commands-core/src/main/java/com/intellectualsites/commands/CommandTree.java rename to cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java index 8dac77f1..0c8d2367 100644 --- a/commands-core/src/main/java/com/intellectualsites/commands/CommandTree.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java @@ -107,7 +107,11 @@ public class CommandTree { } if (child.getValue() != null) { if (commandQueue.isEmpty()) { - if (child.isLeaf()) { + if (child.getValue().hasDefaultValue()) { + commandQueue.add(child.getValue().getDefaultValue()); + } else if (!child.getValue().isRequired()) { + return Optional.ofNullable(child.getValue().getOwningCommand()); + } else if (child.isLeaf()) { /* Not enough arguments */ throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter() .apply(Objects.requireNonNull( diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java similarity index 81% rename from commands-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java index 68dac4ce..8e08741e 100644 --- a/commands-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java @@ -45,7 +45,7 @@ public class CommandComponent implements Comparable< /** * Indicates whether or not the component is required - * or not. All components prior to any other required + * or not. All c$ git ls-files | xargs wc -lomponents prior to any other required * component must also be required, such that the predicate * (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true, * where {c_0, ..., c_n-1} is the set of command components. @@ -61,17 +61,27 @@ public class CommandComponent implements Comparable< * into the corresponding command type */ private final ComponentParser parser; + /** + * Default value, will be empty if none was supplied + */ + private final String defaultValue; private Command owningCommand; public CommandComponent(final boolean required, @Nonnull final String name, - @Nonnull final ComponentParser parser) { + @Nonnull final ComponentParser parser, @Nonnull final String defaultValue) { this.required = required; this.name = Objects.requireNonNull(name, "Name may not be null"); if (!NAME_PATTERN.asPredicate().test(name)) { throw new IllegalArgumentException("Name must be alphanumeric"); } this.parser = Objects.requireNonNull(parser, "Parser may not be null"); + this.defaultValue = defaultValue; + } + + public CommandComponent(final boolean required, @Nonnull final String name, + @Nonnull final ComponentParser parser) { + this(required, name, parser, ""); } /** @@ -179,6 +189,25 @@ public class CommandComponent implements Comparable< } } + /** + * Get the default value + * + * @return Default value + */ + @Nonnull public String getDefaultValue() { + return this.defaultValue; + } + + /** + * Check if the component has a default value + * + * @return {@code true} if the component has a default value, {@code false} if not + */ + public boolean hasDefaultValue() { + return !this.isRequired() && + !this.getDefaultValue().isEmpty(); + } + /** * Mutable builder for {@link CommandComponent} instances @@ -191,6 +220,7 @@ public class CommandComponent implements Comparable< protected String name; protected boolean required = true; protected ComponentParser parser; + protected String defaultValue = ""; protected Builder() { } @@ -237,6 +267,23 @@ public class CommandComponent implements Comparable< return this; } + /** + * Indicates that the component is optional. + * All components prior to any other required + * component must also be required, such that the predicate + * (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true, + * where {c_0, ..., c_n-1} is the set of command components. + * + * @param defaultValue Default value that will be used if none was supplied + * @return Builder instance + */ + @Nonnull + public Builder asOptionalWithDefault(@Nonnull final String defaultValue) { + this.defaultValue = defaultValue; + this.required = false; + return this; + } + /** * Set the component parser * @@ -256,7 +303,7 @@ public class CommandComponent implements Comparable< */ @Nonnull public CommandComponent build() { - return new CommandComponent<>(this.required, this.name, this.parser); + return new CommandComponent<>(this.required, this.name, this.parser, this.defaultValue); } } diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/CommandSyntaxFormatter.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandSyntaxFormatter.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/components/CommandSyntaxFormatter.java rename to cloud-core/src/main/java/com/intellectualsites/commands/components/CommandSyntaxFormatter.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java rename to cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java rename to cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParser.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParser.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParser.java rename to cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParser.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java similarity index 94% rename from commands-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java index c54fd76e..03e83ef3 100644 --- a/commands-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java @@ -39,8 +39,8 @@ public class ByteComponent extends CommandComponent(min, max)); + private ByteComponent(final boolean required, @Nonnull final String name, final byte min, final byte max, final String defaultValue) { + super(required, name, new ByteParser<>(min, max), defaultValue); this.min = min; this.max = max; } @@ -81,7 +81,7 @@ public class ByteComponent extends CommandComponent build() { - return new ByteComponent<>(this.required, this.name, this.min, this.max); + return new ByteComponent<>(this.required, this.name, this.min, this.max, this.defaultValue); } } @@ -153,12 +153,12 @@ public class ByteComponent extends CommandComponent extends CommandComponent< private final int min; private final int max; - private IntegerComponent(final boolean required, @Nonnull final String name, final int min, final int max) { - super(required, name, new IntegerParser<>(min, max)); + private IntegerComponent(final boolean required, @Nonnull final String name, final int min, final int max, final String defaultValue) { + super(required, name, new IntegerParser<>(min, max), defaultValue); this.min = min; this.max = max; } @@ -57,6 +57,10 @@ public class IntegerComponent extends CommandComponent< return IntegerComponent.newBuilder().named(name).asOptional().build(); } + @Nonnull public static CommandComponent optional(@Nonnull final String name, final int defaultNum) { + return IntegerComponent.newBuilder().named(name).asOptionalWithDefault(Integer.toString(defaultNum)).build(); + } + public static final class Builder extends CommandComponent.Builder { @@ -76,7 +80,7 @@ public class IntegerComponent extends CommandComponent< @Nonnull @Override public IntegerComponent build() { - return new IntegerComponent<>(this.required, this.name, this.min, this.max); + return new IntegerComponent<>(this.required, this.name, this.min, this.max, this.defaultValue); } } @@ -143,12 +147,12 @@ public class IntegerComponent extends CommandComponent< @Override public boolean hasMin() { - return this.getMin().intValue() == Integer.MIN_VALUE; + return this.getMin().intValue() != Integer.MIN_VALUE; } @Override public boolean hasMax() { - return this.getMax().intValue() == Integer.MAX_VALUE; + return this.getMax().intValue() != Integer.MAX_VALUE; } @Override diff --git a/commands-core/src/main/java/com/intellectualsites/commands/context/CommandContext.java b/cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContext.java similarity index 97% rename from commands-core/src/main/java/com/intellectualsites/commands/context/CommandContext.java rename to cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContext.java index 0b0c71e9..2dcdca55 100644 --- a/commands-core/src/main/java/com/intellectualsites/commands/context/CommandContext.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContext.java @@ -35,7 +35,7 @@ import java.util.Optional; * * @param Command sender type */ -public class CommandContext { +public final class CommandContext { private final Map internalStorage = new HashMap<>(); private final C commandSender; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContextFactory.java b/cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContextFactory.java new file mode 100644 index 00000000..e32894fa --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContextFactory.java @@ -0,0 +1,44 @@ +// +// 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.context; + +import com.intellectualsites.commands.sender.CommandSender; + +import javax.annotation.Nonnull; + +/** + * Factory for {@link CommandContext} instances + */ +public interface CommandContextFactory { + + /** + * Create a new command context + * + * @param sender Command sender + * @return Command context + */ + @Nonnull + CommandContext create(@Nonnull C sender); + +} diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/context/StandardCommandContextFactory.java b/cloud-core/src/main/java/com/intellectualsites/commands/context/StandardCommandContextFactory.java new file mode 100644 index 00000000..a5d703ae --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/context/StandardCommandContextFactory.java @@ -0,0 +1,38 @@ +// +// 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.context; + +import com.intellectualsites.commands.sender.CommandSender; + +import javax.annotation.Nonnull; + +public final class StandardCommandContextFactory implements CommandContextFactory { + + @Nonnull + @Override + public CommandContext create(@Nonnull final C sender) { + return new CommandContext<>(sender); + } + +} diff --git a/commands-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java rename to cloud-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java rename to cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java rename to cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java rename to cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java rename to cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java rename to cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java b/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java rename to cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java b/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java rename to cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/execution/CommandResult.java b/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandResult.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/execution/CommandResult.java rename to cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandResult.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java b/cloud-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java rename to cloud-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java diff --git a/commands-core/src/main/java/com/intellectualsites/commands/sender/CommandSender.java b/cloud-core/src/main/java/com/intellectualsites/commands/sender/CommandSender.java similarity index 100% rename from commands-core/src/main/java/com/intellectualsites/commands/sender/CommandSender.java rename to cloud-core/src/main/java/com/intellectualsites/commands/sender/CommandSender.java diff --git a/commands-core/src/test/java/com/intellectualsites/commands/CommandTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTest.java similarity index 100% rename from commands-core/src/test/java/com/intellectualsites/commands/CommandTest.java rename to cloud-core/src/test/java/com/intellectualsites/commands/CommandTest.java diff --git a/commands-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java similarity index 76% rename from commands-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java rename to cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java index 0ae57c6f..55a6b806 100644 --- a/commands-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java @@ -24,6 +24,7 @@ package com.intellectualsites.commands; import com.intellectualsites.commands.components.StaticComponent; +import com.intellectualsites.commands.components.standard.IntegerComponent; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.NoPermissionException; import com.intellectualsites.commands.sender.CommandSender; @@ -36,8 +37,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.*; - class CommandTreeTest { private static CommandManager commandManager; @@ -48,7 +47,10 @@ class CommandTreeTest { commandManager.registerCommand(commandManager.commandBuilder("test") .withComponent(StaticComponent.required("one")).build()) .registerCommand(commandManager.commandBuilder("test") - .withComponent(StaticComponent.required("two")).withPermission("no").build()); + .withComponent(StaticComponent.required("two")).withPermission("no").build()) + .registerCommand(commandManager.commandBuilder("test") + .withComponent(StaticComponent.required("opt")) + .withComponent(IntegerComponent.optional("num", 15)).build()); } @Test @@ -58,6 +60,10 @@ class CommandTreeTest { Assertions.assertTrue(command.isPresent()); Assertions.assertThrows(NoPermissionException.class, () -> commandManager.getCommandTree().parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>( Arrays.asList("test", "two")))); + commandManager.getCommandTree().parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("test", "opt"))) + .ifPresent(c -> c.getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()))); + commandManager.getCommandTree().parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("test", "opt", "12"))) + .ifPresent(c -> c.getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()))); } @Test diff --git a/commands-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java b/cloud-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java similarity index 100% rename from commands-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java rename to cloud-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java diff --git a/commands-core/src/test/java/com/intellectualsites/commands/TestCommandSender.java b/cloud-core/src/test/java/com/intellectualsites/commands/TestCommandSender.java similarity index 100% rename from commands-core/src/test/java/com/intellectualsites/commands/TestCommandSender.java rename to cloud-core/src/test/java/com/intellectualsites/commands/TestCommandSender.java diff --git a/commands-jline/README.md b/cloud-jline/README.md similarity index 100% rename from commands-jline/README.md rename to cloud-jline/README.md diff --git a/commands-jline/pom.xml b/cloud-jline/pom.xml similarity index 90% rename from commands-jline/pom.xml rename to cloud-jline/pom.xml index b117fd18..8c8ded6b 100644 --- a/commands-jline/pom.xml +++ b/cloud-jline/pom.xml @@ -8,7 +8,7 @@ 1.0-SNAPSHOT 4.0.0 - commands-jline + cloud-jline org.jline @@ -17,7 +17,7 @@ com.intellectualsites - Commands + cloud 1.0-SNAPSHOT diff --git a/commands-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java b/cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java similarity index 100% rename from commands-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java rename to cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java diff --git a/commands-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandSender.java b/cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandSender.java similarity index 100% rename from commands-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandSender.java rename to cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandSender.java diff --git a/pom.xml b/pom.xml index 3ad0e2c4..50dd58b3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,22 +5,22 @@ 4.0.0 com.intellectualsites - Commands + cloud 1.0-SNAPSHOT - commands-bukkit - commands-core + cloud-bukkit + cloud-core pom 2020 MIT License - https://raw.githubusercontent.com/Sauilitired/Commands/master/LICENSE + https://raw.githubusercontent.com/Sauilitired/cloud/master/LICENSE - Commands + cloud Commands for Java 1.8