1.12.2 How to make Private Gui

Discussion in 'Spigot Plugin Development' started by gameHD852_2, May 14, 2022.

  1. I am trying to make a GUI where I can change the items depending on permissions and arrays for each player. But when I do Bukkit.createInventory(), it creates an inventory that everyone can access. I need to make a new one for each player. But I dont know how. If you know can you please help me? Thanks.
     
  2. cant you set the inventory owner in Bukkit.createInventory()?
     
    • Agree Agree x 2
  3. create a HashMap with UUID Inventory and create for all new player an entry in this map.
     
    • Agree Agree x 2
    • Like Like x 1
  4. What do you mean everyone can access it? Whoever you open that inventory to you will be able to see it and i'm pretty sure each player will see their own version. (for example if someone edits something in the inventory, everyone else's wont update)
     
  5. ..fake? If you keep the same inventory and open it to every player.. every player could see the changes. Same such opening a chest with two different players together at the same time and moving the items inside.
     
    #5 StivenFocs, May 18, 2022 at 8:53 PM
    Last edited: May 18, 2022 at 9:12 PM
    • Agree Agree x 1
  6. Are you opening the same inventory to every player?
     
  7. if they save the inventory in an variable and reuse the same everytime someone runs the command then yes everyone will access the same inventory.
    best option for op is to recreate the inventory everytime someones runs the command since it all depends on permissions
     
  8. and next, editing it at the clickevent
     
  9. Summarizing...

    Create an HashMap<UUID, Inventory>
    Imagine a table of scores in a whiteboard: in this table you assign a score to a person by writing the name on the left and the corresponding score on the right, converting this to a HashMap, you would have this: HashMap<String, Integer> (The String value for the name and the Integer value for the score).
    In your case, you need to assign an Inventory to a player so you can get the corresponding Inventory by providing that player (and in this case, do NOT use a Player object, use its UUID instead).

    Declare this variable of type HashMap as public and place it in a class (even a dedicated one) where you can access it (I recommend making it static).
    Then to avoid confusing or messing up your code write a simple method where you provide a UUID and the method returns the inventory to you (if the inventory does not exist, it creates it and returns it, if it already exists, the method returns it by getting it directly from the HashMap).

    This way you can be free to manage the whole system in an orderly way and (as I think I understand it) to be able to program a GUI on which the player can interact to change the permissions of the one who is assigned to that GUI: you can use an event (InventoryClickEvent) to detect the click, then you have to check if the inventory is owned by your plugin and then be able to recognize which key is being clicked.
     
  10. he doesnt need an hashmap if he wants to recreate the same inventory everytime just like a menu.. its better to recreae it on the fly since player's permissions can change between two openings
     
  11. I was saying that to make something nice to look at and use, where it might still be annoying to have to reopen the GUI multiple times if you have to make multiple changes
     
  12. Use if and else checks to set the blocks with set items method, not sure what else your trying to do tho.