diff --git a/gradle.properties b/gradle.properties index 3d70e8b9..2bbf4ed4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,5 +9,5 @@ javaVersion=21 mcVersion=1.21.4 group=dev.slne.surf -version=1.21.4-2.13.1-SNAPSHOT +version=1.21.4-2.13.2-SNAPSHOT relocationPrefix=dev.slne.surf.surfapi.libs \ No newline at end of file diff --git a/surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/messages/CommonComponents.kt b/surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/messages/CommonComponents.kt index 2d8c2923..30818277 100644 --- a/surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/messages/CommonComponents.kt +++ b/surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/messages/CommonComponents.kt @@ -349,9 +349,7 @@ object CommonComponents { collection: Iterable, formatter: (E) -> Component, ): Component { - val joinConfig = JoinConfiguration.builder() - .separator(Component.text(", ", SPACER)) - .build() + val joinConfig = JoinConfiguration.builder().separator(Component.text(", ", SPACER)).build() return Component.join(joinConfig, collection.mapTo(mutableObjectListOf(), formatter)) } @@ -382,15 +380,20 @@ object CommonComponents { linePrefix: Component = PREFIX, formatter: (E) -> Component, ): Component { - val joinConfig = JoinConfiguration.builder() - .separator(buildText0 { - appendNewline() - append(linePrefix) - appendText("- ", SPACER) - }) - .build() + val separator = buildText0 { + appendNewline() + append(linePrefix) + appendText("- ", SPACER) + } + val joinConfig = JoinConfiguration.builder().separator(separator).build() - return Component.join(joinConfig, collection.mapTo(mutableObjectListOf(), formatter)) + val firstPrefix = if (collection.iterator().hasNext()) separator else Component.empty() + + return firstPrefix.append( + Component.join( + joinConfig, collection.mapTo(mutableObjectListOf(), formatter) + ) + ) } /** @@ -422,20 +425,26 @@ object CommonComponents { linePrefix: Component = PREFIX, keyValueSeparator: Component = MAP_SEPERATOR, ): Component { - val joinConfig = JoinConfiguration.builder() - .separator(buildText0 { - appendNewline() - append(linePrefix) - appendText("- ", SPACER) - }) - - return Component.join(joinConfig, map.mapTo(mutableObjectListOf()) { (key, value) -> - buildText0 { - append(keyFormatter(key).colorIfAbsent(VARIABLE_KEY)) - append(keyValueSeparator) - append(valueFormatter(value).colorIfAbsent(VARIABLE_VALUE)) - } - }) + val separator = buildText0 { + appendNewline() + append(linePrefix) + appendText("- ", SPACER) + } + val joinConfig = JoinConfiguration.builder().separator(separator).build() + val firstPrefix = if (map.isNotEmpty()) separator else Component.empty() + + return firstPrefix.append( + Component.join( + joinConfig, + map.mapTo(mutableObjectListOf()) { (key, value) -> + buildText0 { + append(keyFormatter(key).colorIfAbsent(VARIABLE_KEY)) + append(keyValueSeparator) + append(valueFormatter(value).colorIfAbsent(VARIABLE_VALUE)) + } + } + ) + ) } /**