Testing for partial armor

Discussion in 'Plugin Development' started by xlr20ice, Nov 25, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    xlr20ice

    I want to test for players wearing armor as defined in a config.

    Here is the code involved:

    Code:
        public boolean isProtected(PlayerInventory inv, String condition) //"condition" is the header of the section containing "Protection_Required"
        {
            ItemStack helmet=getConfig().getItemStack(condition+".Protection_Required.helmet");
            ItemStack chestplate=getConfig().getItemStack(condition+".Protection_Required.chestplate");
            ItemStack legs=getConfig().getItemStack(condition+".Protection_Required.legs");
            ItemStack boots=getConfig().getItemStack(condition+".Protection_Required.boots");
            ItemStack held=getConfig().getItemStack(condition+".Protection_Required.held");
           
           
            return (inv.getHelmet().equals(helmet) || inv.getChestplate().equals(chestplate)
                    || inv.getLeggings().equals(legs) || inv.getBoots().equals(boots) || inv.getItemInHand().equals(held));
        }
    Here is the config involved:

    Code:
        Protection_Required:
            helmet: NONE
            chestplate: LEATHER_CHESTPLATE
            legs: NONE
            boots: NONE
            held: TORCH
    However, when I try to run it, I get a NullPointerException. I know, it's because I'm checking armor slots for items that are technically non existent, but is there any way around this?

    Thank you,
    Xlr
     
  2. Offline

    Halmerson

  3. Offline

    xlr20ice

    @Halmerson
    Wouldn't I have to add a null check for every slot I want to check though? Or would it be part of the return statement?
     
  4. Offline

    Lordloss

    yes of course you have...
    if (inv.getHelmet() != null && inv.getHelmet().equals(helmet)) return true;
    if (inv.get...
    and so on
     
  5. Offline

    dlange

    @Lordloss either do that, or instead of NONE try AIR
     
Thread Status:
Not open for further replies.

Share This Page