Simplified usage state watching
This commit is contained in:
@@ -29,6 +29,8 @@ abstract class InventoryGUI<T : ForInventory>(
|
|||||||
|
|
||||||
internal var isInMove: Boolean = false
|
internal var isInMove: Boolean = false
|
||||||
|
|
||||||
|
internal val currentElements = HashSet<InventoryGUIElement<*>>()
|
||||||
|
|
||||||
internal abstract fun loadPageUnsafe(
|
internal abstract fun loadPageUnsafe(
|
||||||
page: Int,
|
page: Int,
|
||||||
offsetHorizontally: Int = 0,
|
offsetHorizontally: Int = 0,
|
||||||
@@ -116,7 +118,14 @@ class InventoryGUIShared<T : ForInventory>(
|
|||||||
if (!ifOffset) {
|
if (!ifOffset) {
|
||||||
|
|
||||||
// unregister this inv from all elements on the previous page
|
// unregister this inv from all elements on the previous page
|
||||||
HashSet(currentPage.slots.values).forEach { if (it is InventoryGUIElement) it.stopUsing(this) }
|
currentElements.forEach { it.stopUsing(this) }
|
||||||
|
currentElements.clear()
|
||||||
|
|
||||||
|
// register this inv for all new elements
|
||||||
|
HashSet(page.slots.values).forEach { if (it is InventoryGUIElement) {
|
||||||
|
currentElements += it
|
||||||
|
it.startUsing(this)
|
||||||
|
} }
|
||||||
|
|
||||||
currentPageInt = page.number
|
currentPageInt = page.number
|
||||||
|
|
||||||
@@ -144,6 +153,7 @@ class InventoryGUIShared<T : ForInventory>(
|
|||||||
}
|
}
|
||||||
} else bukkitInventory.clear()
|
} else bukkitInventory.clear()
|
||||||
|
|
||||||
|
// render the given content
|
||||||
content.forEach {
|
content.forEach {
|
||||||
|
|
||||||
val slot = it.value
|
val slot = it.value
|
||||||
@@ -155,10 +165,7 @@ class InventoryGUIShared<T : ForInventory>(
|
|||||||
val offsetSlot = invSlot.add(offsetHorizontally, offsetVertically).realSlotIn(dimensions)
|
val offsetSlot = invSlot.add(offsetHorizontally, offsetVertically).realSlotIn(dimensions)
|
||||||
if (offsetSlot != null) bukkitInventory.setItem(offsetSlot, slot.getItemStack(offsetSlot))
|
if (offsetSlot != null) bukkitInventory.setItem(offsetSlot, slot.getItemStack(offsetSlot))
|
||||||
}
|
}
|
||||||
} else {
|
} else bukkitInventory.setItem(it.key, slot.getItemStack(it.key))
|
||||||
bukkitInventory.setItem(it.key, slot.getItemStack(it.key))
|
|
||||||
slot.startUsing(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user