aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt b/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt
index 02557ab..a60cd06 100644
--- a/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt
+++ b/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt
@@ -18,6 +18,7 @@ data class IsSlotProtectedEvent(
val actionType: SlotActionType,
var isProtected: Boolean,
val itemStackOverride: ItemStack?,
+ var silent: Boolean = false,
) : FirmamentEvent() {
val itemStack get() = itemStackOverride ?: slot!!.stack
@@ -25,18 +26,25 @@ data class IsSlotProtectedEvent(
isProtected = true
}
+ fun protectSilent() {
+ if (!isProtected) {
+ silent = true
+ }
+ isProtected = true
+ }
+
companion object : FirmamentEventBus<IsSlotProtectedEvent>() {
@JvmStatic
@JvmOverloads
fun shouldBlockInteraction(slot: Slot?, action: SlotActionType, itemStackOverride: ItemStack? = null): Boolean {
if (slot == null && itemStackOverride == null) return false
val event = IsSlotProtectedEvent(slot, action, false, itemStackOverride)
- return publish(event).isProtected.also {
- if (it) {
- MC.player?.sendMessage(Text.translatable("firmament.protectitem").append(event.itemStack.name))
- CommonSoundEffects.playFailure()
- }
+ publish(event)
+ if (event.isProtected && !event.silent) {
+ MC.player?.sendMessage(Text.translatable("firmament.protectitem").append(event.itemStack.name))
+ CommonSoundEffects.playFailure()
}
+ return event.isProtected
}
}
}