From 64523821d82d702c0bf2d62bbe45a1047aed8bda Mon Sep 17 00:00:00 2001 From: nea Date: Wed, 4 Oct 2023 16:41:04 +0200 Subject: Block selling to NPCs, trading and salvaging UUID locked items [no changelog] --- .../moe/nea/firmament/events/IsSlotProtectedEvent.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt') 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() { @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 } } } -- cgit