# Solved List of items and sort into a inventory

Discussion in 'Spigot Plugin Development' started by matgsan, Jun 23, 2016.

1. ### matgsan

Hey guys,
I am trying to figure out how can i sort a List of items into a inventory!
For example i have a List with 4 items and i want to display them with a blank line int the first row, and then in the second row sort them like: BLANK, ITEM, BLANK, ITEM,BLANK, ITEM, BLANK.
As my english is so bad i will try to post a picture here to help you guys

and then if i have a list with for example 8 items add then under those in the image and add a new blank row in the bottom

2. ### Hunky524

Get your item count, for every four items, add another row to your inventory (don't go over 6 rows). Use a for-loop starting at 10 and ending at your inventory size minus one. In the for-loop, place an item in whatever slot the for-loop is on and increment the counter by two every run.

3. ### matgsan

the second item row should be one slot right

@EDIT
Solved -
I just check if the slot was 16,25,34 or 44 and if true increment 3 not 2

#3
Last edited: Jun 23, 2016
4. ### Hunky524

Oh shit I messed up a bit, yea. At the beginning of the for-loop have a quick check to see if the slot number evenly divides into nine. If it does, increment the for-loop counter by one, place an item at the slot number held by the for-loop counter, then use "continue;" to skip the rest of the for-loop. Make sure you do it in that order.

The operation to check divisibility is:
Code (Text):
x % y
If it's 0, that means is it evenly divisible. If it's 1, that means it is not evenly divisible.

5. ### matgsan

i did something similar

i am having trouble now in the first part of the code
if the "categorias" variable is 7 for example, when divided by 4 returns 1, but should be 2 because i will need 2 rows to fit 7 items

6. ### Hunky524

Use Math.ceil(categories/4);

7. ### matgsan

I already tried that, but also returns 1.0

8. ### Hunky524

I guess I should point out it does not work with integers becauae they round themselves before anything else.

It will work if you convert the lower number to a double then cast the entire thing to an int.

Here is a StackOverflow thread for this issue: http://stackoverflow.com/questions/4540684/java-round-up-any-number

#8
Last edited: Jun 23, 2016
9. ### matgsan

Ya my bad i solved the problem!
Thank you bro