Solved Private Inventories?

Discussion in 'Plugin Development' started by SneakyBruh, Sep 30, 2017.

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

    SneakyBruh

    I have been trying for almost 2 hours now. I have found nothing online that works and i have looked at the bukkit inventory method and im not sure how why it doesn't work.
    Im trying to create a Settings GUI (Turn night vision on/off and so on) but its a public inventory so everyone if someone clicks it... it will change for everyone. How would i make private inventories for people and save them for next time they open them?
     
  2. Offline

    Zombie_Striker

    @SneakyBruh
    Create a new inventory for each player. Every time a player should see that window, create a new GUI with all the items you need. When you need to check if the player clicked on an item in that inventory, check the inventories title to verify that it is using your gui.
     
  3. Offline

    SneakyBruh

    Code:
    
        if(!inventories.containsKey(player)){
        Inventoryinvs=Bukkit.createInventory(player,45,"§c§lSettings:");
    
    still makes a public inv
     
  4. Offline

    Caderape2

  5. Offline

    Zombie_Striker

    @SneakyBruh
    [Edit] wrong suggestion. Do not store the inventory instance. That is your problem. Since you want it to have multiple instance, delete InventoryInvs.
     
  6. Offline

    SneakyBruh

    How would i add the items to the inventory? Do i just search if the inventory name is ("§c§lSettings:")
     
  7. Offline

    Zombie_Striker

    @SneakyBruh
    Well, you should set all the items when the inventory is first created. You can store the instance locally, and set the items through that instance, but it should not be stored globally in a field.
     
  8. Offline

    SneakyBruh

    Omg. Thank you so much! I have one final problem tho. When i reload or restart the server it just empty's the inventory and doesn't load it back up?
    My HashMap:
    Code:
    staticMap<Player,Inventory> inventories = newHashMap<Player,Inventory>();
    
    Saving inv:
    Code:
    
    @EventHandler
    public void onClose(InventoryCloseEvent e){
    Player p = (Player) e.getPlayer();
    
        if(e.getInventory().getName().equals("§c§lSettings:")){
    
        Inventory invs = e.getInventory();
    
    inventories.put(p,invs);
    
        }
    
     
    Last edited: Oct 1, 2017
  9. Offline

    Zombie_Striker

    @SneakyBruh
    You do not need to store the inventory instance. The only time you need to get the inventory instances is when the player interacts with inventory, and you can get that by just checking if the titles are the same.
     
  10. Offline

    SneakyBruh

    Thanks so much! you have been such a good help <#
     
Thread Status:
Not open for further replies.

Share This Page