-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9431249
commit a960c11
Showing
12 changed files
with
124 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
72 changes: 72 additions & 0 deletions
72
src/main/kotlin/com/github/rushyverse/api/gui/GUIListener.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,72 @@ | ||
package com.github.rushyverse.api.gui | ||
|
||
import com.github.rushyverse.api.Plugin | ||
import com.github.rushyverse.api.extension.event.cancel | ||
import com.github.rushyverse.api.koin.inject | ||
import com.github.rushyverse.api.player.ClientManager | ||
import org.bukkit.entity.HumanEntity | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.inventory.InventoryClickEvent | ||
import org.bukkit.event.inventory.InventoryCloseEvent | ||
import org.bukkit.event.player.PlayerQuitEvent | ||
|
||
/** | ||
* Listener for GUI events. | ||
* @property clients Manager of clients. | ||
*/ | ||
public class GUIListener(plugin: Plugin) : Listener { | ||
|
||
private val clients: ClientManager by inject(plugin.id) | ||
|
||
/** | ||
* Called when a player clicks on an item in an inventory. | ||
* If the click is detected in a GUI, the event is cancelled and the GUI is notified. | ||
* @param event Event of the click. | ||
*/ | ||
@EventHandler | ||
public suspend fun onInventoryClick(event: InventoryClickEvent) { | ||
if (event.isCancelled) return | ||
val item = event.currentItem ?: return | ||
val player = event.whoClicked | ||
|
||
val client = clients.getClient(player) | ||
val gui = client.gui() ?: return | ||
|
||
// The item in a GUI is not supposed to be moved | ||
event.cancel() | ||
gui.onClick(client, item, event) | ||
} | ||
|
||
/** | ||
* Called when a player closes an inventory. | ||
* If the inventory is a GUI, the GUI is notified that it is closed for this player. | ||
* @param event Event of the close. | ||
*/ | ||
@EventHandler | ||
public suspend fun onInventoryClose(event: InventoryCloseEvent) { | ||
quitOpenedGUI(event.player) | ||
} | ||
|
||
/** | ||
* Called when a player quits the server. | ||
* If the player has a GUI opened, the GUI is notified that it is closed for this player. | ||
* @param event Event of the quit. | ||
*/ | ||
@EventHandler | ||
public suspend fun onPlayerQuit(event: PlayerQuitEvent) { | ||
quitOpenedGUI(event.player) | ||
} | ||
|
||
/** | ||
* Quit the opened GUI for the player. | ||
* @param player Player to quit the GUI for. | ||
*/ | ||
private suspend fun quitOpenedGUI(player: HumanEntity) { | ||
val client = clients.getClientOrNull(player) | ||
val gui = client?.gui() ?: return | ||
// We don't close the inventory because it is closing due to event. | ||
gui.close(client, false) | ||
} | ||
|
||
} |
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
45 changes: 0 additions & 45 deletions
45
src/main/kotlin/com/github/rushyverse/api/listener/GUIListener.kt
This file was deleted.
Oops, something went wrong.
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