Added EnchantingTableChanceGenerateEvent

This commit is contained in:
Auxilor 2023-07-12 12:53:38 +01:00
parent ecb9b4e96d
commit aaf68dd7a1
2 changed files with 30 additions and 1 deletions

View File

@ -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
}
}

View File

@ -9,6 +9,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.conflictsWithDeep import com.willfp.ecoenchants.enchants.conflictsWithDeep
import org.bukkit.Bukkit
import org.bukkit.GameMode import org.bukkit.GameMode
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.enchantments.Enchantment import org.bukkit.enchantments.Enchantment
@ -92,7 +93,12 @@ class EnchantingTableSupport(
continue 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 continue
} }