Skip to content

Commit 051ace8

Browse files
committed
feat: custom identify item
1 parent 9ffab07 commit 051ace8

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/main/kotlin/cc/modlabs/kpaper/extensions/InventoryExtensions.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ fun getInventorySlot(y: Int, x: Int): Int {
5858
return x + y * 9
5959
}
6060

61-
6261
inline fun item(
6362
material: Material,
6463
amount: Int = 1,
@@ -82,21 +81,20 @@ fun ItemStack.lore(lore: List<String>): ItemStack = meta<ItemMeta> {
8281
this.lore(lore.map { text(it) })
8382
}
8483

85-
fun openWithIdentifier(player: Player, inv: Inventory, identifier: String? = null, vararg identifiers: Map<NamespacedKey, String>? = arrayOf()) {
86-
87-
if (identifier != null) inv.identify(identifier, *identifiers)
84+
fun openWithIdentifier(player: Player, inv: Inventory, identifier: String? = null, vararg identifiers: Map<NamespacedKey, String>? = arrayOf(), identificationItem: ItemStack = Material.LIGHT_GRAY_STAINED_GLASS_PANE.asQuantity(1)) {
85+
if (identifier != null) inv.identify(identifier, *identifiers, identificationItem = identificationItem)
8886
player.openInventory(inv)
8987
}
9088

91-
fun Inventory.identify(identifier: String, vararg identifiers: Map<NamespacedKey, String>? = arrayOf()) {
89+
fun Inventory.identify(identifier: String, vararg identifiers: Map<NamespacedKey, String>? = arrayOf(), identificationItem: ItemStack = Material.LIGHT_GRAY_STAINED_GLASS_PANE.asQuantity(1)) {
9290
this.setItem(0, this.getItem(0)?.toItemBuilder {
9391
addPersistentData(NAMESPACE_GUI_IDENTIFIER, identifier)
9492
identifiers.forEach { map ->
9593
map?.forEach { (key, value) ->
9694
addPersistentData(key, value)
9795
}
9896
}
99-
}?.build() ?: Material.LIGHT_GRAY_STAINED_GLASS_PANE.toItemBuilder {
97+
}?.build() ?: identificationItem.toItemBuilder {
10098
addPersistentData(NAMESPACE_GUI_IDENTIFIER, identifier)
10199
identifiers.forEach { map ->
102100
map?.forEach { (key, value) ->

0 commit comments

Comments
 (0)