Inventory Item Not Changing

Discussion in 'Spigot Plugin Development' started by ryu, May 25, 2016.

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

    ryu

    Issue:
    I'm trying to change the potions to jump boost potions but I don't understand why they won't change I don't see anything wrong with the code.

    [​IMG]
    Code (Text):

    package dev.ryujix.shop.Shops.Buy;

    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    public class Haste_1
    {
      static String name = "Haste I";
      static ItemStack item = new ItemStack(Material.POTION);
      static byte id = (byte)8267;
     
      private static ItemStack createItems(ItemStack item, int i, byte id)
      {
        List<String> lores = new ArrayList();
       
        ItemStack finalItem = item;
        ItemMeta meta = finalItem.getItemMeta();
       
        lores.add(ChatColor.AQUA + "Item: " + ChatColor.YELLOW + name);
        lores.add(ChatColor.AQUA + "Amount: " + ChatColor.YELLOW + i);
        lores.add(ChatColor.AQUA + "Price: " + ChatColor.YELLOW + "$" + i * 250);
        lores.add(ChatColor.GRAY + "(Click to purchase this item)");
       
        meta.setDisplayName(ChatColor.GREEN + "x" + i + " " + name);
        meta.setLore(lores);
        meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
       
        finalItem.getData().setData(id);
        finalItem.setItemMeta(meta);
        finalItem.setAmount(i);
       
        lores.clear();
       
        return finalItem;
      }
     
      public static Inventory shopHaste1(Player player)
      {
       
          Inventory inv = Bukkit.createInventory(null, 9, "Buy - " + name + " " + "$" + "250.00" + "/ea");
        for (int i = 0; i < 9; i++) {
          if (i == 0) {
            inv.setItem(i, createItems(item, 1, id));
          } else if (i == 1) {
            inv.setItem(i, createItems(item, 5, id));
          } else if (i == 2) {
            inv.setItem(i, createItems(item, 10, id));
          } else if (i == 3) {
            inv.setItem(i, createItems(item, 15, id));
          } else if (i == 4) {
            inv.setItem(i, createItems(item, 20, id));
          } else if (i == 5) {
            inv.setItem(i, createItems(item, 25, id));
          } else if (i == 6) {
            inv.setItem(i, createItems(item, 30, id));
          } else if (i == 7) {
            inv.setItem(i, createItems(item, 45, id));
          } else if (i == 8) {
            inv.setItem(i, createItems(item, 64, id));
           
            player.openInventory(inv);
          }
        }
        return inv;
      }
    }
     
  2. 1.9 no longer uses data values. Use PotionMeta instead.
     
    • Agree Agree x 1
  3. Have to use PotionMeta instead of ids for potions now. It's similar to ItemMeta.

    EDIT: Ninja'd ;-;
     
  4. ryu

    ryu

    This is for 1.8 not 1.9
     
  5. I may have figured it out, you're calling the getItemMeta before stating the id, that might sometimes mess it up, wouldn't it?
     
  6. ryu

    ryu

    Possibly I'll try it out and let you know
     
  7. Try calling ItemStack#setDurability
     
  8. oh yeah, that's how it works :p
     
Thread Status:
Not open for further replies.