From 3d41e4ae9d8840d45b12ea938a81eef59cc8c21a Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Sat, 3 Oct 2020 14:07:16 +0200 Subject: [PATCH] Replaced append with plusAssign - added plusAssign for Array --- .../kotlin/net/axay/kspigot/chat/KSpigotChat.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt b/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt index 8a4c2de4..e43844f3 100644 --- a/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt +++ b/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt @@ -17,29 +17,31 @@ class KSpigotComponentBuilder { private val components = ArrayList() inline fun text(text: String, builder: TextComponent.() -> Unit = { }) { - append(TextComponent(text).apply(builder)) + this += TextComponent(text).apply(builder) } inline fun keybind(keybind: String, builder: KeybindComponent.() -> Unit = { }) { - append(KeybindComponent(keybind).apply(builder)) + this += KeybindComponent(keybind).apply(builder) } inline fun score(name: String, objective: String, value: String?, builder: ScoreComponent.() -> Unit = { }) { if (value != null) - append(ScoreComponent(name, objective, value).apply(builder)) + this += ScoreComponent(name, objective, value).apply(builder) else - append(ScoreComponent(name, objective).apply(builder)) + this += ScoreComponent(name, objective).apply(builder) } inline fun selector(selector: String, builder: SelectorComponent.() -> Unit = { }) { - append(SelectorComponent(selector).apply(builder)) + this += SelectorComponent(selector).apply(builder) } inline fun translatable(translatable: String, with: Array, builder: TranslatableComponent.() -> Unit = { }) { - append(TranslatableComponent(translatable, with).apply(builder)) + this += TranslatableComponent(translatable, with).apply(builder) } - fun append(baseComponent: BaseComponent) { components += baseComponent } + operator fun plusAssign(baseComponent: BaseComponent) { components += baseComponent } + operator fun plusAssign(baseComponents: Array) { components += baseComponents } + fun create() = components.toTypedArray() }