Skip to content

Commit

Permalink
extra-kotlin: Add some JoinConfiguration related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kezz committed Oct 18, 2021
1 parent 0eab517 commit dd3d451
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package net.kyori.adventure.extra.kotlin

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.ComponentLike
import net.kyori.adventure.text.JoinConfiguration

/**
* Add [that] as a child component.
Expand All @@ -33,3 +34,23 @@ import net.kyori.adventure.text.ComponentLike
* @since 4.6.0
*/
operator fun Component.plus(that: ComponentLike): Component = this.append(that)

/**
* Joins this array of components using the provided [config].
*
* @param config the join configuration
* @return the resulting component
* @since 4.10.0
*/
public fun <T : ComponentLike> Array<T>.join(config: JoinConfiguration = JoinConfiguration.noSeparators()): Component =
this.toList().join(config)

/**
* Joins this iterable of components using the provided [config].
*
* @param config the join configuration
* @return the resulting component
* @since 4.10.0
*/
public fun <T : ComponentLike> Iterable<T>.join(config: JoinConfiguration = JoinConfiguration.noSeparators()): Component =
Component.join(config, this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of adventure, licensed under the MIT License.
*
* Copyright (c) 2017-2021 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.extra.kotlin

import net.kyori.adventure.text.JoinConfiguration

/**
* Builds a new join configuration from the provided [builder].
*
* @param builder the builder to configure the resulting join configuration
* @return a new join configuration
* @since 4.10.0
*/
public fun joinConfiguration(builder: JoinConfiguration.Builder.() -> Unit): JoinConfiguration =
JoinConfiguration.builder().also(builder).build()

0 comments on commit dd3d451

Please sign in to comment.