diff --git a/src/main/java/net/earthcomputer/clientcommands/command/NoteCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/NoteCommand.java index e1647553..0db7c09d 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/NoteCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/NoteCommand.java @@ -5,15 +5,15 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.network.chat.MutableComponent; -import static net.earthcomputer.clientcommands.command.arguments.FormattedComponentArgument.*; +import static net.earthcomputer.clientcommands.command.arguments.ExtendedMarkdownArgument.*; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; public class NoteCommand { public static void register(CommandDispatcher dispatcher) { dispatcher.register(literal("cnote") - .then(argument("message", formattedComponent()) - .executes(ctx -> note(ctx.getSource(), getFormattedComponent(ctx, "message"))))); + .then(argument("message", extendedMarkdown()) + .executes(ctx -> note(ctx.getSource(), getExtendedMarkdown(ctx, "message"))))); } private static int note(FabricClientCommandSource source, MutableComponent message) { diff --git a/src/main/java/net/earthcomputer/clientcommands/command/arguments/FormattedComponentArgument.java b/src/main/java/net/earthcomputer/clientcommands/command/arguments/ExtendedMarkdownArgument.java similarity index 94% rename from src/main/java/net/earthcomputer/clientcommands/command/arguments/FormattedComponentArgument.java rename to src/main/java/net/earthcomputer/clientcommands/command/arguments/ExtendedMarkdownArgument.java index 54881002..1a50acd2 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/arguments/FormattedComponentArgument.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/arguments/ExtendedMarkdownArgument.java @@ -35,21 +35,21 @@ import java.util.function.Consumer; import java.util.function.Function; -public class FormattedComponentArgument implements ArgumentType { +public class ExtendedMarkdownArgument implements ArgumentType { private static final Collection EXAMPLES = Arrays.asList("Earth", "bold{xpple}", "red{hello blue{world}!}", "*italic*"); - private static final SimpleCommandExceptionType TOO_DEEPLY_NESTED = new SimpleCommandExceptionType(Component.translatable("commands.client.componentTooDeeplyNested")); - private static final DynamicCommandExceptionType INVALID_CLICK_ACTION = new DynamicCommandExceptionType(action -> Component.translatable("commands.client.invalidClickAction", action)); - private static final DynamicCommandExceptionType INVALID_HOVER_ACTION = new DynamicCommandExceptionType(action -> Component.translatable("commands.client.invalidHoverAction", action)); - private static final DynamicCommandExceptionType INVALID_HOVER_EVENT = new DynamicCommandExceptionType(event -> Component.translatable("commands.client.invalidHoverEvent", event)); + private static final SimpleCommandExceptionType TOO_DEEPLY_NESTED_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.client.componentTooDeeplyNested")); + private static final DynamicCommandExceptionType INVALID_CLICK_ACTION_EXCEPTION = new DynamicCommandExceptionType(action -> Component.translatable("commands.client.invalidClickAction", action)); + private static final DynamicCommandExceptionType INVALID_HOVER_ACTION_EXCEPTION = new DynamicCommandExceptionType(action -> Component.translatable("commands.client.invalidHoverAction", action)); + private static final DynamicCommandExceptionType INVALID_HOVER_EVENT_EXCEPTION = new DynamicCommandExceptionType(event -> Component.translatable("commands.client.invalidHoverEvent", event)); - private FormattedComponentArgument() { + private ExtendedMarkdownArgument() { } - public static FormattedComponentArgument formattedComponent() { - return new FormattedComponentArgument(); + public static ExtendedMarkdownArgument extendedMarkdown() { + return new ExtendedMarkdownArgument(); } - public static MutableComponent getFormattedComponent(CommandContext context, String arg) { + public static MutableComponent getExtendedMarkdown(CommandContext context, String arg) { return context.getArgument(arg, MutableComponent.class); } @@ -98,7 +98,7 @@ public MutableComponent parse() throws CommandSyntaxException { private MutableComponent parse(int end, int depth) throws CommandSyntaxException { if (depth > MAX_NESTING) { - throw TOO_DEEPLY_NESTED.createWithContext(reader); + throw TOO_DEEPLY_NESTED_EXCEPTION.createWithContext(reader); } StringBuilder plainText = new StringBuilder(); @@ -269,7 +269,8 @@ private MutableComponent parse(int end, int depth) throws CommandSyntaxException components.add(Component.literal(plainText.toString())); plainText.setLength(0); } - components.add(linkComponent.withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, linkHref)) + components.add(linkComponent.withStyle(style -> style + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, linkHref)) .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(linkHref))) .withColor(ChatFormatting.BLUE) .withUnderlined(true))); @@ -432,7 +433,7 @@ interface StylerFunc { private static ClickEvent parseClickEvent(String name, String value) throws CommandSyntaxException { ClickEvent.Action action = CLICK_EVENT_ACTION_BY_NAME.apply(name); if (action == null) { - throw INVALID_CLICK_ACTION.create(name); + throw INVALID_CLICK_ACTION_EXCEPTION.create(name); } return new ClickEvent(action, value); } @@ -440,11 +441,11 @@ private static ClickEvent parseClickEvent(String name, String value) throws Comm private static HoverEvent parseHoverEvent(String name, String value) throws CommandSyntaxException { HoverEvent.Action action = HoverEvent.Action.UNSAFE_CODEC.parse(JsonOps.INSTANCE, new JsonPrimitive(name)).result().orElse(null); if (action == null) { - throw INVALID_HOVER_ACTION.create(name); + throw INVALID_HOVER_ACTION_EXCEPTION.create(name); } JsonElement component = ComponentSerialization.CODEC.encodeStart(JsonOps.INSTANCE, Component.nullToEmpty(value)).getOrThrow(); - HoverEvent.TypedHoverEvent eventData = action.legacyCodec.codec().parse(JsonOps.INSTANCE, component).getOrThrow(error -> INVALID_HOVER_EVENT.create(value)); + HoverEvent.TypedHoverEvent eventData = action.legacyCodec.codec().parse(JsonOps.INSTANCE, component).getOrThrow(error -> INVALID_HOVER_EVENT_EXCEPTION.create(value)); return new HoverEvent(eventData); }