diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc168e57..8fa39a2e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added ExampleVelocityPlugin
- Added CloudInjectionModule to cloud-velocity
- Added PlayerArgument to cloud-velocity
+ - Added TextColorArgument to minecraft-extras
## [1.0.2] - 2020-10-18
diff --git a/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/ColorArgument.java b/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/TextColorArgument.java
similarity index 83%
rename from cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/ColorArgument.java
rename to cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/TextColorArgument.java
index 4b6fa3d7..dd3d0aa0 100644
--- a/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/ColorArgument.java
+++ b/cloud-minecraft/cloud-minecraft-extras/src/main/java/cloud/commandframework/minecraft/extras/TextColorArgument.java
@@ -29,6 +29,7 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.captions.CaptionVariable;
import cloud.commandframework.captions.StandardCaptionKeys;
import cloud.commandframework.context.CommandContext;
+import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import cloud.commandframework.exceptions.parsing.ParserException;
import cloud.commandframework.types.tuples.Pair;
import io.leangen.geantyref.TypeToken;
@@ -44,11 +45,13 @@ import java.util.Queue;
import java.util.regex.Pattern;
/**
- * Parser for color codes
+ * Parser for color codes.
+ *
+ * Accepts {@link NamedTextColor NamedTextColors}, Legacy Minecraft {@literal &} color codes, Hex Codes (#RRGGBB)
*
* @param Command sender type
*/
-public final class ColorArgument extends CommandArgument {
+public final class TextColorArgument extends CommandArgument {
private static final Pattern LEGACY_PREDICATE = Pattern.compile(
"&[0-9a-fA-F]"
@@ -77,7 +80,7 @@ public final class ColorArgument extends CommandArgument {
Pair.of('f', NamedTextColor.WHITE)
);
- private ColorArgument(
+ private TextColorArgument(
final boolean required,
final @NonNull String name,
final @NonNull String defaultValue
@@ -85,7 +88,7 @@ public final class ColorArgument extends CommandArgument {
super(
required,
name,
- new ColorArgumentParser<>(),
+ new TextColorParser<>(),
defaultValue,
TypeToken.get(TextColor.class),
null,
@@ -94,14 +97,14 @@ public final class ColorArgument extends CommandArgument {
}
/**
- * Create a new required colour argument
+ * Create a new required TextColor argument
*
* @param name Argument name
* @param Command sender type
* @return Created argument
*/
- public static @NonNull ColorArgument of(final @NonNull String name) {
- return new ColorArgument<>(
+ public static @NonNull TextColorArgument of(final @NonNull String name) {
+ return new TextColorArgument<>(
true,
name,
""
@@ -109,14 +112,14 @@ public final class ColorArgument extends CommandArgument {
}
/**
- * Create a new optional colour argument
+ * Create a new optional TextColor argument
*
* @param name Argument name
* @param Command sender type
* @return Created argument
*/
- public static @NonNull ColorArgument optional(final @NonNull String name) {
- return new ColorArgument<>(
+ public static @NonNull TextColorArgument optional(final @NonNull String name) {
+ return new TextColorArgument<>(
false,
name,
""
@@ -124,18 +127,18 @@ public final class ColorArgument extends CommandArgument {
}
/**
- * Create a new optional colour argument
+ * Create a new optional TextColor argument
*
* @param name Argument name
* @param defaultValue Default value
* @param Command sender type
* @return Created argument
*/
- public static @NonNull ColorArgument optionalWithDefault(
+ public static @NonNull TextColorArgument optionalWithDefault(
final @NonNull String name,
final @NonNull String defaultValue
) {
- return new ColorArgument<>(
+ return new TextColorArgument<>(
false,
name,
defaultValue
@@ -143,7 +146,7 @@ public final class ColorArgument extends CommandArgument {
}
- public static final class ColorArgumentParser implements ArgumentParser {
+ public static final class TextColorParser implements ArgumentParser {
@Override
public @NonNull ArgumentParseResult<@NonNull TextColor> parse(
@@ -152,9 +155,10 @@ public final class ColorArgument extends CommandArgument {
) {
final String input = inputQueue.peek();
if (input == null) {
- throw new NullPointerException(
- "No input was supplied"
- );
+ return ArgumentParseResult.failure(new NoInputProvidedException(
+ TextColorParser.class,
+ commandContext
+ ));
}
if (LEGACY_PREDICATE.matcher(input).matches()) {
final char code = input.substring(1).toLowerCase().charAt(0);
@@ -181,7 +185,7 @@ public final class ColorArgument extends CommandArgument {
);
}
return ArgumentParseResult.failure(
- new ColorArgumentParseException(
+ new TextColorParseException(
commandContext,
input
)
@@ -211,14 +215,14 @@ public final class ColorArgument extends CommandArgument {
}
- private static final class ColorArgumentParseException extends ParserException {
+ private static final class TextColorParseException extends ParserException {
- private ColorArgumentParseException(
+ private TextColorParseException(
final @NonNull CommandContext> commandContext,
final @NonNull String input
) {
super(
- ColorArgumentParser.class,
+ TextColorParser.class,
commandContext,
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_COLOR,
CaptionVariable.of("input", input)
diff --git a/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java b/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java
index e637d095..960172ba 100644
--- a/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java
+++ b/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/ExamplePlugin.java
@@ -57,7 +57,7 @@ import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.extra.confirmation.CommandConfirmationManager;
import cloud.commandframework.meta.CommandMeta;
-import cloud.commandframework.minecraft.extras.ColorArgument;
+import cloud.commandframework.minecraft.extras.TextColorArgument;
import cloud.commandframework.paper.PaperCommandManager;
import cloud.commandframework.types.tuples.Triplet;
import io.leangen.geantyref.TypeToken;
@@ -319,23 +319,23 @@ public final class ExamplePlugin extends JavaPlugin {
.meta("description", "Sets the color scheme for '/example help'")
.literal("helpcolors")
.argument(
- ColorArgument.of("primary"),
+ TextColorArgument.of("primary"),
Description.of("The primary color for the color scheme")
)
.argument(
- ColorArgument.of("highlight"),
+ TextColorArgument.of("highlight"),
Description.of("The primary color used to highlight commands and queries")
)
.argument(
- ColorArgument.of("alternate_highlight"),
+ TextColorArgument.of("alternate_highlight"),
Description.of("The secondary color used to highlight commands and queries")
)
.argument(
- ColorArgument.of("text"),
+ TextColorArgument.of("text"),
Description.of("The color used for description text")
)
.argument(
- ColorArgument.of("accent"),
+ TextColorArgument.of("accent"),
Description.of("The color used for accents and symbols")
)
.handler(c -> minecraftHelp.setHelpColors(MinecraftHelp.HelpColors.of(