Update formatting

This commit is contained in:
Jakob K
2021-05-15 21:26:10 +02:00
parent ddc576a394
commit fa8fa9ae96
71 changed files with 203 additions and 249 deletions

View File

@@ -7,6 +7,7 @@ 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 java.awt.Color
inline fun chatComponent(builder: KSpigotComponentBuilder.() -> Unit): Array<out BaseComponent> {
return KSpigotComponentBuilder().apply(builder).create()
@@ -14,7 +15,7 @@ inline fun chatComponent(builder: KSpigotComponentBuilder.() -> Unit): Array<out
class KSpigotComponentBuilder {
private val components = ArrayList<BaseComponent>()
// COMPONENTS
inline fun text(text: String, builder: TextComponent.() -> Unit = { }) {
this += TextComponent(text).apply(builder)
}
@@ -41,7 +42,7 @@ class KSpigotComponentBuilder {
) {
this += TranslatableComponent(translatable, with).apply(builder)
}
// SPECIAL
fun legacyText(text: String, color: ChatColor = ChatColor.WHITE, builder: BaseComponent.() -> Unit = { }) {
this += TextComponent.fromLegacyText(text, color).onEach { it.apply(builder) }
}
@@ -56,10 +57,7 @@ class KSpigotComponentBuilder {
fun create() = components.toTypedArray()
}
/*
* BASE COMPONENT
*/
// extensions
inline fun BaseComponent.hoverEventText(builder: KSpigotComponentBuilder.() -> Unit) {
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(KSpigotComponentBuilder().apply(builder).create()))
}
@@ -75,8 +73,7 @@ fun BaseComponent.hoverEventEntity(type: String, id: String, baseComponent: Base
fun BaseComponent.clickEvent(action: ClickEvent.Action, value: String) {
clickEvent = ClickEvent(action, value)
}
/*
* GLOBAL SHORTCUTS
*/
fun col(hex: String): ChatColor = ChatColor.of(hex)
fun col(hex: String): ChatColor = ChatColor.of(hex)
fun col(rgb: Int): ChatColor = ChatColor.of(Color(rgb))

View File

@@ -11,4 +11,4 @@ fun CommandSender.sendMessage(vararg components: BaseComponent) {
fun CommandSender.sendMessage(builder: KSpigotComponentBuilder.() -> Unit) {
this.spigot().sendMessage(*KSpigotComponentBuilder().apply(builder).create())
}
}

View File

@@ -76,7 +76,9 @@ internal abstract class PlayerInput<T>(
timeoutSeconds: Int,
) {
private var received = false
protected abstract val inputListeners: List<Listener>
protected fun onReceive(input: T?) {
if (!received) {
inputListeners.forEach { it.unregister() }
@@ -95,4 +97,4 @@ internal abstract class PlayerInput<T>(
onReceive(null)
}
}
}
}

View File

@@ -41,6 +41,7 @@ internal class PlayerInputAnvilInv(
)
.text("${KColors.ORANGERED}$startText")
.open(player)
override val inputListeners = listOf(
listen<InventoryClickEvent> {
if (it.clickedInventory == anvilInv.inventory)
@@ -51,4 +52,4 @@ internal class PlayerInputAnvilInv(
override fun onTimeout() {
anvilInv.inventory.closeForViewers()
}
}
}

View File

@@ -46,6 +46,7 @@ internal abstract class PlayerInputBook<T>(
}
abstract fun loadBookContent(bookMeta: BookMeta): T
override val inputListeners = listOf(
listen<PlayerEditBookEvent> {
val meta = it.newBookMeta
@@ -63,11 +64,13 @@ internal abstract class PlayerInputBook<T>(
companion object {
val idKey = NamespacedKey(KSpigotMainInstance, "kspigot_bookinput_id")
internal val usedIDs = ArrayList<Int>()
fun getID(): Int {
var returnID = (0..Int.MAX_VALUE).random()
while (usedIDs.contains(returnID)) returnID = (0..Int.MAX_VALUE).random()
return returnID
}
}
}
}

View File

@@ -14,7 +14,6 @@ internal class PlayerInputChat(
timeoutSeconds: Int,
question: String,
) : PlayerInput<String>(player, callback, timeoutSeconds) {
init {
player.sendMessage("${KColors.ORANGERED}$question")
}
@@ -27,4 +26,4 @@ internal class PlayerInputChat(
}
}
)
}
}