diff --git a/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt b/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt index c7be600f..cb1f14d4 100644 --- a/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt +++ b/src/main/kotlin/com/dansplugins/factionsystem/MedievalFactions.kt @@ -31,7 +31,28 @@ import com.dansplugins.factionsystem.law.JooqMfLawRepository import com.dansplugins.factionsystem.law.MfLawRepository import com.dansplugins.factionsystem.law.MfLawService import com.dansplugins.factionsystem.legacy.MfLegacyDataMigrator -import com.dansplugins.factionsystem.listener.* +import com.dansplugins.factionsystem.listener.AreaEffectCloudApplyListener +import com.dansplugins.factionsystem.listener.AsyncPlayerChatListener +import com.dansplugins.factionsystem.listener.AsyncPlayerChatPreviewListener +import com.dansplugins.factionsystem.listener.AsyncPlayerPreLoginListener +import com.dansplugins.factionsystem.listener.BlockBreakListener +import com.dansplugins.factionsystem.listener.BlockExplodeListener +import com.dansplugins.factionsystem.listener.BlockPistonExtendListener +import com.dansplugins.factionsystem.listener.BlockPistonRetractListener +import com.dansplugins.factionsystem.listener.BlockPlaceListener +import com.dansplugins.factionsystem.listener.CreatureSpawnListener +import com.dansplugins.factionsystem.listener.EntityDamageByEntityListener +import com.dansplugins.factionsystem.listener.EntityDamageListener +import com.dansplugins.factionsystem.listener.EntityExplodeListener +import com.dansplugins.factionsystem.listener.InventoryMoveItemListener +import com.dansplugins.factionsystem.listener.LingeringPotionSplashListener +import com.dansplugins.factionsystem.listener.PlayerDeathListener +import com.dansplugins.factionsystem.listener.PlayerInteractListener +import com.dansplugins.factionsystem.listener.PlayerJoinListener +import com.dansplugins.factionsystem.listener.PlayerMoveListener +import com.dansplugins.factionsystem.listener.PlayerQuitListener +import com.dansplugins.factionsystem.listener.PlayerTeleportListener +import com.dansplugins.factionsystem.listener.PotionSplashListener import com.dansplugins.factionsystem.locks.JooqMfLockRepository import com.dansplugins.factionsystem.locks.MfLockRepository import com.dansplugins.factionsystem.locks.MfLockService @@ -230,6 +251,7 @@ class MedievalFactions : JavaPlugin() { EntityDamageByEntityListener(this), EntityDamageListener(this), EntityExplodeListener(this), + InventoryMoveItemListener(this), LingeringPotionSplashListener(this), PlayerDeathListener(this), PlayerInteractListener(this), diff --git a/src/main/kotlin/com/dansplugins/factionsystem/listener/InventoryMoveItemListener.kt b/src/main/kotlin/com/dansplugins/factionsystem/listener/InventoryMoveItemListener.kt new file mode 100644 index 00000000..77a38b0b --- /dev/null +++ b/src/main/kotlin/com/dansplugins/factionsystem/listener/InventoryMoveItemListener.kt @@ -0,0 +1,24 @@ +package com.dansplugins.factionsystem.listener + +import com.dansplugins.factionsystem.MedievalFactions +import com.dansplugins.factionsystem.area.MfBlockPosition +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.inventory.InventoryMoveItemEvent +import org.bukkit.inventory.BlockInventoryHolder + +class InventoryMoveItemListener(private val plugin: MedievalFactions) : Listener { + + @EventHandler + fun onInventoryMoveItem(event: InventoryMoveItemEvent) { + // Stop hoppers from taking items from locked blocks. + val sourceInventoryHolder = event.source.holder + if (sourceInventoryHolder !is BlockInventoryHolder) return + val lockService = plugin.services.lockService + val lockedBlock = lockService.getLockedBlock(MfBlockPosition.fromBukkitBlock(sourceInventoryHolder.block)) + if (lockedBlock != null) { + event.isCancelled = true + return + } + } +}