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 7522519e..3f8fdd29 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -195,6 +195,8 @@ public class EcoEnchants { public static final EcoEnchant CORROSIVE = new Corrosive(); public static final EcoEnchant WOUND = new Wound(); public static final EcoEnchant FINALITY = new Finality(); + public static final EcoEnchant BLIND = new Blind(); + public static final EcoEnchant SICKENING = new Sickening(); /** * Get all registered {@link EcoEnchant}s 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 new file mode 100644 index 00000000..7ac52b17 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Blind.java @@ -0,0 +1,57 @@ +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.integrations.antigrief.AntigriefManager; +import com.willfp.ecoenchants.nms.Target; +import com.willfp.ecoenchants.util.HasEnchant; +import com.willfp.ecoenchants.util.Rand; +import org.bukkit.entity.Arrow; +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; +import org.bukkit.util.Vector; + +public class Blind extends EcoEnchant { + public Blind() { + super( + new EcoEnchantBuilder("blind", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.CROSSBOW, Target.Applicable.BOW}, 4.0) + ); + } + + // START OF LISTENERS + + @EventHandler + public void onHit(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Arrow)) + return; + if (!(event.getEntity() instanceof LivingEntity)) + return; + if(!(((Arrow) event.getDamager()).getShooter() instanceof Player)) + return; + + Player player = (Player) ((Arrow) event.getDamager()).getShooter(); + + LivingEntity victim = (LivingEntity) event.getEntity(); + + if(!AntigriefManager.canInjure(player, victim)) return; + + if(event.isCancelled()) return; + + if (!HasEnchant.playerHeld(player, this)) return; + + int level = HasEnchant.getPlayerLevel(player, this); + + if (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + return; + + int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); + + victim.setVelocity(new Vector(0, 0, 0)); + victim.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration * level, level)); + } +} 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 new file mode 100644 index 00000000..09d2af5a --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java @@ -0,0 +1,57 @@ +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.integrations.antigrief.AntigriefManager; +import com.willfp.ecoenchants.nms.Target; +import com.willfp.ecoenchants.util.HasEnchant; +import com.willfp.ecoenchants.util.Rand; +import org.bukkit.entity.Arrow; +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; +import org.bukkit.util.Vector; + +public class Sickening extends EcoEnchant { + public Sickening() { + super( + new EcoEnchantBuilder("sickening", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.CROSSBOW, Target.Applicable.BOW}, 4.0) + ); + } + + // START OF LISTENERS + + @EventHandler + public void onHit(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Arrow)) + return; + if (!(event.getEntity() instanceof LivingEntity)) + return; + if(!(((Arrow) event.getDamager()).getShooter() instanceof Player)) + return; + + Player player = (Player) ((Arrow) event.getDamager()).getShooter(); + + LivingEntity victim = (LivingEntity) event.getEntity(); + + if(!AntigriefManager.canInjure(player, victim)) return; + + if(event.isCancelled()) return; + + if (!HasEnchant.playerHeld(player, this)) return; + + int level = HasEnchant.getPlayerLevel(player, this); + + if (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + return; + + int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); + + victim.setVelocity(new Vector(0, 0, 0)); + victim.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, duration * level, level)); + } +} diff --git a/Plugin/src/main/resources/enchants/normal/blind.yml b/Plugin/src/main/resources/enchants/normal/blind.yml new file mode 100644 index 00000000..b94e9ef9 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/blind.yml @@ -0,0 +1,24 @@ +# +# Blind EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Blind" + +description: Chance of blinding your opponent. + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 2 + +config: + chance-per-level: 3 #as percentage + duration-per-level: 30 \ No newline at end of file diff --git a/Plugin/src/main/resources/enchants/normal/sickening.yml b/Plugin/src/main/resources/enchants/normal/sickening.yml new file mode 100644 index 00000000..f284e190 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/sickening.yml @@ -0,0 +1,24 @@ +# +# Sickening EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Sickening" + +description: Chance of nauseating your opponent. + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 2 + +config: + chance-per-level: 3 #as percentage + duration-per-level: 30 \ No newline at end of file diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 52069dc0..de157581 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -214,6 +214,8 @@ permissions: ecoenchants.fromtable.corrosive: true ecoenchants.fromtable.wound: true ecoenchants.fromtable.finality: true + ecoenchants.fromtable.sickening: true + ecoenchants.fromtable.blind: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -728,4 +730,10 @@ permissions: default: true ecoenchants.fromtable.finality: description: Allows getting finality from an enchanting table + default: true + ecoenchants.fromtable.blind: + description: Allows getting blind from an enchanting table + default: true + ecoenchants.fromtable.sickening: + description: Allows getting sickening from an enchanting table default: true \ No newline at end of file