Skip to content

Commit

Permalink
Merge pull request #1658 from Dans-Plugins/bugfix/hoppers
Browse files Browse the repository at this point in the history
Prevent items from being taken from locked containers by hoppers, closes #1391
  • Loading branch information
dmccoystephenson authored Dec 19, 2022
2 parents 3ed25a8 + 32efe0a commit 08ad5d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ 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
Expand Down Expand Up @@ -266,6 +267,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 08ad5d5

Please sign in to comment.