Skip to content

Commit

Permalink
refactor: Add suspend modifier to 'createInventory' across multiple c…
Browse files Browse the repository at this point in the history
…lasses
  • Loading branch information
cizetux committed Jan 3, 2024
1 parent 2fd2115 commit 0ad4fa6
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/github/rushyverse/api/gui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public abstract class GUI<T>(
* @param key Key to create the inventory for.
* @return New created inventory.
*/
protected abstract fun createInventory(key: T): Inventory
protected abstract suspend fun createInventory(key: T): Inventory

/**
* Create a new flow of [Item][ItemStack] to fill the inventory with.
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/rushyverse/api/gui/PlayerGUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class PlayerGUI(
* @param key The client to create the inventory for.
* @return The inventory for the client.
*/
override fun createInventory(key: Client): Inventory {
override suspend fun createInventory(key: Client): Inventory {
val player = key.requirePlayer()
return createInventory(player, key)
}
Expand All @@ -54,7 +54,7 @@ public abstract class PlayerGUI(
* @param client The client to create the inventory for.
* @return The inventory for the client.
*/
protected abstract fun createInventory(owner: InventoryHolder, client: Client): Inventory
protected abstract suspend fun createInventory(owner: InventoryHolder, client: Client): Inventory

override suspend fun closeClient(client: Client, closeInventory: Boolean): Boolean {
val (inventory, job) = mutex.withLock { inventories.remove(client) } ?: return false
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/rushyverse/api/gui/SingleGUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public abstract class SingleGUI(
return scope + SupervisorJob(scope.coroutineContext.job)
}

override fun createInventory(key: Unit): Inventory {
override suspend fun createInventory(key: Unit): Inventory {
return createInventory()
}

/**
* Create the inventory.
* @return New created inventory.
*/
protected abstract fun createInventory(): Inventory
protected abstract suspend fun createInventory(): Inventory

/**
* Update the inventory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private abstract class AbstractLocaleGUITest(
animation: InventoryLoadingAnimation<Locale>? = null
) : LocaleGUI(plugin, animation) {

override fun createInventory(key: Locale): Inventory {
override suspend fun createInventory(key: Locale): Inventory {
return serverMock.createInventory(null, type)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private abstract class AbstractPlayerGUITest(
loadingAnimation: InventoryLoadingAnimation<Client>? = null
) : PlayerGUI(loadingAnimation) {

override fun createInventory(owner: InventoryHolder, client: Client): Inventory {
override suspend fun createInventory(owner: InventoryHolder, client: Client): Inventory {
return serverMock.createInventory(owner, type)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private abstract class AbstractSingleGUITest(
animation: InventoryLoadingAnimation<Unit>? = null
) : SingleGUI(plugin, animation) {

override fun createInventory(): Inventory {
override suspend fun createInventory(): Inventory {
return serverMock.createInventory(null, type)
}

Expand Down

0 comments on commit 0ad4fa6

Please sign in to comment.