From c23940ea0c95de297c1fd366cb6ab2afea634ff7 Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Wed, 15 Jul 2020 15:29:01 +0200 Subject: [PATCH] Removed unnecessary method and restructured code --- .../net/axay/kspigot/chat/KSpigotChat.kt | 42 ------------------- .../axay/kspigot/chat/MessageExtensions.kt | 14 +++++++ 2 files changed, 14 insertions(+), 42 deletions(-) create mode 100644 src/main/kotlin/net/axay/kspigot/chat/MessageExtensions.kt diff --git a/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt b/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt index 7f7ce1cc..c02566bc 100644 --- a/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt +++ b/src/main/kotlin/net/axay/kspigot/chat/KSpigotChat.kt @@ -7,7 +7,6 @@ import net.md_5.bungee.api.chat.* import net.md_5.bungee.api.chat.hover.content.Entity import net.md_5.bungee.api.chat.hover.content.Item import net.md_5.bungee.api.chat.hover.content.Text -import org.bukkit.command.CommandSender object KSpigotChat { @@ -15,47 +14,6 @@ object KSpigotChat { return KSpigotComponentBuilder().apply(builder).create() } - fun CommandSender.sendMessage(vararg components: BaseComponent) { - this.spigot().sendMessage(*components) - } - - /** - * Takes objects of the type [String] or [ChatColor], - * combines them to a message and sends it to the player. - */ - fun CommandSender.sendMessage(vararg messageParts: Any) { - sendMessage(buildComponent { - - var currentColor = ChatColor.WHITE - val currentMessage = StringBuilder() - - fun buildText() { - text { - text = currentMessage.toString() - color = currentColor - } - currentMessage.clear() - } - - for (messagePart in messageParts.withIndex()) { - - val index = messagePart.index - val value = messagePart.value - - if (value is String) { - currentMessage.append(value) - if (index == messageParts.lastIndex) - buildText() - } else if (value is ChatColor) { - buildText() - currentColor = value - } - - } - - }) - } - } class KSpigotComponentBuilder { diff --git a/src/main/kotlin/net/axay/kspigot/chat/MessageExtensions.kt b/src/main/kotlin/net/axay/kspigot/chat/MessageExtensions.kt new file mode 100644 index 00000000..9abf83ec --- /dev/null +++ b/src/main/kotlin/net/axay/kspigot/chat/MessageExtensions.kt @@ -0,0 +1,14 @@ +@file:Suppress("MemberVisibilityCanBePrivate") + +package net.axay.kspigot.chat + +import net.md_5.bungee.api.chat.BaseComponent +import org.bukkit.command.CommandSender + +fun CommandSender.sendMessage(vararg components: BaseComponent) { + this.spigot().sendMessage(*components) +} + +fun CommandSender.sendMessage(builder: KSpigotComponentBuilder.() -> Unit) { + this.spigot().sendMessage(*KSpigotComponentBuilder().apply(builder).create()) +} \ No newline at end of file