diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/PlayerBlockListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/PlayerBlockListener.kt index b026ae2..09a149a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/PlayerBlockListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/PlayerBlockListener.kt @@ -6,6 +6,7 @@ import org.bukkit.block.Block import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent import org.bukkit.event.block.BlockMultiPlaceEvent import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.persistence.PersistentDataType @@ -27,10 +28,24 @@ class PlayerBlockListener( writeKey(block) } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + fun onBreak(event: BlockBreakEvent) { + val block = event.block + + this.plugin.scheduler.runLater({ + removeKey(block) + }, 1) + } + private fun writeKey(block: Block) { val loc = block.location.hashCode().toString(16) block.chunk.persistentDataContainer.set(NamespacedKeyUtils.create("ecoskills", loc.lowercase()), PersistentDataType.INTEGER, 1) } + + private fun removeKey(block: Block) { + val loc = block.location.hashCode().toString(16) + block.chunk.persistentDataContainer.remove(NamespacedKeyUtils.create("ecoskills", loc.lowercase())) + } } fun Block.isPlayerPlaced(): Boolean {