Solved Creating A Custom Inventory Help Plz

Discussion in 'Plugin Development' started by __Sour, Mar 2, 2014.

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

    __Sour

    hello, i am making a kitpvp plugin and it will have a kitpvp menu sign and it will create a inventory with items in it and when that item it is clicked which all works well but, when i tryed to put items into the inventory using a diffent way it wont work
    Code:java
    1. public static Inventory kitPicker = Bukkit.createInventory(null, 9, "§2KitPVP §b- §cChose a kit§r.");
    2. static {
    3. kitPicker.setItem(0, new ItemStack(Material.IRON_SWORD, 1));
    4. kitPicker.setItem(1, new ItemStack(Material.BOW, 1));
    5. kitPicker.setItem(2, new ItemStack(Material.DIAMOND_SWORD, 1));
    6. kitPicker.setItem(3, new ItemStack(Material.FIRE, 1));
    7. kitPicker.setItem(4, new ItemStack(Material.FIRE, 1));
    8. kitPicker.setItem(5, new ItemStack(Material.FIRE, 1));
    9. kitPicker.setItem(6, new ItemStack(Material.FIRE, 1));
    10. kitPicker.setItem(7, new ItemStack(Material.FIRE, 1));
    11. kitPicker.createDisplay(new ItemStack(Material.FIRE), Whats Goes here?, 8, "Fire", "Fire BALLS!");
    12. }
    13.  
    14. public static void createDisplay(Material material, Inventory inv, int Slot, String name, String lore) {
    15. ItemStack item = new ItemStack(material);
    16. ItemMeta meta = item.getItemMeta();
    17. meta.setDisplayName(name);
    18. ArrayList<String> Lore = new ArrayList<String>();
    19. Lore.add(lore);
    20. meta.setLore(Lore);
    21. item.setItemMeta(meta);
    22. inv.setItem(Slot, item);
    23. }


    And in the last row where i try to place a item what do i put where it say
    Code:java
    1. What Goes here?


    What would i put there? Im kinda new to making inventorys, maybe JPG2000 can help?

    Or also maybe Tzeentchful could also help cause your amazing at coding!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    JeZPvP

    Code:
        public static Inventory kitPicker = Bukkit.createInventory(null, 9, "§2KitPVP §b- §cChose a kit§r.");
        static {
     
    ItemStack item = new ItemStack(material);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(name);
        ArrayList<String> Lore = new ArrayList<String>();
        Lore.add(lore);
        meta.setLore(Lore);
        item.setItemMeta(meta);
        inv.setItem(Slot, item);
     
        kitPicker.setItem(0, new ItemStack(Material.IRON_SWORD, 1));
        kitPicker.setItem(1, new ItemStack(Material.BOW, 1));
        kitPicker.setItem(2, new ItemStack(Material.DIAMOND_SWORD, 1));
        kitPicker.setItem(3, new ItemStack(Material.FIRE, 1));
        kitPicker.setItem(4, new ItemStack(Material.FIRE, 1));
        kitPicker.setItem(5, new ItemStack(Material.FIRE, 1));
        kitPicker.setItem(6, new ItemStack(Material.FIRE, 1));
        kitPicker.setItem(7, new ItemStack(Material.FIRE, 1));
        kitPicker.setItem(8, item);
        }
    Describe the item before adding it, it's easier.
    So then you just have to set it to the slot.
     
  3. Offline

    supersonicsauce

    __Sour You have to create a new inventory before you can add items to it. Thats what the parameter 'inv' wants.
    Also, the createDisplay method can't create inventories, it only adds items to inventories. So, make a new inventory:

    Code:java
    1. Inventory putyourinvnamehere = Bukkit.createInventory(null, 9);
    2.  


    Then add your items to it:

    Code:java
    1. createDisplay(Material.ARROW, putyourinvnamehere, 0, "Name of item", "Item description");
    2.  
     
  4. Offline

    __Sour

    supersonicsauce
    I did make a inventory and i have updated it to what you sayed to put
    Code:java
    1. public static Inventory kitPicker = Bukkit.createInventory(null, 9, "§2KitPVP §b- §cChose a kit§r.");
    2. static {
    3. kitPicker.setItem(0, new ItemStack(Material.IRON_SWORD, 1));
    4. kitPicker.setItem(1, new ItemStack(Material.BOW, 1));
    5. kitPicker.setItem(2, new ItemStack(Material.DIAMOND_SWORD, 1));
    6. kitPicker.setItem(3, new ItemStack(Material.FIRE, 1));
    7. kitPicker.setItem(4, new ItemStack(Material.FIRE, 1));
    8. kitPicker.setItem(5, new ItemStack(Material.FIRE, 1));
    9. kitPicker.setItem(6, new ItemStack(Material.FIRE, 1));
    10. kitPicker.setItem(7, new ItemStack(Material.FIRE, 1));
    11. kitPicker.createDisplay(Material.FIRE, kitPicker, 8, "Fire", "Fire BALLS!");
    12. }
    13.  
    14. public static void createDisplay(Material material, Inventory inv, int Slot, String name, String lore) {
    15. ItemStack item = new ItemStack(material);
    16. ItemMeta meta = item.getItemMeta();
    17. meta.setDisplayName(name);
    18. ArrayList<String> Lore = new ArrayList<String>();
    19. Lore.add(lore);
    20. meta.setLore(Lore);
    21. item.setItemMeta(meta);
    22. inv.setItem(Slot, item);
    23. }


    Theres a red line under .createDisplay
    When i try to fix it it says add a cast to "kitPicker" which i tried and all it did was leave a error msg in console any other way to do this?

    Also maybe njb_said can help i seen your kitpvp that is kinda like this one with the lores and custom names in a inventory?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    supersonicsauce

    __Sour Where did public static come from? Just do exactly what I said in my previous post. You don't need to put public static in front of your inventory. Also, like I said, the createDisplay method isn't for making an inventory, it's for adding items to it. So the kit picker.setItem lines aren't necessary, you should use createDisplay()for every method.
     
Thread Status:
Not open for further replies.

Share This Page