diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableChanceGenerateEvent.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableChanceGenerateEvent.kt new file mode 100644 index 00000000..b8131a01 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableChanceGenerateEvent.kt @@ -0,0 +1,23 @@ +package com.willfp.ecoenchants.mechanics + +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.Player +import org.bukkit.event.HandlerList +import org.bukkit.event.player.PlayerEvent +import org.bukkit.inventory.ItemStack + +class EnchantingTableChanceGenerateEvent( + who: Player, + val item: ItemStack, + val enchantment: Enchantment, + var chance: Double +) : PlayerEvent(who) { + override fun getHandlers() = HANDLERS + + companion object { + private val HANDLERS = HandlerList() + + @JvmStatic + fun getHandlerList() = HANDLERS + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt index d1291f09..a7f47236 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt @@ -9,6 +9,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin import com.willfp.ecoenchants.enchants.EcoEnchant import com.willfp.ecoenchants.enchants.EcoEnchants import com.willfp.ecoenchants.enchants.conflictsWithDeep +import org.bukkit.Bukkit import org.bukkit.GameMode import org.bukkit.Material import org.bukkit.enchantments.Enchantment @@ -92,7 +93,12 @@ class EnchantingTableSupport( continue } - if (NumberUtils.randFloat(0.0, 1.0) > enchantment.enchantmentRarity.tableChance * multiplier) { + val baseChance = enchantment.enchantmentRarity.tableChance * multiplier + + val chanceEvent = EnchantingTableChanceGenerateEvent(player, item, enchantment, baseChance) + Bukkit.getPluginManager().callEvent(chanceEvent) + + if (NumberUtils.randFloat(0.0, 1.0) > chanceEvent.chance) { continue }