mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-24 15:25:18 +01:00
Added EnchantingTableChanceGenerateEvent
This commit is contained in:
parent
ecb9b4e96d
commit
aaf68dd7a1
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user