Removed unnecessary method and restructured code

This commit is contained in:
bluefireoly
2020-07-15 15:29:01 +02:00
parent 48499bc1fe
commit c23940ea0c
2 changed files with 14 additions and 42 deletions

View File

@@ -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 {

View File

@@ -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())
}