Files
TCOWW/src/main/kotlin/fr/azur/tcoww/ui/PlayerSelectMenu.kt

47 lines
1.6 KiB
Kotlin
Raw Normal View History

2025-11-30 17:22:48 +01:00
package fr.azur.tcoww.ui
import fr.azur.tcoww.Tcoww
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.InventoryCloseEvent
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.SkullMeta
import java.util.concurrent.CompletableFuture
class PlayerSelectMenu(
val players: Iterable<Player>,
) : CustomUI {
val size = (players.count() / 9 + 1) * 9
val future = CompletableFuture<Player?>()
private val inventory =
2025-11-30 19:04:28 +01:00
Tcoww.instance.server.createInventory(this, size, Component.text("Select a player.", NamedTextColor.GREEN)).apply {
2025-11-30 17:22:48 +01:00
players.forEachIndexed { index, player ->
val item =
ItemStack.of(Material.PLAYER_HEAD).apply {
itemMeta =
(itemMeta as SkullMeta).apply {
playerProfile = player.playerProfile
}
}
setItem(index, item)
}
}
override fun getInventory(): Inventory = inventory
override fun onClick(event: InventoryClickEvent) {
val index = event.slot
if (index !in 0..<players.count() || event.clickedInventory != inventory) return
future.complete(players.elementAt(index))
}
override fun onClose(event: InventoryCloseEvent) {
future.complete(null)
}
}