@@ -34,12 +34,14 @@ import org.bukkit.inventory.EquipmentSlot
34
34
import org.bukkit.inventory.InventoryHolder
35
35
import org.bukkit.plugin.Plugin
36
36
import org.slf4j.LoggerFactory
37
- import java.lang.ref.WeakReference
38
37
import java.util.EnumSet
39
38
import java.util.UUID
40
39
import java.util.concurrent.TimeUnit
41
40
import kotlin.time.Duration
42
41
42
+ /* *
43
+ * Listens to bukkit events and manages the current state of all interfaces accordingly.
44
+ */
43
45
public class InterfacesListeners private constructor(private val plugin : Plugin ) : Listener {
44
46
45
47
public companion object {
@@ -55,39 +57,35 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
55
57
println (" Installed interfaces listeners" )
56
58
}
57
59
60
+ /* * All valid closing reasons that should re-open the opened player inventory. */
58
61
private val VALID_REASON = EnumSet .of(
59
62
Reason .PLAYER ,
60
63
Reason .UNKNOWN ,
61
64
Reason .PLUGIN
62
65
)
63
66
67
+ /* * All valid interaction types. */
64
68
private val VALID_INTERACT = EnumSet .of(
65
69
Action .LEFT_CLICK_AIR ,
66
70
Action .LEFT_CLICK_BLOCK ,
67
71
Action .RIGHT_CLICK_AIR ,
68
72
Action .RIGHT_CLICK_BLOCK
69
73
)
70
74
75
+ /* * The possible valid slot range inside the player inventory. */
71
76
private val PLAYER_INVENTORY_RANGE = 0 .. 40
77
+
78
+ /* * The slot index used to indicate a click was outside the UI. */
72
79
private const val OUTSIDE_CHEST_INDEX = - 999
73
80
}
74
81
75
82
/* * Stores data for a single chat query. */
76
83
private data class ChatQuery (
77
- private val playerReference : WeakReference <Player >,
78
- private val openViewReference : WeakReference <PlayerInterfaceView >? ,
79
84
val view : InterfaceView ,
80
85
val onCancel : () -> Unit ,
81
86
val onComplete : (Component ) -> Unit ,
82
87
val id : UUID
83
- ) {
84
-
85
- val player: Player ?
86
- get() = playerReference.get()
87
-
88
- val openView: PlayerInterfaceView ?
89
- get() = openViewReference?.get()
90
- }
88
+ )
91
89
92
90
private val logger = LoggerFactory .getLogger(InterfacesListeners ::class .java)
93
91
@@ -341,7 +339,6 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
341
339
// Store the current open inventory and remove it from the cache so it does
342
340
// not interfere and we can have the player be itemless
343
341
val playerId = view.player.uniqueId
344
- val open = openPlayerInterfaceViews.getIfPresent(playerId)
345
342
openPlayerInterfaceViews.invalidate(playerId)
346
343
347
344
runSync {
@@ -357,8 +354,6 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
357
354
queries.put(
358
355
playerId,
359
356
ChatQuery (
360
- WeakReference (view.player),
361
- open?.let { WeakReference (it) },
362
357
view,
363
358
onCancel,
364
359
onComplete,
0 commit comments