aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-10-04 16:41:04 +0200
committernea <nea@nea.moe>2023-10-04 16:41:04 +0200
commit64523821d82d702c0bf2d62bbe45a1047aed8bda (patch)
treefe5f25316ddf1895281a932b8fe468b5bc330975 /src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt
parentd0cc95b1e9a674c41bedc50d1d7923159e2bd6a2 (diff)
downloadFirmament-64523821d82d702c0bf2d62bbe45a1047aed8bda.tar.gz
Firmament-64523821d82d702c0bf2d62bbe45a1047aed8bda.tar.bz2
Firmament-64523821d82d702c0bf2d62bbe45a1047aed8bda.zip
Block selling to NPCs, trading and salvaging UUID locked items
[no changelog]
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
}
}
}