-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1658 from Dans-Plugins/bugfix/hoppers
Prevent items from being taken from locked containers by hoppers, closes #1391
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/dansplugins/factionsystem/listener/InventoryMoveItemListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |