Change max durability and armour value with craftbukkit

Discussion in 'Plugin Development' started by x2nec, Apr 8, 2013.

Thread Status:
Not open for further replies.
  1. Hey, basically I'm trying to change the max durability and armour values of gold using craftbukkit. Below is what I have but it isn't working for me. Could anyone help? Thanks

    Code:
    public class ArmorHook {
       
        private Field armorValueField;
        private Field durabilityValueField;
     
        public ArmorHook() throws SecurityException, NoSuchFieldException, IllegalAccessException {
            armorValueField = ItemArmor.class.getField("c");
            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(armorValueField, armorValueField.getModifiers() & 0xffffffef);
           
            durabilityValueField = ItemArmor.class.getField("d");
            Field modifiersField2 = Field.class.getDeclaredField("modifiers");
            modifiersField2.setAccessible(true);
            modifiersField2.setInt(durabilityValueField, durabilityValueField.getModifiers() & 0xffffffef);
        }
     
        public void modifyArmorValue(int id, int value, int durability) {
            Item i = Item.byId[id];
            if (i instanceof ItemArmor) {
                try {
                    armorValueField.set(i, Integer.valueOf(value));
                    durabilityValueField.set(i, Integer.valueOf(durability));
                }
                catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
                catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            } else {
                throw new IllegalArgumentException();
            }
        }
     
  2. Offline

    Burnsalan18

    Well I dont think its possible to set the MAX of the durability as in change the max value but you can make the durability less or full. Let me look around in my workplace and ill try to find something for you.
     
  3. I know how to do that stuff, I'm looking at changing the craftbukkit code with reflection, as opposed to bukkit API
     
  4. Offline

    Forseth11

    x2nec you could get the current durability or how many hits it has left and if it has like 10 hits add 5 then if five has been added add three then it get to five then add zero.
     
  5. Any suggestions that wouldn't involve manipulation during this? It'd be more fitting to be able to change the definitive values in craftbukkit
     
Thread Status:
Not open for further replies.

Share This Page