Update KSpigotChat.kt

This commit is contained in:
bluefireoly
2020-07-12 00:35:36 +02:00
parent 69ca7651b3
commit 0d2d9ec314

View File

@@ -4,7 +4,7 @@ package net.axay.kspigot.chat
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.*
import org.bukkit.entity.Player
import org.bukkit.command.CommandSender
object KSpigotChat {
@@ -12,7 +12,7 @@ object KSpigotChat {
return KSpigotComponentBuilder().apply(builder).create()
}
fun Player.sendMessage(vararg components: BaseComponent) {
fun CommandSender.sendMessage(vararg components: BaseComponent) {
this.spigot().sendMessage(*components)
}
@@ -20,25 +20,25 @@ object KSpigotChat {
* Takes objects of the type [String] or [ChatColor],
* combines them to a message and sends it to the player.
*/
fun Player.sendMessage(vararg messageParts: Any) {
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
fun buildText() {
text {
text = currentMessage.toString()
color = currentColor
}
currentMessage.clear()
}
if (value is String) {
currentMessage.append(value)
if (index == messageParts.lastIndex)