diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 00000000..e6aae603 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/Command.java b/cloud-core/src/main/java/com/intellectualsites/commands/Command.java index 2e107615..490a1a53 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/Command.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/Command.java @@ -31,7 +31,11 @@ import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.*; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.function.Consumer; /** @@ -49,6 +53,15 @@ public class Command { @Nonnull private final String commandPermission; @Nonnull private final M commandMeta; + /** + * Construct a new command + * + * @param commandComponents Command components + * @param commandExecutionHandler Execution handler + * @param senderType Required sender type. May be {@code null} + * @param commandPermission Command permission + * @param commandMeta Command meta instance + */ public Command(@Nonnull final List> commandComponents, @Nonnull final CommandExecutionHandler commandExecutionHandler, @Nullable final Class senderType, @@ -78,6 +91,14 @@ public class Command { this.commandMeta = commandMeta; } + /** + * Construct a new command + * + * @param commandComponents Command components + * @param commandExecutionHandler Execution handler + * @param senderType Required sender type. May be {@code null} + * @param commandMeta Command meta instance + */ public Command(@Nonnull final List> commandComponents, @Nonnull final CommandExecutionHandler commandExecutionHandler, @Nullable final Class senderType, @@ -85,6 +106,14 @@ public class Command { this(commandComponents, commandExecutionHandler, senderType, "", commandMeta); } + /** + * Construct a new command + * + * @param commandComponents Command components + * @param commandExecutionHandler Execution handler + * @param commandPermission Command permission + * @param commandMeta Command meta instance + */ public Command(@Nonnull final List> commandComponents, @Nonnull final CommandExecutionHandler commandExecutionHandler, @Nonnull final String commandPermission, diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java b/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java index d18b8698..c9beab87 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java @@ -58,6 +58,12 @@ public abstract class CommandManager commandSyntaxFormatter = new StandardCommandSyntaxFormatter<>(); + /** + * Create a new command manager instance + * + * @param commandExecutionCoordinator Execution coordinator instance + * @param commandRegistrationHandler Command registration handler + */ public CommandManager( @Nonnull final Function, CommandExecutionCoordinator> commandExecutionCoordinator, @Nonnull final CommandRegistrationHandler commandRegistrationHandler) { diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java index 8936f0bc..8851547e 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java @@ -57,7 +57,7 @@ import java.util.stream.Collectors; * @param Command sender type * @param Command meta type */ -public class CommandTree { +public final class CommandTree { private final Object commandLock = new Object(); @@ -106,8 +106,8 @@ public class CommandTree { private Optional> parseCommand(@Nonnull final CommandContext commandContext, @Nonnull final Queue commandQueue, @Nonnull final Node> root) { - String permission; - if ((permission = this.isPermitted(commandContext.getCommandSender(), root)) != null) { + String permission = this.isPermitted(commandContext.getCommandSender(), root); + if (permission != null) { throw new NoPermissionException(permission, commandContext.getCommandSender(), this.getChain(root) .stream() .map(Node::getValue) @@ -179,7 +179,8 @@ public class CommandTree { if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticComponent)) { // The value has to be a variable final Node> child = children.get(0); - if ((permission = this.isPermitted(commandContext.getCommandSender(), child)) != null) { + permission = this.isPermitted(commandContext.getCommandSender(), child); + if (permission != null) { throw new NoPermissionException(permission, commandContext.getCommandSender(), this.getChain(child) .stream() .map(Node::getValue) @@ -220,7 +221,7 @@ public class CommandTree { /* Too many arguments. We have a unique path, so we can send the entire context */ throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter() .apply(Objects.requireNonNull(child.getValue() - .getOwningCommand()) + .getOwningCommand()) .getComponents()), commandContext.getCommandSender(), this.getChain(root) .stream() @@ -244,13 +245,20 @@ public class CommandTree { return null; } + /** + * Get suggestions from the input queue + * + * @param context Context instance + * @param commandQueue Input queue + * @return String suggestions. These should be filtered based on {@link String#startsWith(String)} + */ @Nonnull public List getSuggestions(@Nonnull final CommandContext context, @Nonnull final Queue commandQueue) { return getSuggestions(context, commandQueue, this.internalTree); } @Nonnull - public List getSuggestions(@Nonnull final CommandContext commandContext, + private List getSuggestions(@Nonnull final CommandContext commandContext, @Nonnull final Queue commandQueue, @Nonnull final Node> root) { @@ -281,7 +289,7 @@ public class CommandTree { commandContext.store(child.getValue().getName(), result.getParsedValue().get()); return this.getSuggestions(commandContext, commandQueue, child); } else if (result.getFailure().isPresent()) { - /* TODO: Return error */ + /* I need to return ze error */ return Collections.emptyList(); } } @@ -417,7 +425,7 @@ public class CommandTree { if (commandComponentNode.nodeMeta.containsKey("permission") && !commandComponentNode.nodeMeta.get("permission") .equalsIgnoreCase( node.nodeMeta - .get("permission"))) { + .get("permission"))) { commandComponentNode.nodeMeta.put("permission", ""); } else { commandComponentNode.nodeMeta.put("permission", node.nodeMeta.get("permission")); diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java index da2cfd13..3211cbf4 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java @@ -42,6 +42,9 @@ import java.util.regex.Pattern; @SuppressWarnings("unused") public class CommandComponent implements Comparable> { + /** + * Pattern for command component names + */ private static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z0-9]+"); /** @@ -69,6 +72,14 @@ public class CommandComponent implements Comparable< private Command owningCommand; + /** + * Construct a new command component + * + * @param required Whether or not the component is required + * @param name The component name + * @param parser The component parser + * @param defaultValue Default value used when no value is provided by the command sender + */ public CommandComponent(final boolean required, @Nonnull final String name, @Nonnull final ComponentParser parser, @Nonnull final String defaultValue) { this.required = required; @@ -80,6 +91,13 @@ public class CommandComponent implements Comparable< this.defaultValue = defaultValue; } + /** + * Construct a new command component + * + * @param required Whether or not the component is required + * @param name The component name + * @param parser The component parser + */ public CommandComponent(final boolean required, @Nonnull final String name, @Nonnull final ComponentParser parser) { this(required, name, parser, ""); @@ -95,7 +113,8 @@ public class CommandComponent implements Comparable< * @return Component builder */ @Nonnull - public static CommandComponent.Builder ofType(@Nonnull final Class clazz, @Nonnull final String name) { + public static CommandComponent.Builder ofType(@Nonnull final Class clazz, + @Nonnull final String name) { return new Builder<>(name); } @@ -131,7 +150,7 @@ public class CommandComponent implements Comparable< @Nonnull @Override - public String toString() { + public final String toString() { return String.format("CommandComponent{name=%s}", this.name); } @@ -158,7 +177,7 @@ public class CommandComponent implements Comparable< } @Override - public boolean equals(final Object o) { + public final boolean equals(final Object o) { if (this == o) { return true; } @@ -170,12 +189,12 @@ public class CommandComponent implements Comparable< } @Override - public int hashCode() { + public final int hashCode() { return Objects.hash(isRequired(), getName()); } @Override - public int compareTo(@Nonnull final CommandComponent o) { + public final int compareTo(@Nonnull final CommandComponent o) { if (this instanceof StaticComponent) { if (o instanceof StaticComponent) { return (this.getName().compareTo(o.getName())); @@ -196,7 +215,8 @@ public class CommandComponent implements Comparable< * * @return Default value */ - @Nonnull public String getDefaultValue() { + @Nonnull + public String getDefaultValue() { return this.defaultValue; } @@ -206,8 +226,8 @@ public class CommandComponent implements Comparable< * @return {@code true} if the component has a default value, {@code false} if not */ public boolean hasDefaultValue() { - return !this.isRequired() && - !this.getDefaultValue().isEmpty(); + return !this.isRequired() + && !this.getDefaultValue().isEmpty(); } @@ -219,10 +239,11 @@ public class CommandComponent implements Comparable< */ public static class Builder { - protected final String name; - protected boolean required = true; - protected ComponentParser parser = (c, i) -> ComponentParseResult.failure(new UnsupportedOperationException("No parser was specified")); - protected String defaultValue = ""; + private final String name; + private boolean required = true; + private ComponentParser parser = (c, i) -> ComponentParseResult.failure( + new UnsupportedOperationException("No parser was specified")); + private String defaultValue = ""; protected Builder(@Nonnull final String name) { this.name = name; @@ -297,6 +318,24 @@ public class CommandComponent implements Comparable< return new CommandComponent<>(this.required, this.name, this.parser, this.defaultValue); } + @Nonnull + protected final String getName() { + return this.name; + } + + protected final boolean isRequired() { + return this.required; + } + + @Nonnull + protected final ComponentParser getParser() { + return this.parser; + } + + @Nonnull + protected final String getDefaultValue() { + return this.defaultValue; + } } } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java index b7298b21..66128ef9 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java @@ -41,12 +41,9 @@ import java.util.List; */ public class StandardCommandSyntaxFormatter implements CommandSyntaxFormatter { - public StandardCommandSyntaxFormatter() { - } - @Nonnull @Override - public String apply(@Nonnull final List> commandComponents) { + public final String apply(@Nonnull final List> commandComponents) { final StringBuilder stringBuilder = new StringBuilder(); final Iterator> iterator = commandComponents.iterator(); while (iterator.hasNext()) { diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java index 25a8162e..8b582ea9 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java @@ -83,7 +83,8 @@ public final class StaticComponent extends CommandCompo private final Set acceptedStrings = new HashSet<>(); private StaticComponentParser(@Nonnull final String name, @Nonnull final String... aliases) { - this.acceptedStrings.add(this.name = name); + this.name = name; + this.acceptedStrings.add(this.name); this.acceptedStrings.addAll(Arrays.asList(aliases)); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/package-info.java new file mode 100644 index 00000000..d21395da --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Command components that are used to build command parsing chains + */ +package com.intellectualsites.commands.components; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java index 0b126d07..32d25fbe 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java @@ -79,6 +79,9 @@ public abstract class ComponentParseResult { private static final class ParseSuccess extends ComponentParseResult { + /** + * Parsed value + */ private final T value; private ParseSuccess(@Nonnull final T value) { @@ -102,6 +105,9 @@ public abstract class ComponentParseResult { private static final class ParseFailure extends ComponentParseResult { + /** + * Parse failure + */ private final Throwable failure; private ParseFailure(@Nonnull final Throwable failure) { diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/package-info.java new file mode 100644 index 00000000..ec7db600 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Parser classes used to parse {@link com.intellectualsites.commands.components.CommandComponent} + */ +package com.intellectualsites.commands.components.parser; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java index ca028433..148b87b7 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java @@ -34,33 +34,64 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public class ByteComponent extends CommandComponent { +public final class ByteComponent extends CommandComponent { private final byte min; private final byte max; - private ByteComponent(final boolean required, @Nonnull final String name, final byte min, final byte max, final String defaultValue) { + 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; } + /** + * Create a new builder + * + * @param name Name of the component + * @param Command sender type + * @return Created builder + */ @Nonnull public static Builder newBuilder(@Nonnull final String name) { return new Builder<>(name); } + /** + * Create a new required command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent required(@Nonnull final String name) { return ByteComponent.newBuilder(name).asRequired().build(); } + /** + * Create a new optional command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent optional(@Nonnull final String name) { return ByteComponent.newBuilder(name).asOptional().build(); } - @Nonnull public static CommandComponent optional(@Nonnull final String name, final byte defaultNum) { + /** + * Create a new required command component with a default value + * + * @param name Component name + * @param defaultNum Default num + * @param Command sender type + * @return Created component + */ + @Nonnull public static CommandComponent optional(@Nonnull final String name, + final byte defaultNum) { return ByteComponent.newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build(); } @@ -74,22 +105,39 @@ public class ByteComponent extends CommandComponent withMin(final byte min) { this.min = min; return this; } + /** + * Set a maximum value + * + * @param max Maximum value + * @return Builder instance + */ @Nonnull public Builder withMax(final byte max) { this.max = max; return this; } + /** + * Builder a new byte component + * + * @return Constructed component + */ @Nonnull @Override public ByteComponent build() { - return new ByteComponent<>(this.required, this.name, this.min, this.max, this.defaultValue); + return new ByteComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -119,7 +167,7 @@ public class ByteComponent extends CommandComponent extends CommandComponent extends CommandComponent extends CommandComponent { +public final class IntegerComponent 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, final String defaultValue) { + 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; } - @Nonnull public static Builder newBuilder(@Nonnull final String name) { + /** + * Create a new builder + * + * @param name Name of the component + * @param Command sender type + * @return Created builder + */ + @Nonnull + public static Builder newBuilder(@Nonnull final String name) { return new Builder<>(name); } - @Nonnull public static CommandComponent required(@Nonnull final String name) { + /** + * Create a new required command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ + @Nonnull + public static CommandComponent required(@Nonnull final String name) { return IntegerComponent.newBuilder(name).asRequired().build(); } - @Nonnull public static CommandComponent optional(@Nonnull final String name) { + /** + * Create a new optional command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ + @Nonnull + public static CommandComponent optional(@Nonnull final String name) { return IntegerComponent.newBuilder(name).asOptional().build(); } - @Nonnull public static CommandComponent optional(@Nonnull final String name, final int defaultNum) { + /** + * Create a new required command component with a default value + * + * @param name Component name + * @param defaultNum Default num + * @param Command sender type + * @return Created component + */ + @Nonnull + public static CommandComponent optional(@Nonnull final String name, + final int defaultNum) { return IntegerComponent.newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build(); } @@ -71,20 +109,39 @@ public class IntegerComponent extends CommandComponent< super(name); } - @Nonnull public Builder withMin(final int min) { + /** + * Set a minimum value + * + * @param min Minimum value + * @return Builder instance + */ + @Nonnull + public Builder withMin(final int min) { this.min = min; return this; } - @Nonnull public Builder withMax(final int max) { + /** + * Set a maximum value + * + * @param max Maximum value + * @return Builder instance + */ + @Nonnull + public Builder withMax(final int max) { this.max = max; return this; } + /** + * Builder a new integer component + * + * @return Constructed component + */ @Nonnull @Override public IntegerComponent build() { - return new IntegerComponent<>(this.required, this.name, this.min, this.max, this.defaultValue); + return new IntegerComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -114,7 +171,7 @@ public class IntegerComponent extends CommandComponent< private final int min; private final int max; - public IntegerParser(final int min, final int max) { + private IntegerParser(final int min, final int max) { this.min = min; this.max = max; } @@ -145,6 +202,13 @@ public class IntegerComponent extends CommandComponent< public static final class IntegerParseException extends NumberParseException { + /** + * Construct a new integer parse exception + * + * @param input String input + * @param min Minimum value + * @param max Maximum value + */ public IntegerParseException(@Nonnull final String input, final int min, final int max) { super(input, min, max); } @@ -160,6 +224,7 @@ public class IntegerComponent extends CommandComponent< } @Override + @Nonnull public String getNumberType() { return "integer"; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/package-info.java new file mode 100644 index 00000000..fa493350 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Standard command component types + */ +package com.intellectualsites.commands.components.standard; 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 index 46fa454e..bf83c3f2 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContextFactory.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/context/CommandContextFactory.java @@ -29,6 +29,8 @@ import javax.annotation.Nonnull; /** * Factory for {@link CommandContext} instances + * + * @param Command sender */ public interface CommandContextFactory { 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 index 67c5e0c8..047b6843 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/context/StandardCommandContextFactory.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/context/StandardCommandContextFactory.java @@ -29,6 +29,12 @@ import javax.annotation.Nonnull; public final class StandardCommandContextFactory implements CommandContextFactory { + /** + * Construct a new command context + * + * @param sender Command sender + * @return Created context + */ @Nonnull @Override public CommandContext create(@Nonnull final C sender) { diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/context/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/context/package-info.java new file mode 100644 index 00000000..971b0e96 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/context/package-info.java @@ -0,0 +1,29 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Command context stores values for a {@link com.intellectualsites.commands.sender.CommandSender} + * before and during command execution and parsing + */ +package com.intellectualsites.commands.context; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java index 13fff685..418f8436 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java @@ -33,11 +33,25 @@ public class ComponentParseException extends CommandParseException { private final Throwable cause; - public ComponentParseException(@Nonnull final Throwable throwable, @Nonnull final CommandSender commandSender, @Nonnull final List> currentChain) { + /** + * Create a new command parse exception + * + * @param throwable Exception that caused the parsing error + * @param commandSender Command sender + * @param currentChain Chain leading up to the exception + */ + public ComponentParseException(@Nonnull final Throwable throwable, + @Nonnull final CommandSender commandSender, + @Nonnull final List> currentChain) { super(commandSender, currentChain); this.cause = throwable; } + /** + * Get the cause of the exception + * + * @return Cause + */ @Nonnull public Throwable getCause() { return this.cause; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java index 6ec5cc86..653bb988 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java @@ -37,6 +37,13 @@ public class InvalidSyntaxException extends CommandParseException { private final String correctSyntax; + /** + * Create a new invalid syntax exception instance + * + * @param correctSyntax Expected syntax + * @param commandSender Sender that sent the command + * @param currentChain Chain leading up to issue + */ public InvalidSyntaxException(@Nonnull final String correctSyntax, @Nonnull final CommandSender commandSender, @Nonnull final List> currentChain) { @@ -54,8 +61,9 @@ public class InvalidSyntaxException extends CommandParseException { return this.correctSyntax; } + @Override - public String getMessage() { + public final String getMessage() { return String.format("Invalid command syntax. Correct syntax is: %s", this.correctSyntax); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java index d253ba9e..e72cb5f5 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java @@ -36,6 +36,11 @@ public final class NoCommandInLeafException extends IllegalStateException { private final CommandComponent commandComponent; + /** + * Create a new no command in leaf exception instance + * + * @param commandComponent Command component that caused the exception + */ public NoCommandInLeafException(@Nonnull final CommandComponent commandComponent) { super(String.format("Leaf node '%s' does not have associated owning command", commandComponent.getName())); this.commandComponent = commandComponent; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java index 5b258a3a..7d441f4b 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java @@ -38,6 +38,13 @@ public class NoPermissionException extends CommandParseException { private final String missingPermission; + /** + * Construct a new no permission exception + * + * @param missingPermission Missing permission node + * @param commandSender Command sender + * @param currentChain Chain leading up to the exception + */ public NoPermissionException(@Nonnull final String missingPermission, @Nonnull final CommandSender commandSender, @Nonnull final List> currentChain) { @@ -46,10 +53,15 @@ public class NoPermissionException extends CommandParseException { } @Override - public String getMessage() { + public final String getMessage() { return String.format("Missing permission '%s'", this.missingPermission); } + /** + * Get the missing permission node + * + * @return Get the missing permission node + */ @Nonnull public String getMissingPermission() { return this.missingPermission; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/package-info.java new file mode 100644 index 00000000..a8b9f280 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * cloud related exceptions + */ +package com.intellectualsites.commands.exceptions; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java index 275c7009..795be07c 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/NumberParseException.java @@ -31,6 +31,13 @@ public abstract class NumberParseException extends IllegalArgumentException { private final Number min; private final Number max; + /** + * Construct a new number parse exception + * + * @param input Input + * @param min Maximum value + * @param max Minimum value + */ public NumberParseException(@Nonnull final String input, final int min, final int max) { this.input = input; this.min = min; @@ -38,9 +45,10 @@ public abstract class NumberParseException extends IllegalArgumentException { } @Override - public String getMessage() { + public final String getMessage() { if (this.hasMin() && this.hasMax()) { - return "'" + this.input + "' is not a valid " + this.getNumberType() + " in the range [" + this.min + ", " + this.max + "]"; + return "'" + this.input + "' is not a valid " + this.getNumberType() + " in the range [" + + this.min + ", " + this.max + "]"; } else if (this.hasMin()) { return "'" + this.input + "' is not a valid " + this.getNumberType() + " above " + this.min; } else if (this.hasMax()) { @@ -50,10 +58,26 @@ public abstract class NumberParseException extends IllegalArgumentException { } } + /** + * Get the number type + * + * @return Number type + */ + @Nonnull public abstract String getNumberType(); + /** + * If the parser had a maximum value + * + * @return {@code true} if there was a maximum value, else {@code false} + */ public abstract boolean hasMax(); + /** + * If the parser had a minimum value + * + * @return {@code true} if there was a minimum value, else {@code false} + */ public abstract boolean hasMin(); /** @@ -61,7 +85,8 @@ public abstract class NumberParseException extends IllegalArgumentException { * * @return Input */ - @Nonnull public String getInput() { + @Nonnull + public String getInput() { return this.input; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/package-info.java new file mode 100644 index 00000000..4a434678 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/parsing/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Parsing related exceptions + */ +package com.intellectualsites.commands.exceptions.parsing; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java b/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java index 400fca9b..6f76cb9c 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionCoordinator.java @@ -23,9 +23,9 @@ // package com.intellectualsites.commands.execution; -import com.intellectualsites.commands.meta.CommandMeta; import com.intellectualsites.commands.CommandTree; import com.intellectualsites.commands.context.CommandContext; +import com.intellectualsites.commands.meta.CommandMeta; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -62,12 +62,20 @@ public abstract class CommandExecutionCoordinator Command meta type * @return New coordinator instance */ - public static Function, CommandExecutionCoordinator> simpleCoordinator() { + public static Function, + CommandExecutionCoordinator> simpleCoordinator() { return SimpleCoordinator::new; } - public abstract CompletableFuture coordinateExecution(@Nonnull final CommandContext commandContext, - @Nonnull final Queue input); + /** + * Coordinate the execution of a command and return the result + * + * @param commandContext Command context + * @param input Command input + * @return Future that completes with the result + */ + public abstract CompletableFuture coordinateExecution(@Nonnull CommandContext commandContext, + @Nonnull Queue input); /** * Get the command tree @@ -86,15 +94,16 @@ public abstract class CommandExecutionCoordinator Command sender type * @param Command meta type */ - public static final class SimpleCoordinator extends CommandExecutionCoordinator { + public static final class SimpleCoordinator extends + CommandExecutionCoordinator { private SimpleCoordinator(@Nonnull final CommandTree commandTree) { super(commandTree); } @Override - public CompletableFuture coordinateExecution(@Nonnull CommandContext commandContext, - @Nonnull Queue input) { + public CompletableFuture coordinateExecution(@Nonnull final CommandContext commandContext, + @Nonnull final Queue input) { final CompletableFuture completableFuture = new CompletableFuture<>(); try { this.getCommandTree().parse(commandContext, input).ifPresent( diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java b/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java index 7c4dee6c..c3a38572 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/execution/CommandExecutionHandler.java @@ -42,7 +42,7 @@ public interface CommandExecutionHandler { * * @param commandContext Command context */ - void execute(@Nonnull final CommandContext commandContext); + void execute(@Nonnull CommandContext commandContext); /** diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/execution/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/execution/package-info.java new file mode 100644 index 00000000..7e8e2be6 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/execution/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Classes related to command execution and execution coordination + */ +package com.intellectualsites.commands.execution; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java b/cloud-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java index 9775f755..ce755568 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/internal/CommandRegistrationHandler.java @@ -45,8 +45,14 @@ public interface CommandRegistrationHandler { * @return {@code true} if the command was registered successfully, * else {@code false} */ - boolean registerCommand(@Nonnull final Command command); + boolean registerCommand(@Nonnull Command command); + /** + * Create a new {@link CommandRegistrationHandler} that does nothing + * + * @param Command meta type + * @return Constructed registration + */ static CommandRegistrationHandler nullCommandRegistrationHandler() { return new NullCommandRegistrationHandler<>(); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/internal/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/internal/package-info.java new file mode 100644 index 00000000..b158dd39 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/internal/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Classes that should be used internally in command managers + */ +package com.intellectualsites.commands.internal; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/meta/CommandMeta.java b/cloud-core/src/main/java/com/intellectualsites/commands/meta/CommandMeta.java index 72452ed3..a732ba57 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/meta/CommandMeta.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/meta/CommandMeta.java @@ -33,9 +33,20 @@ import javax.annotation.Nonnull; */ public class CommandMeta { + /** + * Create a new simple command meta builder + * + * @return Builder instance + */ @Nonnull public static SimpleCommandMeta.Builder simple() { return SimpleCommandMeta.builder(); } + @Nonnull + @Override + public final String toString() { + return ""; + } + } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/meta/SimpleCommandMeta.java b/cloud-core/src/main/java/com/intellectualsites/commands/meta/SimpleCommandMeta.java index 888fbad0..6367d2d9 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/meta/SimpleCommandMeta.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/meta/SimpleCommandMeta.java @@ -95,7 +95,7 @@ public class SimpleCommandMeta extends CommandMeta { } @Override - public boolean equals(final Object o) { + public final boolean equals(final Object o) { if (this == o) { return true; } @@ -107,7 +107,7 @@ public class SimpleCommandMeta extends CommandMeta { } @Override - public int hashCode() { + public final int hashCode() { return Objects.hashCode(metaMap); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/meta/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/meta/package-info.java new file mode 100644 index 00000000..64b5b8ce --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/meta/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Command meta are classes associated with commands that store arbitrary data + */ +package com.intellectualsites.commands.meta; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/package-info.java new file mode 100644 index 00000000..b3f44e0e --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/package-info.java @@ -0,0 +1,29 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * cloud API main package + * @see com.intellectualsites.commands.CommandManager Command manager class + */ +package com.intellectualsites.commands; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/sender/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/sender/package-info.java new file mode 100644 index 00000000..752d5a8b --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/sender/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * Command sender related classes + */ +package com.intellectualsites.commands.sender; diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java index 847e3b05..c0be1957 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java @@ -40,6 +40,7 @@ import java.util.Optional; class CommandTreeTest { + private static final int EXPECTED_INPUT_NUMBER = 15; private static CommandManager commandManager; @BeforeAll @@ -51,26 +52,38 @@ class CommandTreeTest { .withComponent(StaticComponent.required("two")).withPermission("no").build()) .registerCommand(commandManager.commandBuilder("test", SimpleCommandMeta.empty()) .withComponent(StaticComponent.required("opt")) - .withComponent(IntegerComponent.optional("num", 15)).build()); + .withComponent(IntegerComponent + .optional("num", EXPECTED_INPUT_NUMBER)) + .build()); } @Test void parse() { - final Optional> command = commandManager.getCommandTree().parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>( - Arrays.asList("test", "one"))); + final Optional> command = commandManager.getCommandTree() + .parse(new CommandContext<>( + new TestCommandSender()), + new LinkedList<>( + Arrays.asList("test", + "one"))); 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"))) + 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"))) + commandManager.getCommandTree() + .parse(new CommandContext<>(new TestCommandSender()), new LinkedList<>(Arrays.asList("test", "opt", "12"))) .ifPresent(c -> c.getCommandExecutionHandler().execute(new CommandContext<>(new TestCommandSender()))); } @Test void getSuggestions() { - Assertions.assertFalse(commandManager.getCommandTree().getSuggestions(new CommandContext<>(new TestCommandSender()), new LinkedList<>( - Collections.singletonList("test"))).isEmpty()); + Assertions.assertFalse( + commandManager.getCommandTree().getSuggestions(new CommandContext<>(new TestCommandSender()), new LinkedList<>( + Collections.singletonList("test"))).isEmpty()); } } diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java b/cloud-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java index c312550a..907a2111 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/TestCommandManager.java @@ -38,7 +38,7 @@ public class TestCommandManager extends CommandManager implements Completer { + /** + * Construct a new JLine command manager + * + * @param executionCoordinatorFunction Function producing a new coordinator + */ public JLineCommandManager(@Nonnull final Function, CommandExecutionCoordinator> executionCoordinatorFunction) { super(executionCoordinatorFunction, CommandRegistrationHandler.nullCommandRegistrationHandler()); } - public static void main(String[] args) throws Exception { - // TODO: REMOVE THIS!!!! + /** + * Main method + * + * @param args Arguments + * @throws Exception Any and all exceptions + */ + public static void main(final String[] args) throws Exception { final JLineCommandManager jLineCommandManager = new JLineCommandManager(CommandExecutionCoordinator.simpleCoordinator()); final Terminal terminal = TerminalBuilder.builder().build(); LineReader lineReader = LineReaderBuilder.builder() @@ -74,7 +84,8 @@ public class JLineCommandManager extends CommandManager builder.asRequired() .withParser(((commandContext, inputQueue) -> { - final StringBuilder stringBuilder = new StringBuilder(); + final StringBuilder stringBuilder = + new StringBuilder(); while (!inputQueue.isEmpty()) { stringBuilder.append(inputQueue.remove()); if (!inputQueue.isEmpty()) { @@ -86,16 +97,16 @@ public class JLineCommandManager extends CommandManager commandContext.get("string") .ifPresent( - System.out::println)) + System.out::println)) .build()) .registerCommand(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty()) - .withComponent(StaticComponent.required("one")) - .withHandler(commandContext -> System.out.println("Test (1)")) - .build()) + .withComponent(StaticComponent.required("one")) + .withHandler(commandContext -> System.out.println("Test (1)")) + .build()) .registerCommand(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty()) - .withComponent(StaticComponent.required("two")) - .withHandler(commandContext -> System.out.println("Test (2)")) - .build()); + .withComponent(StaticComponent.required("two")) + .withHandler(commandContext -> System.out.println("Test (2)")) + .build()); System.out.println("Ready..."); while (!shouldStop[0]) { final String line = lineReader.readLine(); @@ -127,7 +138,7 @@ public class JLineCommandManager extends CommandManager list) { final String line = parsedLine.line(); @@ -140,7 +151,7 @@ public class JLineCommandManager extends CommandManager, - CommandExecutionCoordinator> commandExecutionCoordinator) + CommandExecutionCoordinator> commandExecutionCoordinator) throws Exception { super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler()); ((BukkitPluginRegistrationHandler) this.getCommandRegistrationHandler()).initialize(this); @@ -63,6 +63,11 @@ public class BukkitCommandManager extends CommandManager bukkitCommands = (Map) knownCommands.get( - commandMap); + final Map bukkitCommands = + (Map) knownCommands.get(commandMap); this.bukkitCommands = bukkitCommands; this.bukkitCommandManager = bukkitCommandManager; } diff --git a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/package-info.java b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/package-info.java new file mode 100644 index 00000000..ca5dc2b1 --- /dev/null +++ b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/package-info.java @@ -0,0 +1,28 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// 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. +// + +/** + * cloud implementation for Bukkit 1.8-1.16 + */ +package com.intellectualsites.commands; diff --git a/pom.xml b/pom.xml index eb4397a9..e6c0d314 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,21 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.1 + + checkstyle.xml + + + + + check + + + + org.apache.maven.plugins maven-compiler-plugin