From 9bb3a3e65fadda03667d9b366fb0fcbbd95704f9 Mon Sep 17 00:00:00 2001 From: JOO200 Date: Sun, 20 Feb 2022 12:01:48 +0100 Subject: [PATCH 1/2] minimessage-text: added new tag for linebreaks (
and ) --- .../minimessage/tag/standard/NewlineTag.java | 49 +++++++++++++++++++ .../tag/standard/StandardTags.java | 16 +++++- .../minimessage/MiniMessageParserTest.java | 14 ++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java new file mode 100644 index 000000000..66fe75316 --- /dev/null +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java @@ -0,0 +1,49 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2022 KyoriPowered + * + * 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 net.kyori.adventure.text.minimessage.tag.standard; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.Context; +import net.kyori.adventure.text.minimessage.ParsingException; +import net.kyori.adventure.text.minimessage.tag.Tag; +import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue; +import org.jetbrains.annotations.ApiStatus; + +/** + * Newline tag. + * + * @since 4.10.0 + */ +@ApiStatus.Internal +public final class NewlineTag { + public static final String NEWLINE_2 = "newline"; + public static final String NEWLINE = "br"; + + private NewlineTag() { + } + + static Tag create(final ArgumentQueue args, final Context ctx) throws ParsingException { + return Tag.inserting(Component.newline()); + } +} diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java index 5758e805d..2fbdb2485 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java @@ -64,6 +64,7 @@ private StandardTags() { private static final TagResolver GRADIENT = TagResolver.resolver(GradientTag.GRADIENT, GradientTag::create); private static final TagResolver RAINBOW = TagResolver.resolver(RainbowTag.RAINBOW, RainbowTag::create); private static final TagResolver RESET = TagResolver.resolver(RESET_TAG, ParserDirective.RESET); + private static final TagResolver NEW_LINE = TagResolver.resolver(names(NewlineTag.NEWLINE, NewlineTag.NEWLINE_2), NewlineTag::create); private static final TagResolver ALL = TagResolver.builder() .resolvers( HOVER_EVENT, @@ -76,7 +77,8 @@ private StandardTags() { DECORATION, GRADIENT, RAINBOW, - RESET + RESET, + NEW_LINE ) .build(); @@ -196,6 +198,18 @@ public static TagResolver reset() { return RESET; } + /** + * Get a resolver for the {@value NewlineTag#NEWLINE} tag. + * + *

This tag also responds to {@value NewlineTag#NEWLINE_2}.

+ * + * @return a resolver for the {@value NewlineTag#NEWLINE} tag. + * @since 4.10.0 + */ + public static TagResolver newline() { + return NEW_LINE; + } + /** * Get a resolver that handles all default standard tags. * diff --git a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java index 500ebc023..89761d709 100644 --- a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java +++ b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java @@ -1711,4 +1711,18 @@ void testTreeOutput() { assertEquals(expected, tree.toString()); } + + @Test + void testNewLine() { + final String input = "Line
break!"; + final Component expected = Component.text().color(RED) + .append( + text("Line"), + Component.newline(), + text("break!", color(GRAY)) + ) + .build(); + + this.assertParsedEquals(expected, input); + } } From f60aa0d56447424645f3cf739184905ce34498e2 Mon Sep 17 00:00:00 2001 From: JOO200 Date: Mon, 21 Feb 2022 23:35:13 +0100 Subject: [PATCH 2/2] minimessage-text: set
to an alias of --- .../adventure/text/minimessage/tag/standard/NewlineTag.java | 4 ++-- .../text/minimessage/tag/standard/StandardTags.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java index 66fe75316..3f3bb202c 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/NewlineTag.java @@ -37,8 +37,8 @@ */ @ApiStatus.Internal public final class NewlineTag { - public static final String NEWLINE_2 = "newline"; - public static final String NEWLINE = "br"; + public static final String NEWLINE_2 = "br"; + public static final String NEWLINE = "newline"; private NewlineTag() { } diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java index 2fbdb2485..31509dee3 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/tag/standard/StandardTags.java @@ -64,7 +64,7 @@ private StandardTags() { private static final TagResolver GRADIENT = TagResolver.resolver(GradientTag.GRADIENT, GradientTag::create); private static final TagResolver RAINBOW = TagResolver.resolver(RainbowTag.RAINBOW, RainbowTag::create); private static final TagResolver RESET = TagResolver.resolver(RESET_TAG, ParserDirective.RESET); - private static final TagResolver NEW_LINE = TagResolver.resolver(names(NewlineTag.NEWLINE, NewlineTag.NEWLINE_2), NewlineTag::create); + private static final TagResolver NEWLINE = TagResolver.resolver(names(NewlineTag.NEWLINE, NewlineTag.NEWLINE_2), NewlineTag::create); private static final TagResolver ALL = TagResolver.builder() .resolvers( HOVER_EVENT, @@ -78,7 +78,7 @@ private StandardTags() { GRADIENT, RAINBOW, RESET, - NEW_LINE + NEWLINE ) .build(); @@ -207,7 +207,7 @@ public static TagResolver reset() { * @since 4.10.0 */ public static TagResolver newline() { - return NEW_LINE; + return NEWLINE; } /**