How to check itemMeta

Discussion in 'Plugin Development' started by ProMCKingz, Aug 18, 2014.

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

    ProMCKingz

    Hey!
    I am trying to make it so that in my GUI I can store different items with different itemMeta's.
    However my problem is, how do I check if an object has a specified itemMeta?
    I have the following code, however I am unaware on a method to check for the Meta:
    Code:java
    1. ItemStack item = new ItemStack(Material.GOLD_HELMET, 1);
    2. ItemMeta meta = item.getItemMeta();
    3. meta.setDisplayName(ChatColor.GOLD + "Gold Helmet");
    4. List<String> lore = new ArrayList<String>();
    5. lore.add("Adds a golden helmet to your character!");
    6. meta.setLore(lore);
    7. item.setItemMeta(meta);
    8. inv.setItem(3, item);

    This is just the code for one of my slots in my GUI.
    Thanks,
    ProMCKingz
     
  2. Offline

    jpjunho

    ProMCKingz
    use ItemStack.hasItemMeta()
    then you can use getDisplayName() , getLore() and getEnchants()
    Remember to check if it has a display name, lore or enchants before by using hasDisplayName()
     
  3. Offline

    patey

    I use metaData on player entities in plugin I'm working on, not sure if it'll help but here's how I do it:

    method to save the data-
    Code:
        public void setMetadata(Entity player, String key, Object value, Plugin plugin){
            player.setMetadata(key,new FixedMetadataValue(plugin,value));
            }
    compare the metaData:

    Code:java
    1. String race = player.getMetadata("race").get(0).asString();
    2.  
    3. if (race.equalsIgnoreCase("human"){
    4. //do code
    5. }
     
  4. Offline

    Gater12

    patey
    OP asking for ItemMeta not Metadata.
     
  5. Offline

    patey

    sorry, thought that was just meta data for items lol
     
  6. Offline

    ProMCKingz

Thread Status:
Not open for further replies.

Share This Page