From b5b6d40103bc5ac82ae0bd1398a7f1e2adca4acc Mon Sep 17 00:00:00 2001 From: Daedalus <16168171+RedDaedalus@users.noreply.github.com> Date: Sun, 13 Aug 2023 14:11:00 -0600 Subject: [PATCH 1/2] feature: Add a new standard join configuration for spaces --- .../kyori/adventure/text/JoinConfiguration.java | 13 +++++++++++++ .../adventure/text/JoinConfigurationImpl.java | 1 + .../java/net/kyori/adventure/text/JoinTest.java | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java b/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java index 19ee8b175..67db711b0 100644 --- a/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java +++ b/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java @@ -118,6 +118,19 @@ public interface JoinConfiguration extends BuildableA purely text based example of this syntax, without introducing the concepts of components, would join the two strings 'hello' and 'there' together, + * creating the following output: 'hello there'.

+ * + * @return the join configuration + * @since 4.14.0 + */ + static @NotNull JoinConfiguration spaces() { + return JoinConfigurationImpl.STANDARD_SPACES; + } + /** * Provides a join configuration with no prefix or suffix that simply joins the components together using a single comma, matching a CSV like layout. * diff --git a/api/src/main/java/net/kyori/adventure/text/JoinConfigurationImpl.java b/api/src/main/java/net/kyori/adventure/text/JoinConfigurationImpl.java index 135392c17..621a0ccfb 100644 --- a/api/src/main/java/net/kyori/adventure/text/JoinConfigurationImpl.java +++ b/api/src/main/java/net/kyori/adventure/text/JoinConfigurationImpl.java @@ -41,6 +41,7 @@ final class JoinConfigurationImpl implements JoinConfiguration { static final JoinConfigurationImpl NULL = new JoinConfigurationImpl(); static final JoinConfiguration STANDARD_NEW_LINES = JoinConfiguration.separator(Component.newline()); + static final JoinConfiguration STANDARD_SPACES = JoinConfiguration.separator(Component.space()); static final JoinConfiguration STANDARD_COMMA_SEPARATED = JoinConfiguration.separator(Component.text(",")); static final JoinConfiguration STANDARD_COMMA_SPACE_SEPARATED = JoinConfiguration.separator(Component.text(", ")); static final JoinConfiguration STANDARD_ARRAY_LIKE = JoinConfiguration.builder() diff --git a/api/src/test/java/net/kyori/adventure/text/JoinTest.java b/api/src/test/java/net/kyori/adventure/text/JoinTest.java index 6f11ca243..2a74f2110 100644 --- a/api/src/test/java/net/kyori/adventure/text/JoinTest.java +++ b/api/src/test/java/net/kyori/adventure/text/JoinTest.java @@ -276,6 +276,21 @@ final void testStandardJoinConfigurationsNewLines() { ); } + @Test + final void testStandardJoinConfigurationsSpaces() { + final Component result = Component.join(JoinConfiguration.spaces(), Component.text("line 1"), Component.text("line 2"), Component.text("line 3")); + assertEquals( + Component.text() + .append(Component.text("line 1")) + .append(Component.space()) + .append(Component.text("line 2")) + .append(Component.space()) + .append(Component.text("line 3")) + .build(), + result + ); + } + @Test final void testStandardJoinConfigurationsCommas() { final Component result = Component.join(JoinConfiguration.commas(false), Component.text("line 1"), Component.text("line 2"), Component.text("line 3")); From c506cba3b2dd234cbb3faa75c7006d4c23315dc8 Mon Sep 17 00:00:00 2001 From: Daedalus <16168171+RedDaedalus@users.noreply.github.com> Date: Sun, 13 Aug 2023 14:15:37 -0600 Subject: [PATCH 2/2] Update api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java Co-authored-by: zml --- .../main/java/net/kyori/adventure/text/JoinConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java b/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java index 67db711b0..44709a988 100644 --- a/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java +++ b/api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java @@ -125,7 +125,7 @@ public interface JoinConfiguration extends Buildable * * @return the join configuration - * @since 4.14.0 + * @since 4.15.0 */ static @NotNull JoinConfiguration spaces() { return JoinConfigurationImpl.STANDARD_SPACES;