[Tutorial] Create a Inventory Menu!

Discussion in 'Resources' started by JPG2000, Sep 8, 2013.

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


    Heres a small snipit of the code im messing with. Is there a way to make it when the player clicks and item and has it following the cursor, to set that to null, so essentially they can't move the items? The only solution so far is to include the player.closeInventory() but i was hoping for a way to keep it open so players can check out multiple stats. Also quick side note great tutorial.
                        else if(clicked.getType() ==Material.BOW)
                                int playerarchery;
                                PlayerData pd = new PlayerData(player.getName());
                                playerarchery = pd.getData().getInt("Archery");
                                player.sendMessage("Your archery is: " + playerarchery);
  2. Offline


    valon750: Take a look at Ultimate_n00b's class.. If you use it you can set multiple lines of lore using the addButton function.
    1. public IconMenu addButton(Row row, int position, ItemStack item, String name, String... lore)

  3. Offline


    Mine only works when I do this:
    1. public static org.bukkit.inventory.Inventory myInventory = Bukkit.createInventory(null, 9, "Inventory");

    Even if i do import it, it says its an unused import

    EDIT: NEVERMIND I know what I did wrong, the name of my class is Inventory :p oops
  4. Offline


    What would I have to do if I wanted a skeleton spawn egg instead of a block in the inventory?
  5. Offline


    JPG2000 in your first code line you have Bxukkit xD
  6. How to check if the clicked item is custom?
    1. if (event.getInventory() != shopinventory){
    2. player.sendMessage("This is not the shop you're looking for");
    3. return;
    4. }
    5. if (event.getCurrentItem() == getAbilities(ShopItems.Abilities)){
    6. player.sendMessage("Works");
    7. event.setCancelled(true);
    8. }

    1. public enum ShopItems {
    2. Abilities;
    3. }
    5. @SuppressWarnings("incomplete-switch")
    6. public ItemStack getAbilities(ShopItems item) {
    7. Potion potion = new Potion (PotionType.REGEN, 1);
    8. ItemStack potionstack = potion.toItemStack(1);
    9. ItemMeta meta = potionstack.getItemMeta();
    10. ArrayList<String> lore;
    11. switch (item) {
    12. case Abilities:
    13. meta.setDisplayName(ChatColor.ITALIC + "Abilities");
    14. lore = new ArrayList<String>();
    15. lore.add(ChatColor.BLUE + "Find your abilities here!");
    16. meta.setLore(lore);
    17. potionstack.setItemMeta(meta);
    18. }
    19. return potionstack;
    20. }

    Doesn't work for me though.
  7. Offline


    Uuhm i need help :S i making a wand plugin but i wanna set a magic wand on a air material in slot 9 can someone help me? please :D
  8. Offline


    I would really like to use this, everything works except for the keeping it in the inventory part :3

    EDIT: Nvm I figured it out a different way
    Last edited: Mar 31, 2015
    JPG2000 likes this.
  9. Offline


    OMG Thx man I love your "Tutorials" you helped me a lot <3
    #No Homo :3

    Awsome Tutorial man :3 but I have a questions how do I make that there Heads from Players in the Menu?
    Last edited by a moderator: Jun 2, 2015
  10. Offline


  11. Offline


    Hey how do i set the Slot for the Item Stack / Meta it doesnt show the way I do it
       public static void createDisplay(Material material, Inventory inv, int Slot, String name, String lore) {
               ItemStack Bedwars = new ItemStack(Material.BED);
               ItemMeta BedwarsMeta = Bedwars.getItemMeta();
               BedwarsMeta.setDisplayName(ChatColor.BLUE + "Bedwars");
               ArrayList<String> Lore = new ArrayList<String>();
               Lore.add( ChatColor.GREEN + "Teleportiert dich zu" + ChatColor.BLUE + "Bedwars" + ChatColor.GREEN + "!");
               inv.setItem(11, Bedwars);
  12. Offline


    it says "The method setItem(int, org.bukkit.inventory.ItemStack) in the type Inventory is not applicable for the arguments (int, net.minecraft.server.v1_8_R3.ItemStack)" What to do about that?
  13. Offline

    timtower Administrator Administrator Moderator

    You imported the wrong ItemStack
  14. Offline


    @timtower Yay! It works! Thanks so much!

    it says the "The constructor ItemStack(Material, int) is undefined" how do I define it? there's no import option.

    EDIT by Timtower: merged posts

    And also, how do I name the items inside the inventory?

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
    Last edited by a moderator: Aug 21, 2015
  15. Offline


    How can I add items to the GUI shop with commands?
    E.g. /shop additem
    Then, it will get the item in my hand and save it to the config file so when I type /shop, it shows all the item from the config file. Can someone help me?
  16. Offline


    Bxukkit should be Bukkit
  17. Offline


    Nice tutorial, but if I click on a empty slot (so in my own inventory or on a empty slot in the GUI) it gives an NullPointerException in my console,

    how can I fix this?

  18. Offline


    First, why are you replying to a tread that is over a year old? That's necro-posting, and not needed.

    Secondly, check if it's null when getting it? Do you know Java?
  19. Offline


    first, this is the only good tutorial I can find on the web, so i did asked it here,

    and yes i do know java, and I did checked that with this line:
    if (e.getCurrentItem().getItemMeta() == null) return;
    if (e.getCurrentItem().getItemMeta() == null) return;
    but that did not worked
  20. Offline


    Returning it will do nothing. Just check if the item is not null before executing your code.
  21. Can you please give an example of this in use? i cant seem to get it to work. Also how would you set the amount of the material?
  22. Offline


    What if I want to have the same items but with different names??
  23. Offline


    And, how to save the inventory? Because i have another class, in this, i add items for the inventory, but, when i reload the server, all items remove.
  24. Offline


    @FiesteroCraft When you reload the server, the plugin instance is literally tossed aside by Bukkit/Spigot and a new instance is created, so you need to use either a database or the configuration files.

    Creating a simple configuration file for inventory persistence shouldn't be too hard to do on your own.
  25. Offline


    Hey guy, author of the theme, i'm really grateful to you for this guide, you really helped me. THANK YOU A LOT!
  26. how to close the inventory for everyone who is using the menu?
    Last edited: Apr 28, 2017
Thread Status:
Not open for further replies.

Share This Page