-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: breakup event listeners * misc: bump version
- Loading branch information
1 parent
c50302d
commit 691c54a
Showing
11 changed files
with
411 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/me/tech/mcchestui/listeners/GUICloseListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package me.tech.mcchestui.listeners | ||
|
||
import me.tech.mcchestui.GUI | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.inventory.InventoryCloseEvent | ||
|
||
internal class GUICloseListener(gui: GUI) : GUIEventListener(gui) { | ||
@EventHandler | ||
internal fun InventoryCloseEvent.onClose() { | ||
if(!gui.isBukkitInventory(inventory)) { | ||
return | ||
} | ||
|
||
gui.onCloseInventory?.let { uiEvent -> | ||
uiEvent(this, player) | ||
} | ||
|
||
if(gui.singleInstance) { | ||
return | ||
} | ||
|
||
if(inventory.viewers.size > 1) { | ||
return | ||
} | ||
|
||
gui.unregister() | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/me/tech/mcchestui/listeners/GUIEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package me.tech.mcchestui.listeners | ||
|
||
import me.tech.mcchestui.GUI | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.inventory.InventoryAction | ||
|
||
internal abstract class GUIEventListener( | ||
protected val gui: GUI | ||
) : Listener { | ||
companion object { | ||
/** | ||
* All actions related to placing an item. | ||
*/ | ||
@JvmStatic | ||
protected val PLACE_ACTIONS = listOf( | ||
InventoryAction.PLACE_ONE, | ||
InventoryAction.PLACE_SOME, | ||
InventoryAction.PLACE_ALL, | ||
InventoryAction.SWAP_WITH_CURSOR | ||
) | ||
|
||
/** | ||
* All actions related to using hotkeys to place/pickup | ||
* an item. | ||
*/ | ||
@JvmStatic | ||
protected val HOTBAR_ACTIONS = listOf( | ||
InventoryAction.HOTBAR_SWAP, | ||
InventoryAction.HOTBAR_MOVE_AND_READD | ||
) | ||
|
||
/** | ||
* All actions related to picking up an item. | ||
*/ | ||
@JvmStatic | ||
protected val PICKUP_ACTIONS = listOf( | ||
InventoryAction.PICKUP_ONE, | ||
InventoryAction.PICKUP_SOME, | ||
InventoryAction.PICKUP_HALF, | ||
InventoryAction.PICKUP_ALL, | ||
InventoryAction.SWAP_WITH_CURSOR, | ||
InventoryAction.COLLECT_TO_CURSOR | ||
) | ||
} | ||
} |
Oops, something went wrong.