Skip to content

Commit cbde70a

Browse files
committed
added admin gui
Signed-off-by: illyrius666 <[email protected]>
1 parent 64821ed commit cbde70a

3 files changed

Lines changed: 147 additions & 9 deletions

File tree

IllyriaKingdoms/src/commands/KingdomCmd.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import org.bukkit.permissions.Permission
55
import org.bukkit.permissions.PermissionDefault
66
import org.xodium.illyriaplus.IllyriaKingdoms.Companion.instance
77
import org.xodium.illyriaplus.data.CommandData
8+
import org.xodium.illyriaplus.guis.AdminGui
89
import org.xodium.illyriaplus.interfaces.CmdInterface
9-
import org.xodium.illyriaplus.items.SceptreItem
1010
import org.xodium.illyriaplus.utils.CommandUtils.playerExecuted
1111
import kotlin.uuid.ExperimentalUuidApi
1212

1313
/**
14-
* Command to create a new kingdom and receive its sceptre.
15-
* Usage: /kingdom create <name>
14+
* Command to open the kingdom admin GUI.
15+
* Usage: /kingdom
1616
*/
1717
@OptIn(ExperimentalUuidApi::class)
1818
internal object KingdomCmd : CmdInterface {
@@ -22,12 +22,8 @@ internal object KingdomCmd : CmdInterface {
2222
Commands
2323
.literal("kingdom")
2424
.requires { it.sender.hasPermission(perms[0]) }
25-
.then(
26-
Commands
27-
.literal("create")
28-
.playerExecuted { player, _ -> player.inventory.addItem(SceptreItem.item) },
29-
),
30-
"Create a new kingdom and receive its sceptre",
25+
.playerExecuted { player, _ -> AdminGui.window(player).open() },
26+
"Open the kingdom admin GUI",
3127
listOf("k"),
3228
),
3329
)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package org.xodium.illyriaplus.guis
2+
3+
import io.papermc.paper.datacomponent.DataComponentTypes
4+
import io.papermc.paper.datacomponent.item.ItemLore
5+
import net.kyori.adventure.text.Component
6+
import org.bukkit.Material
7+
import org.bukkit.entity.Player
8+
import org.bukkit.inventory.ItemStack
9+
import org.xodium.illyriaplus.data.KingdomData
10+
import org.xodium.illyriaplus.items.SceptreItem
11+
import org.xodium.illyriaplus.managers.KingdomManager
12+
import org.xodium.illyriaplus.utils.Utils.GUI_FILLER_ITEM
13+
import org.xodium.illyriaplus.utils.Utils.MM
14+
import xyz.xenondevs.invui.gui.Markers
15+
import xyz.xenondevs.invui.gui.PagedGui
16+
import xyz.xenondevs.invui.item.BoundItem
17+
import xyz.xenondevs.invui.item.Item
18+
import xyz.xenondevs.invui.window.Window
19+
import kotlin.uuid.ExperimentalUuidApi
20+
21+
/** Admin GUI for managing kingdoms with paginated list view. */
22+
@Suppress("UnstableApiUsage")
23+
@OptIn(ExperimentalUuidApi::class)
24+
internal object AdminGui {
25+
private const val GUI_TITLE = "<gradient:#FFA751:#FFE259>Kingdoms Admin Panel</gradient>"
26+
27+
private fun kingdomItem(kingdom: KingdomData): Item =
28+
Item
29+
.builder()
30+
.setItemProvider(
31+
ItemStack.of(Material.PLAYER_HEAD).apply {
32+
setData(DataComponentTypes.ITEM_NAME, kingdom.displayName())
33+
setData(
34+
DataComponentTypes.LORE,
35+
ItemLore.lore(
36+
listOf(
37+
Component.empty(),
38+
MM.deserialize("<gray>ID: <white>${kingdom.id}"),
39+
MM.deserialize("<gray>Members: <white>${kingdom.members.size}"),
40+
Component.empty(),
41+
MM.deserialize("<yellow>Click to view details"),
42+
MM.deserialize("<red>Shift+Click to delete"),
43+
),
44+
),
45+
)
46+
},
47+
).addClickHandler { _, click ->
48+
if (click.clickType.isShiftClick) {
49+
KingdomManager.remove(kingdom.id)
50+
click.player.sendMessage(MM.deserialize("<green>Kingdom '${kingdom.name}' has been removed."))
51+
window(click.player).open()
52+
} else {
53+
MainGui.window(click.player, kingdom).open()
54+
}
55+
}.build()
56+
57+
private val create: Item =
58+
Item
59+
.builder()
60+
.setItemProvider(
61+
ItemStack.of(Material.EMERALD_BLOCK).apply {
62+
setData(DataComponentTypes.ITEM_NAME, MM.deserialize("<green>Create Kingdom"))
63+
},
64+
).addClickHandler { _, click ->
65+
click.player.inventory.addItem(SceptreItem.item)
66+
click.player.sendMessage(MM.deserialize("<green>Received a Kingdom Sceptre."))
67+
}.build()
68+
69+
private val delete: Item =
70+
Item
71+
.builder()
72+
.setItemProvider(
73+
ItemStack.of(Material.REDSTONE_BLOCK).apply {
74+
setData(DataComponentTypes.ITEM_NAME, MM.deserialize("<red>Delete Kingdom</red>"))
75+
setData(
76+
DataComponentTypes.LORE,
77+
ItemLore.lore(listOf(MM.deserialize("<gray>Shift+Click a kingdom to delete it"))),
78+
)
79+
},
80+
).build()
81+
82+
private val back: BoundItem =
83+
BoundItem
84+
.pagedBuilder()
85+
.setItemProvider(
86+
ItemStack.of(Material.ARROW).apply {
87+
setData(DataComponentTypes.ITEM_NAME, MM.deserialize("<gray>Previous Page"))
88+
},
89+
).addClickHandler { _, gui, _ -> gui.page++ }
90+
.build()
91+
92+
private val forward: BoundItem =
93+
BoundItem
94+
.pagedBuilder()
95+
.setItemProvider(
96+
ItemStack.of(Material.ARROW).apply {
97+
setData(DataComponentTypes.ITEM_NAME, MM.deserialize("<gray>Next Page"))
98+
},
99+
).addClickHandler { _, gui, _ -> gui.page++ }
100+
.build()
101+
102+
fun window(player: Player): Window =
103+
Window
104+
.builder()
105+
.setTitle(MM.deserialize(GUI_TITLE))
106+
.setUpperGui(
107+
PagedGui
108+
.itemsBuilder()
109+
.setStructure(
110+
"# # # # # # # # #",
111+
"# x x x x x x x #",
112+
"# x x x x x x x #",
113+
"# x x x x x x x #",
114+
"# C # B # F # D #",
115+
).addIngredient('#', GUI_FILLER_ITEM)
116+
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
117+
.addIngredient('C', create)
118+
.addIngredient('D', delete)
119+
.addIngredient('F', forward)
120+
.addIngredient('B', back)
121+
.setContent(KingdomManager.getAll().map { kingdomItem(it) })
122+
.build(),
123+
).setViewer(player)
124+
.build()
125+
}

IllyriaKingdoms/src/managers/KingdomManager.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,21 @@ internal object KingdomManager {
5151
* @return The [KingdomData] if found, null otherwise.
5252
*/
5353
fun get(id: Uuid): KingdomData? = kingdoms[id]
54+
55+
/**
56+
* Gets all kingdoms.
57+
*
58+
* @return A list of all [KingdomData].
59+
*/
60+
fun getAll(): List<KingdomData> = kingdoms.values.toList()
61+
62+
/**
63+
* Removes a kingdom by ID and saves to disk.
64+
*
65+
* @param id The UUID of the kingdom to remove.
66+
*/
67+
fun remove(id: Uuid) {
68+
kingdoms.remove(id)
69+
save()
70+
}
5471
}

0 commit comments

Comments
 (0)