Working with ArrayList<Inventory>

Discussion in 'Spigot Plugin Development' started by Ean244, Jun 8, 2017.

  1. Im working on a plugin that has multiple inventories that players can view.The inventories are stored in an arraylist.Players add items into it by using commands. If it is full a new inventory would be created.Players can choose the inventory they want to look at by clicking itemstacks.The problem is when i created a new inventory it seems to be the same as the first inventory.

    Code to create new inventory when the previous inv is full(its in a command):
    Code (Text):
    if(array_inv.get(array_inv.size()-1).firstEmpty() == -1) {
                                array_inv.add(Bukkit.createInventory(null, 54));
    //note: init is just inserting items into the inventory given in param
    code to let players view different inventories(note: its in an InventoryClickEvent):
    i = event itemstack
    hash_player = a hashmap that stores player uuid and an int(the page he/she is viewing, default = 0)
    Code (Text):
    if (i.equals(next)) {
                        int max = array_inv.size() -1;
                        int now = hash_player.get(localPlayer.getUniqueId());
                        if (max - now > 0) {
                           array_player.put(localPlayer.getUniqueId(), now);
                        } else {
    #1 Ean244, Jun 8, 2017
    Last edited: Jun 8, 2017
  2. I'm not a java expert and I may be wrong, but it looks like you're just calling the same inventory event again even when full? (is that your issue).
  3. Its in a command sry not to tell
  4. Show your init method?