Added Corrosive

This commit is contained in:
Auxilor 2020-08-29 14:09:29 +01:00
parent aae45e98d5
commit bc994608fb
4 changed files with 103 additions and 0 deletions

View File

@ -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

View File

@ -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<ItemStack> armor = new ArrayList<ItemStack>(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);
}
}
}
}

View File

@ -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

View File

@ -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