I for the life of me, cannot fetch the color of armor a player is wearing...

Discussion in 'Plugin Development' started by Codmikeg, Apr 2, 2013.

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

    Codmikeg

    Code:
    ItemStack chest = player.getInventory().getChestplate();
            //ItemStack leggings = player.getInventory().getLeggings();
            //ItemStack boots = player.getInventory().getBoots();
            if(chest != null && chest.getType() != Material.AIR){
                if(chest.getType() == Material.LEATHER_CHESTPLATE){
                    ItemMeta meta = chest.getItemMeta();
                    LeatherArmorMeta metaChest = (LeatherArmorMeta) meta;
                    if(metaChest.getColor() == Color.fromRGB(255, 255, 255)){
                        player.sendMessage("White");
                    }
                }
            }
    This little snippit is executed through a command for debugging purposes. The "player" variable is being passed from the previous class, I just cant get the color of the armor to compare in the IF statement... help please :c
     
  2. Offline

    chasechocolate

    Try just:
    Code:java
    1. if(metaChest.getColor() == Color.WHITE){
    2. //Do something
    3. }
     
  3. Color is not an enum, use equals().

    Or use .asRGB() and compare those since they're integers, but it would be easier with equals().
     
    microgeek likes this.
  4. Offline

    Codmikeg

    I love you. This is it updated.. working flawlessly.
    Code:
    ItemStack chest = player.getInventory().getChestplate();
            //ItemStack leggings = player.getInventory().getLeggings();
            //ItemStack boots = player.getInventory().getBoots();
            if(chest != null && chest.getType() != Material.AIR){
                if(chest.getType() == Material.LEATHER_CHESTPLATE){
                    ItemMeta meta = chest.getItemMeta();
                    LeatherArmorMeta metaChest = (LeatherArmorMeta) meta;
                    if(metaChest.getColor().equals(Color.WHITE)){
                        player.sendMessage("White");
                    }
                }
            }
     
Thread Status:
Not open for further replies.

Share This Page