Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gk0Wk committed Aug 27, 2023
1 parent bb54456 commit ad8dc87
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ idea {

val targetJavaVersion = 8

version = "2.1.5"
version = "2.1.6"
group = "city.newnan.violet"
description = "Useful toolkits java library for Bukkit Server Plugin."

Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/city/newnan/violet/gui/GuiManager.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package city.newnan.violet.gui

import me.lucko.helper.Events
import me.lucko.helper.event.filter.EventFilters
import me.lucko.helper.terminable.Terminable
import me.lucko.helper.terminable.TerminableConsumer
import org.bukkit.entity.Player
import org.bukkit.event.EventPriority
import org.bukkit.event.inventory.InventoryInteractEvent
import org.bukkit.event.player.AsyncPlayerChatEvent
import org.bukkit.event.player.PlayerQuitEvent
import org.bukkit.plugin.Plugin
Expand All @@ -23,6 +25,14 @@ class GuiManager(private val plugin: Plugin) : Terminable {
catch (e: Exception) { e.printStackTrace() }
} }
.also { if (plugin is TerminableConsumer) it.bindWith(plugin) }
Events.subscribe(InventoryInteractEvent::class.java, EventPriority.MONITOR)
.filter(EventFilters.ignoreCancelled())
.filter { it.whoClicked !is Player }
.handler {
playerSessions[it.whoClicked as Player]?.current?.also { gui ->
if (gui.inventory != it.inventory) return@handler
}
}
}

override fun close() {
Expand Down
27 changes: 19 additions & 8 deletions src/main/kotlin/city/newnan/violet/gui/PlayerGuiSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.bukkit.entity.Player

class PlayerGuiSession(val player: Player) {
var chatInputHandlers: ((input: String) -> Boolean)? = null
val history = ArrayDeque<Triple<BaseGui, UpdateHandler<BaseGui>?, CloseHandler<BaseGui>?>>()
var history = ArrayDeque<Triple<BaseGui, UpdateHandler<BaseGui>?, CloseHandler<BaseGui>?>>()
val length
get() = history.size

Expand Down Expand Up @@ -100,15 +100,26 @@ class PlayerGuiSession(val player: Player) {
}
}

@Synchronized
fun clear() {
current?.inventory?.viewers?.forEach { viewer ->
viewer.closeInventory()
}
while (history.isNotEmpty()) {
val (gui, _, close) = history.removeLast()
close?.invoke(CloseType.Hide, gui, this)
}
val oldHistory = history
history = ArrayDeque()
chatInputHandlers = null
try {
oldHistory.lastOrNull()?.first?.inventory?.viewers?.forEach { viewer ->
viewer.closeInventory()
}
while (oldHistory.isNotEmpty()) {
val (gui, _, close) = oldHistory.removeLast()
try {
close?.invoke(CloseType.Hide, gui, this)
} catch (e: Exception) {
e.printStackTrace()
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}

/**
Expand Down

0 comments on commit ad8dc87

Please sign in to comment.