Discussion in 'Spigot Plugin Development' started by Valon750, May 26, 2016.

Thread Status:
Not open for further replies.
  1. .
    #1 Valon750, May 26, 2016
    Last edited: Nov 10, 2019
  2. If you can't find a direct way to do it (I can't think of any off the top of my head) you can always opt to intercept all damage events and change the damage to a higher value accordingly.
  3. There is 2 ways to remove this. The use of NBTTags which would be long and treacherous, but would be needed if you want to remove the armor bar completely. Or you can just use the entity damage event.

    On the EntityDamageEvent you can just set use #setDamage(EntityDamageEvent.DamageModifier type, double damage)
    to set the Armor damage modifier to 0. Like this:
    Code (Text):
    event.setDamage(DamageModifier.ARMOR, 0);
    And the damage would completely ignore Armor.

    Or we could use NBTTags to set the Toughness value and Armor.

    Here is the armor formula:
    Where A represents how many armor points you have and T represents the armors toughness.
    I left this here because if you were calculating damage reduced by armor its good to understand how its calculated. This formula is why if we set the "generic.armor" value of an itemstack to 0 it does not protect anything.

    Now time for solution #2 Item Attributes:
    Code (Text):
            ItemStack x = new ItemStack(material, amount);
            net.minecraft.server.v1_10_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(x);
            NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
            NBTTagList modifiers = new NBTTagList();
            NBTTagCompound toughness = new NBTTagCompound();
            toughness.set("AttributeName", new NBTTagString("armorToughness"));
            toughness.set("Name", new NBTTagString("armorToughness"));
            toughness.set("Amount", new NBTTagInt(0));
            toughness.set("Operation", new NBTTagInt(0));
            toughness.set("UUIDLeast", new NBTTagInt(894654));
            toughness.set("UUIDMost", new NBTTagInt(2872));
            NBTTagCompound armor = new NBTTagCompound();
            armor.set("AttributeName", new NBTTagString("generic.armor"));
            armor.set("Name", new NBTTagString("generic.armor"));
            armor.set("Amount", new NBTTagInt(0));
            armor.set("Operation", new NBTTagInt(0));
            armor.set("UUIDLeast", new NBTTagInt(894654));
            armor.set("UUIDMost", new NBTTagInt(2872));
            compound.set("AttributeModifiers", modifiers);
            x = CraftItemStack.asBukkitCopy(nmsStack);
            ItemMeta im = x.getItemMeta();
            return x;
    Cool NMS stuff, If you want to know step by step what each part means, https://www.spigotmc.org/threads/tutorial-1-9-the-complete-guide-to-item-nbttags-attributes.131458/
    You can loop through every item in everyones inventory and if its a piece of armor do this. And you will have every piece of armor on the server not protecting anything.

    Don't know if this is a necro since it is only a month old, saw it wasn't really solved so I put my 2cents in.
    • Like Like x 2
Thread Status:
Not open for further replies.