Skip to content

Commit

Permalink
Prevent hoppers from picking up items from locked chests, closes #1391
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrenic authored and renbinden committed Dec 19, 2022
1 parent 85da277 commit 48a88e0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -230,6 +251,7 @@ class MedievalFactions : JavaPlugin() {
EntityDamageByEntityListener(this),
EntityDamageListener(this),
EntityExplodeListener(this),
InventoryMoveItemListener(this),
LingeringPotionSplashListener(this),
PlayerDeathListener(this),
PlayerInteractListener(this),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 48a88e0

Please sign in to comment.