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 4102fe9b..12ad07cd 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -193,6 +193,7 @@ public class EcoEnchants { public static final EcoEnchant DIURNAL = new Diurnal(); public static final EcoEnchant MARKING = new Marking(); public static final EcoEnchant CORROSIVE = new Corrosive(); + public static final EcoEnchant WOUND = new Wound(); /** * Get all registered {@link EcoEnchant}s 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 new file mode 100644 index 00000000..2d3fd6a9 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java @@ -0,0 +1,72 @@ +package com.willfp.ecoenchants.enchantments.ecoenchants.normal; + +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.integrations.antigrief.AntigriefManager; +import com.willfp.ecoenchants.nms.Cooldown; +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.scheduler.BukkitRunnable; + +import java.util.concurrent.atomic.AtomicInteger; + +public class Wound extends EcoEnchant { + public Wound() { + super( + new EcoEnchantBuilder("wound", EnchantmentType.NORMAL, Target.Applicable.SWORD, 4.0) + ); + } + + // START OF LISTENERS + + @EventHandler + public void onHit(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Arrow)) + return; + + if(!(((Arrow) event.getDamager()).getShooter() instanceof Player)) + return; + + if (!(event.getEntity() instanceof LivingEntity)) + return; + + Player player = (Player) ((Arrow) event.getDamager()).getShooter(); + + LivingEntity victim = (LivingEntity) event.getEntity(); + + if(!AntigriefManager.canInjure(player, victim)) 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; + + double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage"); + + int bleedCount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "amount-per-level"); + bleedCount *= level; + final int finalBleedCount = bleedCount; + + AtomicInteger currentBleedCount = new AtomicInteger(0); + + new BukkitRunnable() { + @Override + public void run() { + currentBleedCount.addAndGet(1); + + victim.damage(bleedDamage); + + if(currentBleedCount.get() >= finalBleedCount) this.cancel(); + } + }.runTaskTimer(EcoEnchantsPlugin.getInstance(), 0, 10); + } +} diff --git a/Plugin/src/main/resources/enchants/normal/wound.yml b/Plugin/src/main/resources/enchants/normal/wound.yml new file mode 100644 index 00000000..c735f5f7 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/wound.yml @@ -0,0 +1,25 @@ +# +# Wound EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Wound" + +description: Causes your opponent to bleed, damaging them repeatedly. + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 3 + +config: + chance-per-level: 5 #chance of bleeding per level + bleed-damage: 1 + amount-per-level: 2 # Bleed number per level diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 60bb3b24..3d8ed488 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -212,6 +212,7 @@ permissions: ecoenchants.fromtable.diurnal: true ecoenchants.fromtable.marking: true ecoenchants.fromtable.corrosive: true + ecoenchants.fromtable.wound: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -720,4 +721,7 @@ permissions: default: true ecoenchants.fromtable.corrosive: description: Allows getting corrosive from an enchanting table + default: true + ecoenchants.fromtable.wound: + description: Allows getting wound from an enchanting table default: true \ No newline at end of file