From f54f99bcea7a2905f230df09510bebcf85496ee7 Mon Sep 17 00:00:00 2001 From: joserobjr Date: Fri, 21 Oct 2016 04:13:58 -0300 Subject: [PATCH] Added spigot color utility --- .../br/com/gamemods/kotlinfun/bukkit/color.kt | 4 +-- .../com/gamemods/kotlinfun/bukkit/player.kt | 1 + .../com/gamemods/kotlinfun/bukkit/spigot.kt | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/spigot.kt diff --git a/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/color.kt b/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/color.kt index 3348562..3b0fb78 100644 --- a/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/color.kt +++ b/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/color.kt @@ -8,7 +8,7 @@ import java.util.* class Colorized(str: String) : ColorizedBase(str) { override val format : EnumSet = EnumSet.noneOf(ChatColor::class.java) - fun currentFormat() = format.clone() + fun currentFormat(): EnumSet = format.clone() private fun setColor(c: ChatColor?) : Colorized { color = c @@ -68,4 +68,4 @@ fun String.strike() = Colorized(this).strike() fun String.underline() = Colorized(this).underline() fun String.italic() = Colorized(this).italic() -operator fun ChatColor.plus(str : String) = this.toString() + str +operator fun ChatColor.plus(o: Any?) = this.toString() + o diff --git a/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/player.kt b/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/player.kt index 5c65aee..3271ca3 100644 --- a/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/player.kt +++ b/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/player.kt @@ -1,3 +1,4 @@ +@file:JvmName("PlayerUtil") package br.com.gamemods.kotlinfun.bukkit import org.bukkit.Bukkit diff --git a/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/spigot.kt b/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/spigot.kt new file mode 100644 index 0000000..9cca7a8 --- /dev/null +++ b/BukkitPlugin/src/main/kotlin/br/com/gamemods/kotlinfun/bukkit/spigot.kt @@ -0,0 +1,27 @@ +@file:JvmName("SpigotUtil") +package br.com.gamemods.kotlinfun.bukkit + +import br.com.gamemods.kotlinfun.bungee.ComponentArray +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.chat.* + +fun Colorized.builder() = ComponentArray(create()) +fun Colorized.color(color: ChatColor) = builder().color(color) +fun Colorized.obfuscated(magic: Boolean) = builder().obfuscated(magic) +fun Colorized.bold(bold: Boolean) = builder().bold(bold) +fun Colorized.strikethrough(strike: Boolean) = builder().strikethrough(strike) +fun Colorized.underlined(underlined: Boolean) = builder().underlined(underlined) +fun Colorized.italic(italic: Boolean) = builder().italic(italic) +fun Colorized.append(text: String) = builder().append(text) +fun Colorized.append(text: String, retention: ComponentBuilder.FormatRetention) = builder().append(text, retention) +fun Colorized.insertion(insertion: String) = builder().insertion(insertion) +fun Colorized.event(clickEvent: ClickEvent) = builder().event(clickEvent) +fun Colorized.event(hoverEvent: HoverEvent) = builder().event(hoverEvent) +fun Colorized.retain(retain: ComponentBuilder.FormatRetention) = builder().retain(retain) + +fun Colorized.create(): Array = TextComponent.fromLegacyText(toString()) + +operator fun Colorized.plus(o: BaseComponent) = builder() + o +operator fun Colorized.plus(o: ComponentBuilder) = builder() + o +operator fun Colorized.plus(o: ComponentArray) = builder() + o +operator fun Colorized.plus(o: Array) = builder() + o