Resource GUI Creator - Making inventories was never easier!

Discussion in 'Spigot Plugin Development' started by Homer04, Mar 24, 2016.

  1. Hello there,

    although I've seen plenty flying around here, I wanted to share with you my class for creating Inventories. It supports all versions of CraftBukkit and Spigot. From Version 1.4.x.

    Installation:
    1. Put this class into your Project
    2. Register the Listener in your Main-Class with:
      Code (Text):
      Bukkit.getPluginManager().registerEvents(AdvInventory.getListener(), plugin);

    How to use:
    1. Make a new Object of Type AdvInventory. Like this:
      Code (Text):
      AdvInventory inventory = new AdvInventory(title: String , size: int, placeholder: ItemStack);
      title is the Title seen on top of the Inventory
      size is the size of the Inventory. This needs to be divisible by 9 without 0 (9, 18, 27,...)
      placeholder is a placeholder to put everywhere before all other Items are set. An example is below, set null if you don't want one.
    2. Set Items with:
      Code (Text):
      inventory.setItem(item: ItemStack, name: String, slot: int, new ClickRunnable() {
          @Override
          public void run(InventoryClickEvent e) {
              //What happens on click
          }
      }, description: String...);
      itemstack is the ItemStack to place there
      name is the DisplayName of the Item [Optional]
      slot is the slot to place the Item
      description is the description to use [Optional]
      ClickRunnable is a class provieded by AdvInventory. Just use as above. Everything inside the Curly Braces of the run will be executed on click.
      ► Both name and description can be left out in case your ItemStack already has one
    3. Open Inventory to Player with:
      Code (Text):
      inventory.openInventory(player: Player);

    Additional Methods:
    • Inventory: getSourceInventory - to get the Bukkit-Inventory the AdvInventory is based on
    • Integer: getSize - to get the Size
    • void: removeItem - to remove an Item from a Slot
    • void: setItem - to manually set an Item without any ClickEvent
    Code (Text):
    public static ItemStack placeholder(DyeColor d, String n) {
        @SuppressWarnings("deprecation")
        ItemStack placeholder = new ItemStack(Material.STAINED_GLASS_PANE, 1, d.getData());
        ItemMeta placeholdermeta = placeholder.getItemMeta();
        placeholdermeta.setDisplayName(n);
        placeholder.setItemMeta(placeholdermeta);
        return placeholder;
    }
     
    #1 Homer04, Mar 24, 2016
    Last edited: Apr 6, 2016
    • Useful Useful x 4
    • Like Like x 2
    • Agree Agree x 1
  2. Good job, I'm sure someone will find this useful =)
     
  3. to get more people to see this post, i would recommend changing the title to something like

    [UTIL] GUI Creator with Item Listeners

    because the current title makes it seem like a confusing thing to create inventories like furnace and crafting inventories... i mean... think about yourself stumbling upon a post that starts with "AdvInventory.class"

    i just got confused and stopped trying to read it xD

    the above is mainly a suggestion to help you get more people to see the post! its a great post and i think
    a lot of people will find it useful but won'tbe able to find it without the right keywords
     
    • Useful Useful x 1
  4. Forgot the example I mentioned, added it.
     
  5. hmm, good tutorial
     
    • Agree Agree x 1
  6. Fun fact: I had to look up into my own API because I needed this API for a small project for a friend.
     
    • Funny Funny x 1
  7. You know, to add all item flags to an item's meta you can simply do meta.addItemFlags(ItemFlag.values()) ;p. Still a nice resource though.
     
  8. What are the uses of "currentOpen" ?
    It is just used to count the inventories opened ?
     
  9. There's an error on line 30:

    Code (Text):
    new AdvInventory(name, size, null);
    should be

    Code (Text):
    this(name, size, null);
    as otherwise a new object is being created but we cant access it
     
  10. Very usefull, thank you very much :)