Skip to content

Commit aa25ba4

Browse files
committedFeb 27, 2024
Add a bit of documentation
1 parent cd2025c commit aa25ba4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+271
-125
lines changed
 

‎interfaces/src/main/kotlin/com/noxcrew/interfaces/Constants.kt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger
1010

1111
internal object Constants {
1212

13+
/** The [CoroutineScope] for any suspending operations performed by interfaces. */
1314
internal val SCOPE = CoroutineScope(
1415
CoroutineName("interfaces") +
1516
SupervisorJob() +

‎interfaces/src/main/kotlin/com/noxcrew/interfaces/InterfacesListeners.kt

+9-14
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ import org.bukkit.inventory.EquipmentSlot
3434
import org.bukkit.inventory.InventoryHolder
3535
import org.bukkit.plugin.Plugin
3636
import org.slf4j.LoggerFactory
37-
import java.lang.ref.WeakReference
3837
import java.util.EnumSet
3938
import java.util.UUID
4039
import java.util.concurrent.TimeUnit
4140
import kotlin.time.Duration
4241

42+
/**
43+
* Listens to bukkit events and manages the current state of all interfaces accordingly.
44+
*/
4345
public class InterfacesListeners private constructor(private val plugin: Plugin) : Listener {
4446

4547
public companion object {
@@ -55,39 +57,35 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
5557
println("Installed interfaces listeners")
5658
}
5759

60+
/** All valid closing reasons that should re-open the opened player inventory. */
5861
private val VALID_REASON = EnumSet.of(
5962
Reason.PLAYER,
6063
Reason.UNKNOWN,
6164
Reason.PLUGIN
6265
)
6366

67+
/** All valid interaction types. */
6468
private val VALID_INTERACT = EnumSet.of(
6569
Action.LEFT_CLICK_AIR,
6670
Action.LEFT_CLICK_BLOCK,
6771
Action.RIGHT_CLICK_AIR,
6872
Action.RIGHT_CLICK_BLOCK
6973
)
7074

75+
/** The possible valid slot range inside the player inventory. */
7176
private val PLAYER_INVENTORY_RANGE = 0..40
77+
78+
/** The slot index used to indicate a click was outside the UI. */
7279
private const val OUTSIDE_CHEST_INDEX = -999
7380
}
7481

7582
/** Stores data for a single chat query. */
7683
private data class ChatQuery(
77-
private val playerReference: WeakReference<Player>,
78-
private val openViewReference: WeakReference<PlayerInterfaceView>?,
7984
val view: InterfaceView,
8085
val onCancel: () -> Unit,
8186
val onComplete: (Component) -> Unit,
8287
val id: UUID
83-
) {
84-
85-
val player: Player?
86-
get() = playerReference.get()
87-
88-
val openView: PlayerInterfaceView?
89-
get() = openViewReference?.get()
90-
}
88+
)
9189

9290
private val logger = LoggerFactory.getLogger(InterfacesListeners::class.java)
9391

@@ -341,7 +339,6 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
341339
// Store the current open inventory and remove it from the cache so it does
342340
// not interfere and we can have the player be itemless
343341
val playerId = view.player.uniqueId
344-
val open = openPlayerInterfaceViews.getIfPresent(playerId)
345342
openPlayerInterfaceViews.invalidate(playerId)
346343

347344
runSync {
@@ -357,8 +354,6 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
357354
queries.put(
358355
playerId,
359356
ChatQuery(
360-
WeakReference(view.player),
361-
open?.let { WeakReference(it) },
362357
view,
363358
onCancel,
364359
onComplete,

0 commit comments

Comments
 (0)
Please sign in to comment.