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 c90092fb..4102fe9b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -192,6 +192,7 @@ public class EcoEnchants { public static final EcoEnchant END_INFUSION = new EndInfusion(); public static final EcoEnchant DIURNAL = new Diurnal(); public static final EcoEnchant MARKING = new Marking(); + public static final EcoEnchant CORROSIVE = new Corrosive(); /** * Get all registered {@link EcoEnchant}s diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Corrosive.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Corrosive.java new file mode 100644 index 00000000..d2169ca8 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Corrosive.java @@ -0,0 +1,75 @@ +package com.willfp.ecoenchants.enchantments.ecoenchants.normal; + +import com.comphenix.protocol.PacketType; +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.ItemDurability; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.Arrays; + +public class Corrosive extends EcoEnchant { + public Corrosive() { + super( + new EcoEnchantBuilder("corrosive", EnchantmentType.NORMAL, new Target.Applicable[]{Target.Applicable.BOW, Target.Applicable.CROSSBOW}, 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 Player)) + return; + + if (event.isCancelled()) + return; + + Player player = (Player) ((Arrow) event.getDamager()).getShooter(); + Player victim = (Player) event.getEntity(); + + if(!AntigriefManager.canInjure(player, victim)) return; + + if (!HasEnchant.playerHeld(player, this)) return; + + int level = HasEnchant.getPlayerLevel(player, this); + + ArrayList armor = new ArrayList(Arrays.asList(victim.getInventory().getArmorContents())); + if (armor.isEmpty()) + return; + + for (ItemStack armorPiece : armor) { + if (armorPiece == null) + continue; + + if (Target.Applicable.HELMET.getMaterials().contains(armorPiece.getType())) { + ItemDurability.damageItem(player, player.getInventory().getHelmet(), level, 39); + } + if (Target.Applicable.CHESTPLATE.getMaterials().contains(armorPiece.getType())) { + ItemDurability.damageItem(player, player.getInventory().getChestplate(), level, 38); + } + if (Target.Applicable.LEGGINGS.getMaterials().contains(armorPiece.getType())) { + ItemDurability.damageItem(player, player.getInventory().getLeggings(), level, 37); + } + if (Target.Applicable.BOOTS.getMaterials().contains(armorPiece.getType())) { + ItemDurability.damageItem(player, player.getInventory().getBoots(), level, 36); + } + } + } +} diff --git a/Plugin/src/main/resources/enchants/normal/corrosive.yml b/Plugin/src/main/resources/enchants/normal/corrosive.yml new file mode 100644 index 00000000..2fa640c3 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/corrosive.yml @@ -0,0 +1,23 @@ +# +# Corrosive EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Corrosive" + +description: Damages your opponents armor. + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 2 + +config: + # No config is available for this enchantment \ No newline at end of file diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 8f6c4160..60bb3b24 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -211,6 +211,7 @@ permissions: ecoenchants.fromtable.endinfusion: true ecoenchants.fromtable.diurnal: true ecoenchants.fromtable.marking: true + ecoenchants.fromtable.corrosive: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -716,4 +717,7 @@ permissions: default: true ecoenchants.fromtable.marking: description: Allows getting marking from an enchanting table + default: true + ecoenchants.fromtable.corrosive: + description: Allows getting corrosive from an enchanting table default: true \ No newline at end of file