Skip to content

Commit

Permalink
Added spigot color utility
Browse files Browse the repository at this point in the history
  • Loading branch information
joserobjr committed Oct 21, 2016
1 parent f3f8043 commit f54f99b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.*
class Colorized(str: String) : ColorizedBase<ChatColor>(str) {
override val format : EnumSet<ChatColor> = EnumSet.noneOf(ChatColor::class.java)

fun currentFormat() = format.clone()
fun currentFormat(): EnumSet<ChatColor> = format.clone()

private fun setColor(c: ChatColor?) : Colorized {
color = c
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:JvmName("PlayerUtil")
package br.com.gamemods.kotlinfun.bukkit

import org.bukkit.Bukkit
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BaseComponent> = 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<out BaseComponent>) = builder() + o

0 comments on commit f54f99b

Please sign in to comment.