Solved Item Inventory

Discussion in 'Spigot Plugin Development' started by Loxo, Jun 11, 2018.

  1. (For everyone: Im from Germany and my english is not the best)
    Hello there,

    At the moment im working on a spigot plugin and I want to know if somenone can help me with my problem.
    I searched in the internet but found nothing yet.
    Can someone tell me how I can create an inventory in a inventory?
    So for example: I open a quest which is in my slotbar and when I rightclick it, a inventory opens.
    And now the point where I stuck:
    If I open the inventory I want to click a Item which is inside THIS inventory and this item opens another inventory.
    I hope you understand what I need.

    It would also be perfect if you send me the 'code'.
    Is it made with PlayerClickEvent?

    Pls let me know!
     
  2. Would you want to make a new inventory?
    Code (Java):
    Bukkit.createInventory(null, [size], [name]);
     
  3. But does this work to open a inventory by clicking an item what is allready i a inventory?
     
  4. I am pretty sure because it creates a new inventory and all you need to do is say
    Code (Java):
    [Player].openInventory(inventory);
     
  5. This is definitely what you want, simply do
    Code (Java):
     Inventory inv = Bukkit.createInventory(null, [size], [name]);
    // add your items and what not to the inventory here
    targetPlayer.openInventory(inv);
    you can do this recursively!
    If you intend to create "back" buttons or the ability to navigate through these inventories at will, you may want to create them as your class' static method, or in your onEnable, avoiding having to create all those itemstacks over and over.
     
  6. Ok, and how can I select with which item I can open the new inventory?
     
  7. You got to have the inventoryclick event.
    Code (Java):
    public void onClick(InventoryClickEvent e)
    {
    if(e.getInventory().getName().equals(e.getPlayer().getOpenInventory().getName())
    {
    //Get item and open the new inventory
    }
    }
     
    • Agree Agree x 2
  8. If you want to make it so that you need to right click with a item then you need to use onrightclickevent and then check what item the player has in his hand
     
  9. Ah ok...
    Can I send you a part of the code so that you can take a look?
    I just started coding so pls dont hate me and give me some tips^^
    http://prntscr.com/jts6qa
    So what is missing now?
     
  10. This will set the entire inventory to glass planes with no name, except the 10th slot, which will be a fishing rod. Assuming you want another inventory to open when they click this fishing rod, use the InventoryClickEvent once more. Check if the inventory is equal to the currently open one (as provided by @nayongbin108 above), and check if the item clicked is equal to your fishing rod and repeat the process.
     
    • Like Like x 1
  11. Ok, thank you.
     
    • Like Like x 1