From d6096789d7be8f70bcde7e9f5cbedb59dbddabf4 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 1 Oct 2021 09:09:58 +0100 Subject: [PATCH] Fixed Master Lumberjack and Bountiful Harvest --- .../effects/effects/EffectBountifulHarvest.kt | 48 +++++++++++++------ .../effects/effects/EffectMasterLumberjack.kt | 33 ++++++------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectBountifulHarvest.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectBountifulHarvest.kt index 507f20b..db5510d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectBountifulHarvest.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectBountifulHarvest.kt @@ -4,6 +4,7 @@ import com.willfp.eco.core.drops.DropQueue import com.willfp.eco.util.NumberUtils 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 @@ -16,6 +17,7 @@ class EffectBountifulHarvest : Effect( "bountiful_harvest" ) { private val blockMap = mutableMapOf() + private val noRepeat = mutableListOf() override fun formatDescription(string: String, level: Int): String { return string.replace("%chance%", NumberUtils.format(this.getChance(level))) @@ -31,13 +33,18 @@ class EffectBountifulHarvest : Effect( } } - @EventHandler(ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) fun handle(event: BlockDropItemEvent) { + if (noRepeat.contains(event)) { + return + } + val mat = blockMap[event.block.location] ?: return - val block = event.block val player = event.player + val block = event.block + val data = block.blockData if (data !is Ageable) { @@ -52,7 +59,7 @@ class EffectBountifulHarvest : Effect( return } - if (event.items.isEmpty()) { + if (!config.getStrings("on-blocks").contains(mat.name.lowercase())) { return } @@ -60,21 +67,34 @@ class EffectBountifulHarvest : Effect( val chance = getChance(level) - val multiplier = getMultiplier(level) + var bonus = getMultiplier(level) - 2 - if (multiplier >= 2) { - for (i in 2 until multiplier) { - DropQueue(player) - .addItems(*event.items.map { item -> item.itemStack }) - .push() - } + if (bonus <= 0) { + return } if (NumberUtils.randFloat(0.0, 100.0) < chance) { - DropQueue(player) - .addItems(*event.items.map { item -> item.itemStack }) - .push() + bonus++ } + + val dropEvent = BlockDropItemEvent(block, block.state, player, event.items.map { + it.itemStack = it.itemStack.apply { + this.amount *= bonus + } + it + }) + + noRepeat.add(dropEvent) + + Bukkit.getPluginManager().callEvent(dropEvent) + + if (dropEvent.items.isEmpty() || dropEvent.isCancelled) { + return + } + + DropQueue(player) + .addItems(*dropEvent.items.map { it.itemStack }) + .push() } private fun getMultiplier(level: Int): Int { @@ -92,7 +112,7 @@ class EffectBountifulHarvest : Effect( private fun getChance(level: Int): Double { var chance = config.getDouble("chance-per-level") * level - chance -= (getMultiplier(level) - 2) * 100 + chance -= ((getMultiplier(level) - 2) * 100) if (chance == 0.0) { chance = 100.0 } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectMasterLumberjack.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectMasterLumberjack.kt index 97549fc..4fccf23 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectMasterLumberjack.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectMasterLumberjack.kt @@ -57,33 +57,34 @@ class EffectMasterLumberjack : Effect( val chance = getChance(level) - val multiplier = getMultiplier(level) + var bonus = getMultiplier(level) - 2 - if (multiplier == 1) { + if (bonus <= 0) { return } - val dropEvent = BlockDropItemEvent(block, block.state, player, event.items) + if (NumberUtils.randFloat(0.0, 100.0) < chance) { + bonus++ + } + + val dropEvent = BlockDropItemEvent(block, block.state, player, event.items.map { + it.itemStack = it.itemStack.apply { + this.amount *= bonus + } + it + }) + noRepeat.add(dropEvent) + Bukkit.getPluginManager().callEvent(dropEvent) if (dropEvent.items.isEmpty() || dropEvent.isCancelled) { return } - if (multiplier > 2) { - for (i in 2 until multiplier) { - DropQueue(player) - .addItems(*dropEvent.items.map { item -> item.itemStack }) - .push() - } - } - - if (NumberUtils.randFloat(0.0, 100.0) < chance) { - DropQueue(player) - .addItems(*dropEvent.items.map { item -> item.itemStack }) - .push() - } + DropQueue(player) + .addItems(*dropEvent.items.map { it.itemStack }) + .push() } private fun getMultiplier(level: Int): Int {