diff --git a/src/main/kotlin/net/axay/kspigot/inventory/elements/InventoryGUISpaceCompound.kt b/src/main/kotlin/net/axay/kspigot/inventory/elements/InventoryGUISpaceCompound.kt index 5da61098..efa3e645 100644 --- a/src/main/kotlin/net/axay/kspigot/inventory/elements/InventoryGUISpaceCompound.kt +++ b/src/main/kotlin/net/axay/kspigot/inventory/elements/InventoryGUISpaceCompound.kt @@ -16,6 +16,10 @@ class InventoryGUISpaceCompoundElement( compound.onClickElement(clickEvent) } + override fun startUsing(gui: InventoryGUI<*>) = compound.registerGUI(gui) + + override fun stopUsing(gui: InventoryGUI<*>) = compound.unregisterGUI(gui) + } class InventoryGUISpaceCompound( @@ -46,6 +50,8 @@ class InventoryGUISpaceCompound( private var contentSort: () -> Unit = { } + private val registeredGUIs = HashSet>() + private fun translateSlot(slot: Int) = (scrolledLines * invType.dimensions.width) + slot private fun contentAtSlot(slot: Int) = content.getOrNull( @@ -70,6 +76,14 @@ class InventoryGUISpaceCompound( realInternalSlots.sort() } + internal fun registerGUI(gui: InventoryGUI<*>) { + registeredGUIs += gui + } + + internal fun unregisterGUI(gui: InventoryGUI<*>) { + registeredGUIs -= gui + } + /** * Defines the sort behaviour which gets applied to the content * automatically. @@ -94,7 +108,7 @@ class InventoryGUISpaceCompound( fun addContent(elements: Collection) { content += elements contentSort.invoke() - // TODO reload GUIs using this compound at this time + registeredGUIs.forEach { it.reloadCurrentPage() } } } \ No newline at end of file