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