Skip to content

Commit

Permalink
Added EnchantingTableChanceGenerateEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jul 12, 2023
1 parent ecb9b4e commit aaf68dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit aaf68dd

Please # to comment.