diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java index df6b7c01..a535a7b9 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.curse; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -19,7 +20,7 @@ public class BreaklessnessCurse extends EcoEnchant { @Override public void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) { - if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance")) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java index 3ea0b87a..191746c2 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.curse; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -18,7 +19,7 @@ public class HarmlessnessCurse extends EcoEnchant { @Override public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance")) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setDamage(0); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java index 9e94fb0e..23129da4 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.curse; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -19,7 +20,7 @@ public class MisfortuneCurse extends EcoEnchant { @Override public void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) { - if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance")) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setDropItems(false); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java index 8d0072f6..4957c92d 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageEvent; @@ -20,8 +21,8 @@ public class Arcanic extends EcoEnchant { if (!(event.getCause().equals(EntityDamageEvent.DamageCause.POISON) || event.getCause().equals(EntityDamageEvent.DamageCause.WITHER))) return; - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + + if(!EnchantmentUtils.passedChance(this, level)) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Beheading.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Beheading.java index 7a25b054..956bb3b3 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Beheading.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Beheading.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.queue.DropQueue; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.Material; @@ -36,8 +37,7 @@ public class Beheading extends EcoEnchant { int level = EnchantChecks.getMainhandLevel(player, this); - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; ItemStack item; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java index cc5b137e..f570d277 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Bleed.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -27,7 +28,7 @@ public class Bleed extends EcoEnchant { if (attacker instanceof Player && Cooldown.getCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) return; - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Blind.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Blind.java index 50567aa6..7dc5c000 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Blind.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Blind.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; @@ -23,7 +24,8 @@ public class Blind extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlockBreather.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlockBreather.java index 1dff326a..6eeff297 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlockBreather.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlockBreather.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageEvent; @@ -22,9 +23,8 @@ public class BlockBreather extends EcoEnchant { if(!event.getCause().equals(EntityDamageEvent.DamageCause.SUFFOCATION)) return; - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Conclude.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Conclude.java index 032a7934..4dac79c8 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Conclude.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Conclude.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Trident; @@ -20,7 +21,8 @@ public class Conclude extends EcoEnchant { @Override public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; double minhealth = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "minimum-health-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java index ea5cbf18..18582459 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -28,7 +29,7 @@ public class Disable extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, level * 10, 5)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java index 055fec21..990b8fa8 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Dullness.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -26,7 +27,8 @@ public class Dullness extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; int durationPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Electroshock.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Electroshock.java index fb2e39a6..4511d5af 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Electroshock.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Electroshock.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.Lightning; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -19,11 +20,10 @@ public class Electroshock extends EcoEnchant { @Override public void onDeflect(Player blocker, LivingEntity attacker, int level, EntityDamageByEntityEvent event) { - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage"); - double finalChance = (chance * level)/100; - if(NumberUtils.randFloat(0, 1) > finalChance) return; + if(!EnchantmentUtils.passedChance(this, level)) + return; Lightning.strike(attacker, damage); } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Evasion.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Evasion.java index 144bafc3..14927bed 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Evasion.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Evasion.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageEvent; @@ -18,9 +19,8 @@ public class Evasion extends EcoEnchant { @Override public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) { - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Extinguishing.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Extinguishing.java index 21dd517b..c8bb0ca4 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Extinguishing.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Extinguishing.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageEvent; @@ -20,8 +21,8 @@ public class Extinguishing extends EcoEnchant { if(!event.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK)) return; - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + + if(!EnchantmentUtils.passedChance(this, level)) return; victim.setFireTicks(0); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java index a03e94f8..7893bf66 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Famine.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -27,7 +28,8 @@ public class Famine extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; victim.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, level * 40, level)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finality.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finality.java index ed58fe74..9f74047f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finality.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finality.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; @@ -20,7 +21,8 @@ public class Finality extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; double minhealth = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "minimum-health-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finishing.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finishing.java index 09f80ec8..19f929d7 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finishing.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Finishing.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -18,7 +19,8 @@ public class Finishing extends EcoEnchant { @Override public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; double minhealth = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "minimum-health-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Flinch.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Flinch.java index 73aa7077..287b9553 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Flinch.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Flinch.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -21,11 +22,10 @@ public class Flinch extends EcoEnchant { @Override public void onDeflect(Player blocker, LivingEntity attacker, int level, EntityDamageByEntityEvent event) { - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); - double finalChance = (chance * level)/100; - if(NumberUtils.randFloat(0, 1) > finalChance) return; + if(!EnchantmentUtils.passedChance(this, level)) + return; int finalDuration = duration * level; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Freerunner.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Freerunner.java index 48cf1ffb..ebb0b3f6 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Freerunner.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Freerunner.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageEvent; @@ -18,9 +19,8 @@ public class Freerunner extends EcoEnchant { @Override public void onFallDamage(LivingEntity faller, int level, EntityDamageEvent event) { - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java index 0c5f958e..f02af29c 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Frozen.java @@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; @@ -38,7 +39,8 @@ public class Frozen extends EcoEnchant { if (points == 0) return; - if (NumberUtils.randFloat(0, 1) > points * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point")) + + if(!EnchantmentUtils.passedChance(this, points)) return; int divisor = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "points-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java index 3cf3dc36..5acc7a8b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Fury.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import com.willfp.ecoenchants.util.VectorUtils; @@ -25,7 +26,8 @@ public class Fury extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; double distancePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java index 0fbc03c5..cd33ce0d 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -36,7 +37,8 @@ public class Graceful extends EcoEnchant { if(!EnchantChecks.boots(player, this)) return; int level = EnchantChecks.getBootsLevel(player, this); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 5, false, false, true)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IceShot.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IceShot.java index 72f339f8..fcccadab 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IceShot.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IceShot.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; @@ -22,7 +23,8 @@ public class IceShot extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; victim.setVelocity(new Vector(0, 0, 0)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Identify.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Identify.java index 1db32296..63664b24 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Identify.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Identify.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -22,11 +23,10 @@ public class Identify extends EcoEnchant { @Override public void onDeflect(Player blocker, LivingEntity attacker, int level, EntityDamageByEntityEvent event) { - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); - double finalChance = (chance * level)/100; - if(NumberUtils.randFloat(0, 1) > finalChance) return; + if(!EnchantmentUtils.passedChance(this, level)) + return; int finalDuration = duration * level; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Ignite.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Ignite.java index a4e92d23..2e34659c 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Ignite.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Ignite.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.Material; @@ -33,7 +34,8 @@ public class Ignite extends EcoEnchant { if (!AntigriefManager.canBreakBlock(shooter, event.getHitBlock())) return; - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; BlockFace face = event.getHitBlockFace(); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java index bf220b75..46997e0e 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/IllusionAspect.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -27,8 +28,8 @@ public class IllusionAspect extends EcoEnchant { return; } - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + + if(!EnchantmentUtils.passedChance(this, level)) return; victim.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, level * 10 + 15, level)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Impact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Impact.java index 21254544..573cac54 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Impact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Impact.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Trident; @@ -20,7 +21,8 @@ public class Impact extends EcoEnchant { @Override public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + + if(!EnchantmentUtils.passedChance(this, level)) return; event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier")); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Infuriate.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Infuriate.java index d15d78ad..00a553ea 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Infuriate.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Infuriate.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import com.willfp.ecoenchants.util.VectorUtils; import org.bukkit.entity.*; @@ -21,9 +22,8 @@ public class Infuriate extends EcoEnchant { @Override public void onDeflect(Player blocker, LivingEntity attacker, int level, EntityDamageByEntityEvent event) { - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - double finalChance = (chance * level)/100; - if(NumberUtils.randFloat(0, 1) > finalChance) return; + if(!EnchantmentUtils.passedChance(this, level)) + return; double distancePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level"); final double distance = distancePerLevel * level; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Instantaneous.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Instantaneous.java index 3d6a8e97..fe04bfb8 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Instantaneous.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Instantaneous.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.integrations.anticheat.AnticheatManager; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.block.Block; @@ -20,7 +21,7 @@ public class Instantaneous extends EcoEnchant { @Override public void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; AnticheatManager.exemptPlayer(player); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java index e7aa71c8..f2c98f58 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Lesion.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Trident; @@ -24,7 +25,7 @@ public class Lesion extends EcoEnchant { @Override public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Levitate.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Levitate.java index fd2e0cea..fa9629d4 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Levitate.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Levitate.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; @@ -22,7 +23,7 @@ public class Levitate extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Necrotic.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Necrotic.java index 7747d5b0..54968303 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Necrotic.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Necrotic.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.queue.DropQueue; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.Material; @@ -35,8 +36,7 @@ public class Necrotic extends EcoEnchant { int level = EnchantChecks.getMainhandLevel(player, this); - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; ItemStack item = new ItemStack(Material.WITHER_SKELETON_SKULL, 1); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Paralyze.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Paralyze.java index a68a7c09..e63494a1 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Paralyze.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Paralyze.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -22,11 +23,10 @@ public class Paralyze extends EcoEnchant { @Override public void onDeflect(Player blocker, LivingEntity attacker, int level, EntityDamageByEntityEvent event) { - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); - double finalChance = (chance * level)/100; - if(NumberUtils.randFloat(0, 1) > finalChance) return; + if(!EnchantmentUtils.passedChance(this, level)) + return; int finalDuration = duration * level; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rage.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rage.java index 900bc913..8ce74ac7 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rage.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rage.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import com.willfp.ecoenchants.util.VectorUtils; import org.bukkit.entity.*; @@ -21,7 +22,7 @@ public class Rage extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; double distancePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sating.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sating.java index 892beb13..9a20cf69 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sating.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sating.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -29,9 +30,7 @@ public class Sating extends EcoEnchant { int level = EnchantChecks.getHelmetLevel(player, this); - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java index 9923a084..2f5bd84d 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; @@ -23,7 +24,7 @@ public class Sickening extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java index 79d79ff0..7cdfb640 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.TridentStack; import com.willfp.ecoenchants.queue.DropQueue; import com.willfp.ecoenchants.util.NumberUtils; @@ -50,9 +51,8 @@ public class Spearfishing extends EcoEnchant { if (!EnchantChecks.item(item, this)) return; int level = EnchantChecks.getItemLevel(item, this); - - double chance = level * (this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")/100); - if(NumberUtils.randFloat(0, 1) > chance) return; + if(!EnchantmentUtils.passedChance(this, level)) + return; List potentialDrops = new ArrayList<>(); this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "drops").forEach(material -> { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java index a1ec710c..9df3e4ee 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -30,10 +31,7 @@ public class Stamina extends EcoEnchant { if(event.getFoodLevel() > player.getFoodLevel()) return; int level = EnchantChecks.getBootsLevel(player, this); - - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java index 6adf1c00..d66c45c3 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.queue.DropQueue; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.GameMode; @@ -27,10 +28,7 @@ public class StoneSwitcher extends EcoEnchant { return; if(!block.getType().equals(Material.STONE)) return; - - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - - if(NumberUtils.randFloat(0, 1) > level * chance * 0.01) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setDropItems(false); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java index 632f5faa..fa793ada 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -26,8 +27,7 @@ public class StrayAspect extends EcoEnchant { if (Cooldown.getCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) return; } - - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, level * 10, level)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java index 8ce00806..e2721ce7 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -25,7 +26,7 @@ public class Supercritical extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier")); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java index d27e51a0..3c541154 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.Lightning; import com.willfp.ecoenchants.util.NumberUtils; @@ -26,7 +27,7 @@ public class Thor extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "lightning-damage"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java index d2b291c2..66c090be 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -27,7 +28,7 @@ public class Toxic extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; victim.addPotionEffect(new PotionEffect(PotionEffectType.POISON, level * 10 + 20, level)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java index 42090c0a..a01c60bb 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.queue.DropQueue; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.GameMode; @@ -27,9 +28,7 @@ public class Transfuse extends EcoEnchant { if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) return; - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - - if(NumberUtils.randFloat(0, 1) > level * chance * 0.01) + if(!EnchantmentUtils.passedChance(this, level)) return; event.setDropItems(false); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java index 1a1b7c44..dcb5d66a 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; @@ -30,33 +31,7 @@ public class VampireAspect extends EcoEnchant { return; } - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) - return; - - victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, level * 10 + 20, level)); - } - - @EventHandler - public void vampireAspectHit(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player)) - return; - - if (!(event.getEntity() instanceof LivingEntity)) - return; - - Player player = (Player) event.getDamager(); - - LivingEntity victim = (LivingEntity) event.getEntity(); - - if(!AntigriefManager.canInjure(player, victim)) return; - - if (!EnchantChecks.mainhand(player, this)) return; - - if (Cooldown.getCooldown(player) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) - return; - - int level = EnchantChecks.getMainhandLevel(player, this); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, level * 10 + 20, level)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java index d14b1b3d..df84c72e 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; @@ -21,7 +22,7 @@ public class Venom extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, level * 10 + 20, level)); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java index b549f8c7..f2018f48 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java @@ -4,6 +4,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; @@ -24,7 +25,7 @@ public class Wound extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java index 889cbeef..059bb11d 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.util.Lightning; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Arrow; @@ -20,7 +21,7 @@ public class Zeus extends EcoEnchant { @Override public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "lightning-damage"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java index 8e563f13..2f542543 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Bolt.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.Lightning; import com.willfp.ecoenchants.util.NumberUtils; @@ -25,8 +26,7 @@ public class Bolt extends EcoEnchant { if (Cooldown.getCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) return; } - - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "lightning-damage"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java index b95876dd..acef17d3 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Confusion.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.LivingEntity; @@ -32,9 +33,7 @@ public class Confusion extends EcoEnchant { if (Cooldown.getCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) return; } - - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); - if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) + if(!EnchantmentUtils.passedChance(this, level)) return; List hotbar = new ArrayList(); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java index 4ac7594a..8be681fd 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.NumberUtils; @@ -28,8 +29,7 @@ public class Volatile extends EcoEnchant { if (Cooldown.getCooldown(attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) return; - - if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + if(!EnchantmentUtils.passedChance(this, level)) return; boolean fire = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantmentUtils.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantmentUtils.java new file mode 100644 index 00000000..b111d864 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantmentUtils.java @@ -0,0 +1,19 @@ +package com.willfp.ecoenchants.enchantments.util; + +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.util.NumberUtils; + +public class EnchantmentUtils { + public static double getDamageMultiplier(EcoEnchant enchantment, int level) { + return 1 + ((enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier") * level)/ 100); + } + + public static boolean passedChance(EcoEnchant enchantment, int level) { + return NumberUtils.randFloat(0, 1) < ((enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level") * level) / 100); + } + + public static double getDamageBonus(EcoEnchant enchant, int level) { + return (level * enchant.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level")); + } +} diff --git a/Plugin/src/main/resources/enchants/curse/breaklessnesscurse.yml b/Plugin/src/main/resources/enchants/curse/breaklessnesscurse.yml index 1d32cf11..54c24948 100644 --- a/Plugin/src/main/resources/enchants/curse/breaklessnesscurse.yml +++ b/Plugin/src/main/resources/enchants/curse/breaklessnesscurse.yml @@ -24,4 +24,4 @@ general-config: conflicts: [] config: - chance: 15 \ No newline at end of file + chance-per-level: 15 \ No newline at end of file diff --git a/Plugin/src/main/resources/enchants/curse/harmlessnesscurse.yml b/Plugin/src/main/resources/enchants/curse/harmlessnesscurse.yml index 0519b585..bc7d806c 100644 --- a/Plugin/src/main/resources/enchants/curse/harmlessnesscurse.yml +++ b/Plugin/src/main/resources/enchants/curse/harmlessnesscurse.yml @@ -22,4 +22,4 @@ general-config: conflicts: [] config: - chance: 15 \ No newline at end of file + chance-per-level: 15 \ No newline at end of file diff --git a/Plugin/src/main/resources/enchants/curse/misfortunecurse.yml b/Plugin/src/main/resources/enchants/curse/misfortunecurse.yml index e4676a27..21ec676e 100644 --- a/Plugin/src/main/resources/enchants/curse/misfortunecurse.yml +++ b/Plugin/src/main/resources/enchants/curse/misfortunecurse.yml @@ -25,4 +25,4 @@ general-config: - fortune config: - chance: 15 \ No newline at end of file + chance-per-level: 15 \ No newline at end of file diff --git a/Plugin/src/main/resources/enchants/normal/arcanic.yml b/Plugin/src/main/resources/enchants/normal/arcanic.yml index e0b8ecba..278a8164 100644 --- a/Plugin/src/main/resources/enchants/normal/arcanic.yml +++ b/Plugin/src/main/resources/enchants/normal/arcanic.yml @@ -25,4 +25,4 @@ general-config: maximum-level: 6 config: - chance-per-point: 2 #Chance of ignoring potion damage = Total points (16 points * 3 chance = 48% chance) \ No newline at end of file + chance-per-level: 2 #Chance of ignoring potion damage = Total points (16 points * 3 chance = 48% chance) \ No newline at end of file diff --git a/Plugin/src/main/resources/enchants/normal/evasion.yml b/Plugin/src/main/resources/enchants/normal/evasion.yml index ffe5ecff..46e6fbc7 100644 --- a/Plugin/src/main/resources/enchants/normal/evasion.yml +++ b/Plugin/src/main/resources/enchants/normal/evasion.yml @@ -26,4 +26,4 @@ general-config: config: # Each level of evasion on each piece of armor counts as a point, so if a player is wearing 4 pieces of armor all with Evasion 3, then that would be 12 points - chance-per-point: 0.5 \ No newline at end of file + chance-per-level: 0.5 \ No newline at end of file diff --git a/Plugin/src/main/resources/enchants/normal/extinguishing.yml b/Plugin/src/main/resources/enchants/normal/extinguishing.yml index b0bc8d16..b4bf5c99 100644 --- a/Plugin/src/main/resources/enchants/normal/extinguishing.yml +++ b/Plugin/src/main/resources/enchants/normal/extinguishing.yml @@ -25,4 +25,4 @@ general-config: maximum-level: 3 config: - chance-per-point: 4 #Chance of being extinguished = Total points (12 points * 4 chance = 48% chance) \ No newline at end of file + chance-per-level: 4 #Chance of being extinguished = Total points (12 points * 4 chance = 48% chance) \ No newline at end of file diff --git a/Plugin/src/main/resources/enchants/normal/frozen.yml b/Plugin/src/main/resources/enchants/normal/frozen.yml index 93a2dcec..cfdbb846 100644 --- a/Plugin/src/main/resources/enchants/normal/frozen.yml +++ b/Plugin/src/main/resources/enchants/normal/frozen.yml @@ -25,5 +25,5 @@ general-config: maximum-level: 6 config: - chance-per-point: 0.6 + chance-per-level: 0.6 points-per-level: 6 # Points of frozen required to increment slowness level by 1