Checking if a player is wearing leather boots.

Discussion in 'Plugin Development' started by Big_Mac_dev, Jul 12, 2014.

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

    Big_Mac_dev

    I am trying to see if a player is wearing leather boots here is my code.
    Code:java
    1. if(player.getInventory().getBoots().getType().equals(new ItemStack(Material.LEATHER_BOOTS))){
    2. player.sendMessage("leather");
    3.  
    4.  
    5. }
     
  2. Offline

    Seadragon91

    Code:
    if (player.getInventory().getBoots().getType() == Material.LEATHER_BOOTS) {
    // your code
    }
     
  3. Offline

    Necrodoom

    Big_Mac_dev You are doing getType() on the boots, which returns Material, then you try to .equals() it with an ItemStack. Either both are ItemStack or both are Material.
     
  4. Offline

    mythbusterma

    Big_Mac_dev

    A new ItemStack of 0 is not equal to what the player would be wearing, the player cannot wear stacks of zero, and you shouldn't (in this context) create new objects just for comparison operations, especially when better alternatives exist.
     
  5. Offline

    mazentheamazin

    Big_Mac_dev
    As well, enums and primitives should be compared with '==' whilst objects should be compared with the Object#equals method.
     
Thread Status:
Not open for further replies.

Share This Page