Help with inventories

Discussion in 'Plugin Development' started by Monkey_Swag, Jul 28, 2014.

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

    Monkey_Swag

    I hate myself for this... I bet it something obvious that I'm not doing. Anyways, I have created an Inventory using the following code:
    Code:java
    1. public static Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Abilities");

    And when I try to add an item into the inventory like inv#setItem, it doesn't let me do it, it has no available methods or anything. I searched JavaDocs and tutorials, and this should work, and I do not know why. Any help is appreciated thanks.
     
  2. Offline

    xAstraah

  3. Offline

    Monkey_Swag

    xAstraah See what I'm talking about? http://prntscr.com/47bj7l

    Also, I am using CraftBukkit 1.7.9

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

    CraftCreeper6

  5. Offline

    Monkey_Swag

  6. Offline

    CraftCreeper6

    Monkey_Swag
    Try:
    Code:java
    1. ItemStack i = new ItemStack(Material.MY_MATERIAL);
    2. inv.addItem(i);
     
  7. Offline

    Monkey_Swag

  8. Offline

    _LB

    If that variable is static, it means it is not in a method. You can't have code outside of methods or initializers.
     
  9. Offline

    SkyleTyler1337

    Most likely imported the wrong Inventory?
     
  10. Offline

    zombiekiller753

    SkyleTyler1337
    _LB is correct. The code is outside a method.

    You could try an initialization block?
     
  11. Offline

    Monkey_Swag

    The reason I made it static is because I need to access it from another class. But I'll see what i can do
     
  12. Offline

    _LB

    The variable can stay static. The code cannot be in that spot, though.
     
  13. Offline

    messageofdeath

    It has to be within a method like this
    Code:java
    1. public static Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Abilities");
    2.  
    3. public void someMethod() {
    4. Class.inv.addItem(new ItemStack(Material.TEST_MATERIAL);
    5. }
    6.  
     
Thread Status:
Not open for further replies.

Share This Page