WIP: BookUI
This commit is contained in:
parent
8f6f505cb4
commit
2621d28e67
|
|
@ -221,53 +221,52 @@ class SectorListener(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open GUI
|
// Create Written Book for UI
|
||||||
val gui = org.bukkit.Bukkit.createInventory(null, 27, Component.text("Sector Manager (#${sectorId})", NamedTextColor.BLACK))
|
val book = org.bukkit.inventory.ItemStack(Material.WRITTEN_BOOK)
|
||||||
|
val meta = book.itemMeta as org.bukkit.inventory.meta.BookMeta
|
||||||
|
|
||||||
// Info Item with Ranges
|
meta.title(Component.text("Sector Manager"))
|
||||||
|
meta.author(Component.text("System"))
|
||||||
|
|
||||||
|
// Build Page Content
|
||||||
|
val content = Component.text()
|
||||||
|
.append(Component.text("Sector Core @ ${sector.x},${sector.y},${sector.z}\n\n", NamedTextColor.BLACK))
|
||||||
|
|
||||||
|
// Actions Row 1
|
||||||
|
content.append(
|
||||||
|
Component.text("[Activate]", NamedTextColor.DARK_GREEN)
|
||||||
|
.clickEvent(ClickEvent.runCommand("/landsector activate $sectorId"))
|
||||||
|
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(Component.text("Click to activate sector")))
|
||||||
|
)
|
||||||
|
content.append(Component.text(" "))
|
||||||
|
content.append(
|
||||||
|
Component.text("[Destroy]\n", NamedTextColor.RED)
|
||||||
|
.clickEvent(ClickEvent.runCommand("/landsector cancel $sectorId"))
|
||||||
|
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(Component.text("Click to destroy sector")))
|
||||||
|
)
|
||||||
|
|
||||||
|
// Actions Row 2
|
||||||
|
content.append(
|
||||||
|
Component.text("[Get Tool]\n\n", NamedTextColor.DARK_AQUA)
|
||||||
|
.clickEvent(ClickEvent.runCommand("/landsector givetool $sectorId"))
|
||||||
|
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(Component.text("Click to get selection tool")))
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ranges List
|
||||||
val ranges = sectorService.getRanges(sectorId)
|
val ranges = sectorService.getRanges(sectorId)
|
||||||
val rangeLore = ranges.map { Component.text(" - [${it.id}] ${it.type}", NamedTextColor.GRAY) }
|
if (ranges.isEmpty()) {
|
||||||
val infoLore = mutableListOf<Component>()
|
content.append(Component.text("Parts: None", NamedTextColor.GRAY))
|
||||||
infoLore.add(Component.text("Sector ID: $sectorId", NamedTextColor.WHITE))
|
} else {
|
||||||
infoLore.addAll(rangeLore)
|
content.append(Component.text("Parts:", NamedTextColor.BLACK))
|
||||||
|
ranges.forEach { range ->
|
||||||
gui.setItem(4, createGuiItem(
|
content.append(Component.text("\n- [${range.id}] ${range.type}", NamedTextColor.DARK_GRAY))
|
||||||
Material.PAPER,
|
}
|
||||||
Component.text("Sector Info", NamedTextColor.GOLD),
|
}
|
||||||
infoLore,
|
|
||||||
sectorId,
|
|
||||||
"info"
|
|
||||||
))
|
|
||||||
|
|
||||||
// Get Selection Tool
|
meta.addPages(content.build())
|
||||||
gui.setItem(11, createGuiItem(
|
book.itemMeta = meta
|
||||||
Material.FLINT,
|
|
||||||
Component.text("Get Selection Tool", NamedTextColor.AQUA),
|
|
||||||
listOf(Component.text("Click to receive the selection tool.", NamedTextColor.GRAY)),
|
|
||||||
sectorId,
|
|
||||||
"give_tool"
|
|
||||||
))
|
|
||||||
|
|
||||||
// Activate
|
player.openBook(book)
|
||||||
gui.setItem(13, createGuiItem(
|
|
||||||
Material.LIME_CONCRETE,
|
|
||||||
Component.text("Activate Sector", NamedTextColor.GREEN),
|
|
||||||
listOf(Component.text("Click to activate this sector.", NamedTextColor.GRAY)),
|
|
||||||
sectorId,
|
|
||||||
"activate"
|
|
||||||
))
|
|
||||||
|
|
||||||
// Cancel / Destroy
|
|
||||||
gui.setItem(15, createGuiItem(
|
|
||||||
Material.RED_CONCRETE,
|
|
||||||
Component.text("Cancel / Destroy", NamedTextColor.RED),
|
|
||||||
listOf(Component.text("Click to destroy this sector.", NamedTextColor.GRAY)),
|
|
||||||
sectorId,
|
|
||||||
"cancel"
|
|
||||||
))
|
|
||||||
|
|
||||||
player.openInventory(gui)
|
|
||||||
|
|
||||||
event.isCancelled = true
|
event.isCancelled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -420,47 +419,4 @@ class SectorListener(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
fun onInventoryClick(event: org.bukkit.event.inventory.InventoryClickEvent) {
|
|
||||||
val item = event.currentItem ?: return
|
|
||||||
val meta = item.itemMeta ?: return
|
|
||||||
val pluginKey = NamespacedKey(plugin, "gui_action")
|
|
||||||
|
|
||||||
if (!meta.persistentDataContainer.has(pluginKey, PersistentDataType.STRING)) return
|
|
||||||
|
|
||||||
event.isCancelled = true // Prevent taking items
|
|
||||||
|
|
||||||
val player = event.whoClicked as? Player ?: return
|
|
||||||
val action = meta.persistentDataContainer.get(pluginKey, PersistentDataType.STRING)
|
|
||||||
val sectorKey = NamespacedKey(plugin, "sector_id")
|
|
||||||
val sectorId = meta.persistentDataContainer.get(sectorKey, PersistentDataType.INTEGER) ?: return
|
|
||||||
|
|
||||||
player.closeInventory()
|
|
||||||
|
|
||||||
when (action) {
|
|
||||||
"give_tool" -> player.performCommand("landsector givetool $sectorId")
|
|
||||||
"activate" -> player.performCommand("landsector activate $sectorId")
|
|
||||||
"cancel" -> player.performCommand("landsector cancel $sectorId")
|
|
||||||
"info" -> {
|
|
||||||
player.playSound(player.location, Sound.UI_BUTTON_CLICK, 1f, 1f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createGuiItem(material: Material, name: Component, lore: List<Component>, sectorId: Int, action: String): org.bukkit.inventory.ItemStack {
|
|
||||||
val item = org.bukkit.inventory.ItemStack(material)
|
|
||||||
val meta = item.itemMeta
|
|
||||||
meta.displayName(name)
|
|
||||||
meta.lore(lore)
|
|
||||||
|
|
||||||
val actionKey = NamespacedKey(plugin, "gui_action")
|
|
||||||
val sectorKey = NamespacedKey(plugin, "sector_id")
|
|
||||||
|
|
||||||
meta.persistentDataContainer.set(actionKey, PersistentDataType.STRING, action)
|
|
||||||
meta.persistentDataContainer.set(sectorKey, PersistentDataType.INTEGER, sectorId)
|
|
||||||
|
|
||||||
item.itemMeta = meta
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,53 +221,52 @@ class SectorListener(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open GUI
|
// Create Written Book for UI
|
||||||
val gui = org.bukkit.Bukkit.createInventory(null, 27, Component.text("Sector Manager (#${sectorId})", NamedTextColor.BLACK))
|
val book = org.bukkit.inventory.ItemStack(Material.WRITTEN_BOOK)
|
||||||
|
val meta = book.itemMeta as org.bukkit.inventory.meta.BookMeta
|
||||||
|
|
||||||
// Info Item with Ranges
|
meta.title(Component.text("Sector Manager"))
|
||||||
|
meta.author(Component.text("System"))
|
||||||
|
|
||||||
|
// Build Page Content
|
||||||
|
val content = Component.text()
|
||||||
|
.append(Component.text("Sector Core @ ${sector.x},${sector.y},${sector.z}\n\n", NamedTextColor.BLACK))
|
||||||
|
|
||||||
|
// Actions Row 1
|
||||||
|
content.append(
|
||||||
|
Component.text("[Activate]", NamedTextColor.DARK_GREEN)
|
||||||
|
.clickEvent(ClickEvent.runCommand("/landsector activate $sectorId"))
|
||||||
|
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(Component.text("Click to activate sector")))
|
||||||
|
)
|
||||||
|
content.append(Component.text(" "))
|
||||||
|
content.append(
|
||||||
|
Component.text("[Destroy]\n", NamedTextColor.RED)
|
||||||
|
.clickEvent(ClickEvent.runCommand("/landsector cancel $sectorId"))
|
||||||
|
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(Component.text("Click to destroy sector")))
|
||||||
|
)
|
||||||
|
|
||||||
|
// Actions Row 2
|
||||||
|
content.append(
|
||||||
|
Component.text("[Get Tool]\n\n", NamedTextColor.DARK_AQUA)
|
||||||
|
.clickEvent(ClickEvent.runCommand("/landsector givetool $sectorId"))
|
||||||
|
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(Component.text("Click to get selection tool")))
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ranges List
|
||||||
val ranges = sectorService.getRanges(sectorId)
|
val ranges = sectorService.getRanges(sectorId)
|
||||||
val rangeLore = ranges.map { Component.text(" - [${it.id}] ${it.type}", NamedTextColor.GRAY) }
|
if (ranges.isEmpty()) {
|
||||||
val infoLore = mutableListOf<Component>()
|
content.append(Component.text("Parts: None", NamedTextColor.GRAY))
|
||||||
infoLore.add(Component.text("Sector ID: $sectorId", NamedTextColor.WHITE))
|
} else {
|
||||||
infoLore.addAll(rangeLore)
|
content.append(Component.text("Parts:", NamedTextColor.BLACK))
|
||||||
|
ranges.forEach { range ->
|
||||||
gui.setItem(4, createGuiItem(
|
content.append(Component.text("\n- [${range.id}] ${range.type}", NamedTextColor.DARK_GRAY))
|
||||||
Material.PAPER,
|
}
|
||||||
Component.text("Sector Info", NamedTextColor.GOLD),
|
}
|
||||||
infoLore,
|
|
||||||
sectorId,
|
|
||||||
"info"
|
|
||||||
))
|
|
||||||
|
|
||||||
// Get Selection Tool
|
meta.addPages(content.build())
|
||||||
gui.setItem(11, createGuiItem(
|
book.itemMeta = meta
|
||||||
Material.FLINT,
|
|
||||||
Component.text("Get Selection Tool", NamedTextColor.AQUA),
|
|
||||||
listOf(Component.text("Click to receive the selection tool.", NamedTextColor.GRAY)),
|
|
||||||
sectorId,
|
|
||||||
"give_tool"
|
|
||||||
))
|
|
||||||
|
|
||||||
// Activate
|
player.openBook(book)
|
||||||
gui.setItem(13, createGuiItem(
|
|
||||||
Material.LIME_CONCRETE,
|
|
||||||
Component.text("Activate Sector", NamedTextColor.GREEN),
|
|
||||||
listOf(Component.text("Click to activate this sector.", NamedTextColor.GRAY)),
|
|
||||||
sectorId,
|
|
||||||
"activate"
|
|
||||||
))
|
|
||||||
|
|
||||||
// Cancel / Destroy
|
|
||||||
gui.setItem(15, createGuiItem(
|
|
||||||
Material.RED_CONCRETE,
|
|
||||||
Component.text("Cancel / Destroy", NamedTextColor.RED),
|
|
||||||
listOf(Component.text("Click to destroy this sector.", NamedTextColor.GRAY)),
|
|
||||||
sectorId,
|
|
||||||
"cancel"
|
|
||||||
))
|
|
||||||
|
|
||||||
player.openInventory(gui)
|
|
||||||
|
|
||||||
event.isCancelled = true
|
event.isCancelled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -420,47 +419,4 @@ class SectorListener(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
fun onInventoryClick(event: org.bukkit.event.inventory.InventoryClickEvent) {
|
|
||||||
val item = event.currentItem ?: return
|
|
||||||
val meta = item.itemMeta ?: return
|
|
||||||
val pluginKey = NamespacedKey(plugin, "gui_action")
|
|
||||||
|
|
||||||
if (!meta.persistentDataContainer.has(pluginKey, PersistentDataType.STRING)) return
|
|
||||||
|
|
||||||
event.isCancelled = true // Prevent taking items
|
|
||||||
|
|
||||||
val player = event.whoClicked as? Player ?: return
|
|
||||||
val action = meta.persistentDataContainer.get(pluginKey, PersistentDataType.STRING)
|
|
||||||
val sectorKey = NamespacedKey(plugin, "sector_id")
|
|
||||||
val sectorId = meta.persistentDataContainer.get(sectorKey, PersistentDataType.INTEGER) ?: return
|
|
||||||
|
|
||||||
player.closeInventory()
|
|
||||||
|
|
||||||
when (action) {
|
|
||||||
"give_tool" -> player.performCommand("landsector givetool $sectorId")
|
|
||||||
"activate" -> player.performCommand("landsector activate $sectorId")
|
|
||||||
"cancel" -> player.performCommand("landsector cancel $sectorId")
|
|
||||||
"info" -> {
|
|
||||||
player.playSound(player.location, Sound.UI_BUTTON_CLICK, 1f, 1f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createGuiItem(material: Material, name: Component, lore: List<Component>, sectorId: Int, action: String): org.bukkit.inventory.ItemStack {
|
|
||||||
val item = org.bukkit.inventory.ItemStack(material)
|
|
||||||
val meta = item.itemMeta
|
|
||||||
meta.displayName(name)
|
|
||||||
meta.lore(lore)
|
|
||||||
|
|
||||||
val actionKey = NamespacedKey(plugin, "gui_action")
|
|
||||||
val sectorKey = NamespacedKey(plugin, "sector_id")
|
|
||||||
|
|
||||||
meta.persistentDataContainer.set(actionKey, PersistentDataType.STRING, action)
|
|
||||||
meta.persistentDataContainer.set(sectorKey, PersistentDataType.INTEGER, sectorId)
|
|
||||||
|
|
||||||
item.itemMeta = meta
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user