1.15.2 Viewing massive amounts of items

Discussion in 'Spigot Plugin Development' started by hidden1nin, Mar 1, 2020.

  1. What would be the best way to view an itemstack[] in an inventory with more items than storage slots? i'll be using this for a massive storage system.
  2. FrostedSnowman

    Resource Staff

    One option is to create a pagination system. This will essentially hold indexes (or pages) of items for you. The idea is that you have some underlying collection or dataset with all of your elements or data-- this will then be partitioned up into sections. For an inventory, with maximum slots, it'd be sections of 54 elements.

    Guava, already included in Spigot, provides a utility method for partitioning lists.

    For example, if you have 109 items in total, by partitioning your data into sections of 54, you will get 3 lists of data: the first 2 being entirely populated with 54 elements (108 items in total), and the third list having the remaining single element.

    There is more about the functionality in the Javadoc provided.
  3. how can one divide a list? like i want to divide my list into lists that contain indexes each?
  4. FrostedSnowman

    Resource Staff

    I linked you to a library already included in Spigot that allows you to divide or partition a list: Lists::partition

    This will return a List<List<T>> where the inner would be your elements, and the outerlist would be the partition of elements or 'pages' of elements. For example, assuming your data actually has elements:

    Code (Java):
    int inventorySize = 54;
    List<List<ItemStack>> pages = Lists.partition(data, inventorySize);

    List<ItemStack> page1 = pages.get(0);
    You'd then populate your inventory with the page's items. To actually 'see' each page, you'll need to create some sort of 'next' or 'previous' button that will grab the items for a specific page.
  5. Code (Java):
    ArrayList<ItemStack> items = new ArrayList<ItemStack>();
                            Chest chest = (Chest) loc.getBlock().getState();
                            for(ItemStack i:chest.getInventory().getContents()) {
                                if(i!=null) {
                                player.sendMessage("added "+i.getType().toString()+x+y+z);
    }// to add the items

    i can't find the import for the .partition please help
    i don't know what to do from here
    #5 hidden1nin, Mar 2, 2020
    Last edited: Mar 2, 2020
  6. You don't even have it in your code... It's Lists.partition(array, quantity per page)
  7. I tried that but all i could find was an import from google.
  8. because it's import from google, dude.
    • Funny Funny x 1