Armor == null not working

Discussion in 'Plugin Development' started by MCCoding, Jun 16, 2014.

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

    MCCoding

    I'm trying to check if a player just has a diamond block on his head but when i check if their chestplate, leggings and boots are null it does not work. Here is what i have tried

    • player.getEquipment().getChestplate().getTypeId() == 0
    • player.getEquipment().getChestplate().getType() == null
    • player.getEquipment().getChestplate().getType() == Material.AIR
    • player.getEquipment().getChestplate().getTypeId() == 0
    • player.getEquipment().getChestplate().getItemMeta().getDisplayName() == "DIAMOND_BLOCK"
    None of that has worked for some reason but here is my code I have currently
    Code:
    if(player.getEquipment().getHelmet().getType() == Material.DIAMOND_BLOCK &&
                        player.getEquipment().getChestplate().getType() == null &&
                        player.getEquipment().getLeggings().getType() == null  &&
                        player.getEquipment().getBoots().getType() == null) {
     
  2. Offline

    AoH_Ruthless

    MCCoding
    The type cannot be null I think. Remove the getType() checks and then see. You should also debug.
     
  3. Offline

    Rocoty

    Don't just say it doesn't work. Tell us what happens. Do you get an error? getChestplate returns null if there is no chestplate, so it is pointless to check the type of it.
     
  4. Offline

    MCCoding

    AoH_Ruthless
    I have tested this got no error and didn't work, what i'm trying to do Rocoty is when they are just wearing the diamond block send them a message but it's not working since it's not liking me having no armor on.

    Code:java
    1. if(player.getEquipment().getHelmet().getType() == Material.DIAMOND_BLOCK&&
    2. player.getEquipment().getChestplate() == null &&
    3. player.getEquipment().getLeggings() == null &&
    4. player.getEquipment().getBoots() == null) {
     
  5. MCCoding Debug those values to see which are true
     
  6. Offline

    PluginMaker

    MCCoding
    you need to check if the type is Material.AIR.
    to be honest, it does make more sense to have the item set to null, but it seem like when an item is null in most methods it retuns itemstack with 0 amount and Material.AIR
     
  7. PluginMaker Actually, getEquipment().getInsertRandomArmourNameHere() returns null, not an empty air ItemStack
     
  8. Offline

    Garris0n

    AdamQpzm likes this.
  9. Garris0n Oh yes, my mistake. I forgot CraftItemStack converts null values. :)
     
Thread Status:
Not open for further replies.

Share This Page