Package org.bukkit.inventory.meta

Examples of org.bukkit.inventory.meta.ItemMeta


  public static void transferAll(ItemStack stack, JsonObject json, boolean stack2json)
  {
    transferBasic(stack, json, stack2json);

    ItemMeta meta = stack.getItemMeta();
    transferMeta(meta, json, stack2json);

    if (stack2json == false)
    {
      stack.setItemMeta(meta);
View Full Code Here


            }
        }
    }
   
    private ItemStack addItemMeta(ItemStack is, String meta) {
        ItemMeta ismeta = is.getItemMeta();
        String[] msplit = meta.split("#");
        //Let's see if we've got new meta or the old way of handling it.
        if(msplit[0].equals("NM")) {
            HashMap<String, String> itemdata = new HashMap<String,String>();
            int potionint = 0;
            int effectint = 0;
            int fireworkint = 0;
            for(String data : msplit) {
                if(data.equals("NM")) continue;
                if(data.length() > 1) {
                    String key = data.substring(0, 1);
                    //There can be multiple potion effects, let's add an identifier
                    if(key.equals("P")) {
                        key = "P" + String.valueOf(potionint);
                        potionint++;
                    }else if(key.equals("E")) {
                        key = "E" + String.valueOf(effectint);
                        effectint++;
                    }else if(key.equals("F")) {
                        key = "F" + String.valueOf(fireworkint);
                        fireworkint++;
                    }
                    String value = data.substring(1);
                    itemdata.put(key, value);
                }
            }
            String data = itemdata.get("N");
            if(data != null) {
                ismeta.setDisplayName(base64Decode(data));
            }
            data = itemdata.get("L");
            if(data != null) {
                ismeta.setLore(decodeLore(data));
            }
            if(ismeta instanceof SkullMeta) {
                data = itemdata.get("O");
                if(data != null) {
                    ((SkullMeta) ismeta).setOwner(data);
                }
            } else if(ismeta instanceof LeatherArmorMeta) {
                data = itemdata.get("C");
                if(data != null) {
                    int color = Integer.parseInt(data);
                    ((LeatherArmorMeta) ismeta).setColor(Color.fromRGB(color));
                }
            } else if(ismeta instanceof PotionMeta) {
                PotionMeta pmeta = (PotionMeta) ismeta;
                for(int i = 0; (data = itemdata.get("P" + String.valueOf(i))) != null; i++) {
                    String[] potion = data.split("\\+");
                    PotionEffectType type = PotionEffectType.getByName(potion[0]);
                    int amplifier = Integer.parseInt(potion[1]);
                    int duration = Integer.parseInt(potion[2]);
                    PotionEffect pe = new PotionEffect(type, duration, amplifier);
                    pmeta.addCustomEffect(pe, true);
                }
            }else if(ismeta instanceof EnchantmentStorageMeta) {
                EnchantmentStorageMeta emeta = (EnchantmentStorageMeta) ismeta;
                for(int i = 0; (data = itemdata.get("E" + String.valueOf(i))) != null; i++) {
                    String[] enchant = data.split("\\+");
                    Enchantment enchantenum = Enchantment.getByName(enchant[0]);
                    if(enchantenum != null) {
                        int value = Integer.parseInt(enchant[1]);
                        emeta.addStoredEnchant(enchantenum, value, true);
                    }
                }
            }else if(ismeta instanceof FireworkMeta) {
                FireworkMeta fmmeta = (FireworkMeta) ismeta;
                for(int i = 0; (data = itemdata.get("F" + String.valueOf(i))) != null; i++) {
                    String[] fedata = data.split("\\+");
                    Type effect = FireworkEffect.Type.valueOf(fedata[0]);
                    Builder ef = FireworkEffect.builder();
                    ef.with(effect);
                    if(effect != null) {
                        String[] colors = fedata[1].split("-");
                        for(String color : colors) {
                            try {
                                ef.withColor(Color.fromRGB(Integer.parseInt(color)));
                            }catch (Exception e) {
                               
                            }
                        }
                        String[] fadecolors = fedata[2].split("-");
                        for(String fadecolor : fadecolors) {
                            try {
                                ef.withFade(Color.fromRGB(Integer.parseInt(fadecolor)));
                            }catch (Exception e) {
                               
                            }
                        }
                        ef.flicker(Boolean.parseBoolean(fedata[3]));
                        ef.trail(Boolean.parseBoolean(fedata[4]));
                        fmmeta.addEffect(ef.build());
                    }
                }
                data = itemdata.get("G");
                try {
                    fmmeta.setPower(Integer.parseInt(data));
                }catch (Exception e) {
                   
                }
            }else if(ismeta instanceof FireworkEffectMeta) {
                data = itemdata.get("F0");
                if(data != null) {
                    String[] fedata = data.split("\\+");
                    Type effect = FireworkEffect.Type.valueOf(fedata[0]);
                    Builder ef = FireworkEffect.builder();
                    ef.with(effect);
                    if(effect != null) {
                        String[] colors = fedata[1].split("-");
                        for(String color : colors) {
                            try {
                                ef.withColor(Color.fromRGB(Integer.parseInt(color)));
                            }catch (Exception e) {
                               
                            }
                        }
                        String[] fadecolors = fedata[2].split("-");
                        for(String fadecolor : fadecolors) {
                            try {
                                ef.withFade(Color.fromRGB(Integer.parseInt(fadecolor)));
                            }catch (Exception e) {
                               
                            }
                        }
                        ef.flicker(Boolean.parseBoolean(fedata[3]));
                        ef.trail(Boolean.parseBoolean(fedata[4]));
                        ((FireworkEffectMeta) ismeta).setEffect(ef.build());
                    }
                }
            }
            if(ismeta instanceof Repairable) {
                data = itemdata.get("R");
                if(data != null) {
                    Repairable rmeta = (Repairable) ismeta;
                    rmeta.setRepairCost(Integer.parseInt(data));
                }
            }
        }else {
            //Old item meta here
            int repairableindex = 2;
            if(msplit.length > 1) {
                if(!msplit[0].equals("")) {
                    ismeta.setDisplayName(base64Decode(msplit[0]));
                }
                if(!msplit[1].equals("")) {
                    ismeta.setLore(decodeLore(msplit[1]));
                }
                if(ismeta instanceof SkullMeta) {
                    if(!msplit[2].isEmpty()) {
                        ((SkullMeta) ismeta).setOwner(msplit[2]);
                    }
View Full Code Here

                ItemStack item = GlowBufUtils.readSlot(buf);
                //GlowServer.logger.info("BookEdit [" + session.getPlayer().getName() + "]: " + item);
                if (item == null || item.getType() != Material.BOOK_AND_QUILL) {
                    return;
                }
                ItemMeta meta = item.getItemMeta();
                if (!(meta instanceof BookMeta)) {
                    return;
                }
                BookMeta book = (BookMeta) meta;
                if (!book.hasPages()) {
                    return;
                }

                // verify item in hand
                ItemStack inHand = session.getPlayer().getItemInHand();
                if (inHand == null || inHand.getType() != Material.BOOK_AND_QUILL) {
                    return;
                }
                ItemMeta handMeta = inHand.getItemMeta();
                if (!(handMeta instanceof BookMeta)) {
                    return;
                }
                BookMeta handBook = (BookMeta) handMeta;

                // apply pages to book
                handBook.setPages(book.getPages());
                inHand.setItemMeta(handBook);
                session.getPlayer().setItemInHand(inHand);
                break;
            }
            case "MC|BSign": {
                // read and verify stack
                ItemStack item = GlowBufUtils.readSlot(buf);
                //GlowServer.logger.info("BookSign [" + session.getPlayer().getName() + "]: " + item);
                if (item == null || item.getType() != Material.WRITTEN_BOOK) {
                    return;
                }
                ItemMeta meta = item.getItemMeta();
                if (!(meta instanceof BookMeta)) {
                    return;
                }
                BookMeta book = (BookMeta) meta;
                if (!book.hasPages() || !book.hasTitle()) {
                    return;
                }

                // verify item in hand
                ItemStack inHand = session.getPlayer().getItemInHand();
                if (inHand == null || inHand.getType() != Material.BOOK_AND_QUILL) {
                    return;
                }
                ItemMeta handMeta = inHand.getItemMeta();
                if (!(handMeta instanceof BookMeta)) {
                    return;
                }
                BookMeta handBook = (BookMeta) handMeta;
View Full Code Here

//    this.loadItemStack(); // WTH !?
   
    int      id      = getInteger(INTEGER_ID);
    int     durability  = getInteger(INTEGER_DURABILITY);
    Storage    metaStorage  = getStorage(STORAGE_ITEMMETA);
    ItemMeta  meta    = (ItemMeta)new ConfigurationSerializationStorage(metaStorage).getConfigurationSerializable();
   
    this.stack    = new ItemStack(id, Properties.DEFAULT_STACK_AMOUNT, (short)durability);
    this.stack.setItemMeta(meta);
  }
View Full Code Here

      int   id    = stack.getTypeId();
      short  meta  = stack.getDurability();
     
        switch(id) {
            default:
              ItemMeta itemMeta = stack.getItemMeta();
             
              if (itemMeta.getDisplayName() != null) {
                return itemMeta.getDisplayName();
              } else {
                return stack.getType().toString()+" ["+ id + ":" + meta+"]";
              }
            case 0: return "Air";
            case 1: return "Stone";
View Full Code Here

    // SLOT 6: ACTIVE POTION EFFECTS
    if (player.getActivePotionEffects().size() > 0)
    {
      ItemStack potion = new Potion(PotionType.POISON).toItemStack(1);
      ItemMeta meta = potion.getItemMeta();

      List<String> effects = Lists.newLinkedList();
      for (PotionEffect effect : player.getActivePotionEffects())
        effects.add(ChatColor.RESET + "" + ChatColor.GRAY +
          PlayerUtil.getStatusEffectName(effect));

      meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.ITALIC + "Status Effects");
      meta.setLore(effects);

      potion.setItemMeta(meta);
      newContents[oldContents.length + 5] = potion;
    }

    // SLOT 7: CURRENT PLAYER LEVEL
    if (player.getLevel() > 0)
    {
      ItemStack level = new ItemStack(Material.EXP_BOTTLE, player.getLevel());
      ItemMeta meta = level.getItemMeta();

      meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.ITALIC + "Player XP Level");
      meta.setLore(Lists.newArrayList(ChatColor.GRAY + "" + ChatColor.ITALIC +
        String.format("%d %s", player.getLevel(), player.getLevel() == 1 ? "level" : "levels")));

      level.setItemMeta(meta);
      newContents[oldContents.length + 6] = level;
    }

    // SLOT 8: PLAYER HEALTH
    {
      ItemStack health = new ItemStack(Material.APPLE, player.getHealth());
      ItemMeta meta = health.getItemMeta();

      meta.setDisplayName(ChatColor.RED + "" + ChatColor.ITALIC + "Player Health");
      meta.setLore(Lists.newArrayList(ChatColor.GRAY + "" + ChatColor.ITALIC +
        String.format("%2.1f hearts", player.getHealth() / 2.0)));

      health.setItemMeta(meta);
      newContents[oldContents.length + 7] = health;
    }

    // SLOT 9: PLAYER HUNGER
    {
      ItemStack hunger = new ItemStack(Material.COOKED_BEEF, player.getFoodLevel());
      ItemMeta meta = hunger.getItemMeta();

      meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.ITALIC + "Player Hunger");
      meta.setLore(Lists.newArrayList(ChatColor.GRAY + "" + ChatColor.ITALIC +
        String.format("%2.1f food", player.getFoodLevel() / 2.0)));

      hunger.setItemMeta(meta);
      newContents[oldContents.length + 8] = hunger;
    }
View Full Code Here

        for (Element enchant : gear.getChildren("enchant"))
          addParsedEnchantment(item, enchant);

        if (gear.getChild("name") != null)
        {
          ItemMeta itemMeta = item.getItemMeta();
          itemMeta.setDisplayName(gear.getChildTextTrim("name"));
          item.setItemMeta(itemMeta);
        }

        // TODO Books
View Full Code Here

        }

        itemStack = new ItemStack(material);
        itemStack.setDurability(durability);

        ItemMeta meta = getMetadata(itemName);

        if (meta != null) {
            itemStack.setItemMeta(meta);
        }
View Full Code Here

    }
    final Object meta = this.meta;
    if (meta != null) {
      if (item == null)
        return false;
      final ItemMeta m = item.getItemMeta();
      unsetItemMetaEnchs(m);
      if (!meta.equals(m))
        return false;
    }
    return true;
View Full Code Here

      b.append(" ");
      b.append(e.getValue());
      i++;
    }
    if (meta != null) {
      final ItemMeta m = (ItemMeta) meta;
      if (m.hasDisplayName()) {
        b.append(" " + m_named.toString() + " ");
        b.append("\"" + m.getDisplayName() + "\"");
      }
      if (debug)
        b.append(" meta=[").append(meta).append("]");
    }
    return "" + b.toString();
View Full Code Here

TOP

Related Classes of org.bukkit.inventory.meta.ItemMeta

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.