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..3f3bb202c --- /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 = "br"; + public static final String NEWLINE = "newline"; + + 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..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,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 NEWLINE = 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, + NEWLINE ) .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 NEWLINE; + } + /** * 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); + } }