diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index 767a481e..c06ac0e5 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -214,6 +214,7 @@ public class EcoEnchants { public static final EcoEnchant ARACHNID = new Arachnid(); public static final EcoEnchant PACIFY = new Pacify(); public static final EcoEnchant ABATTOIR = new Abattoir(); + public static final EcoEnchant DISABLE = new Disable(); /** * Get all registered {@link EcoEnchant}s 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 new file mode 100644 index 00000000..47b989e0 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Disable.java @@ -0,0 +1,52 @@ +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.checks.EnchantChecks; +import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; +import com.willfp.ecoenchants.nms.Cooldown; +import com.willfp.ecoenchants.nms.Target; +import com.willfp.ecoenchants.util.Rand; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Disable extends EcoEnchant { + public Disable() { + super( + new EcoEnchantBuilder("disable", EnchantmentType.NORMAL, Target.Applicable.AXE, 4.0) + ); + } + + // START OF LISTENERS + + @EventHandler + public void onHit(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 (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + return; + + victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, level * 10, 5)); + } +} diff --git a/Plugin/src/main/resources/enchants/normal/disable.yml b/Plugin/src/main/resources/enchants/normal/disable.yml new file mode 100644 index 00000000..8c3c3908 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/disable.yml @@ -0,0 +1,24 @@ +# +# Disable EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Disable" + +description: Chance of giving your opponent extreme mining fatigue. + +obtaining: + table: true + villager: true + loot: true + rarity: epic + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 3 + +config: + allow-not-fully-charged: false #require attack to be at full charge + chance-per-level: 2 #as percentage \ No newline at end of file diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index c483d754..337ba4df 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -233,6 +233,7 @@ permissions: ecoenchants.fromtable.arachnid: true ecoenchants.fromtable.pacify: true ecoenchants.fromtable.abattoir: true + ecoenchants.fromtable.disable: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -804,4 +805,7 @@ permissions: default: true ecoenchants.fromtable.abattoir: description: Allows getting abattoir from an enchanting table + default: true + ecoenchants.fromtable.disable: + description: Allows getting disable from an enchanting table default: true \ No newline at end of file