9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-03 14:22:17 +00:00

Added check for block being player placed

This commit is contained in:
Auxilor
2021-08-24 14:59:28 +01:00
parent 6d8edcc3c1
commit a7cade9bf6
2 changed files with 43 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
package com.willfp.ecoskills.data
import com.willfp.eco.util.NamespacedKeyUtils
import com.willfp.ecoskills.EcoSkillsPlugin
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.BlockMultiPlaceEvent
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.persistence.PersistentDataType
class PlayerBlockListener(
private val plugin: EcoSkillsPlugin
) : Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun onPlace(event: BlockPlaceEvent) {
val block = event.blockPlaced
writeKey(block)
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun onPlace(event: BlockMultiPlaceEvent) {
val block = event.blockPlaced
writeKey(block)
}
private fun writeKey(block: Block) {
val loc = block.location.hashCode().toString(16)
block.chunk.persistentDataContainer.set(NamespacedKeyUtils.create("ecoskills", loc.lowercase()), PersistentDataType.INTEGER, 1)
}
}
fun Block.isPlayerPlaced(): Boolean {
val chunk = this.chunk
return chunk.persistentDataContainer.has(NamespacedKeyUtils.create("ecoskills", this.location.hashCode().toString(16)), PersistentDataType.INTEGER)
}

View File

@@ -2,13 +2,11 @@ package com.willfp.ecoskills.effects.effects
import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoskills.data.isPlayerPlaced
import com.willfp.ecoskills.effects.Effect
import com.willfp.ecoskills.getEffectLevel
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.data.Ageable
import org.bukkit.enchantments.Enchantment
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.block.BlockBreakEvent
@@ -39,7 +37,9 @@ class EffectSpelunking: Effect(
val player = event.player
if (player.inventory.itemInMainHand.containsEnchantment(Enchantment.SILK_TOUCH)) {
val block = event.block
if (block.isPlayerPlaced()) {
return
}