ποΈSlotIterator
Here you will find all the methods that are in the SlotIterator class.
The SlotIterator class is only used in conjunction with Pagination.
Create SlotIterator
Call
SlotIterator#builder
. With this you call the builder of the SlotIterator, this offers you the setting options.
pagination.iterator(SlotIterator.builder()
.startPosition(0)
.blackList(2)
.override()
.endPosition(5)
.type(SlotIterator.SlotIteratorType.HORIZONTAL)
.build());
This is how a simpler SlotIterator could look like. There is another way to create a SlotIterator, but more about that later. A short description of what the code does exactly:
We define the start position (where he should start placing the items).
We define slots that he should ignore.
We say that he should still place the item even though there is already an item there.
We say he should stop at slot 5.
We tell him to place the items horizontally.
Create SlotIterator based on Pattern
The pattern system works only for EnderChest or a normal chest!
Sometimes you want to have a certain design. Using the pattern system, you can create your desired inventory without having to remember hundreds of different numbers.
Das Pattern kann wie folgt aussehen:
In the SlotIterator Builder we call the
#withPattern
method.With
#define
we define our pattern. In this case I have the pattern "OOXXXXXXX". After that I wrote a 6. I have an inventory with 6 rows and in all 6 rows this pattern is valid. As a result, you don't have to put "OOXXXXXXX" 6x into the method.With
#attach
we say, to which character in the pattern should the items be attached? In this case I said 'O'. That means always the first 2 slots in a row are filled.
RyseInventory.builder()
.title("Example")
.rows(6)
.provider(new InventoryProvider() {
@Override
public void init(Player player, InventoryContents contents) {
Pagination pagination = contents.pagination();
pagination.setItemsPerPage(30);
pagination.iterator(SlotIterator.builder().withPattern(SlotIteratorPattern.builder()
.define("OOXXXXXXX", 6)
.attach('O')
.buildPattern())
.build());
for (int i = 0; i < 12; i++) {
pagination.addItem(IntelligentItem.empty(new ItemStack(Material.MAGMA_CREAM)));
}
}
})
.build(this)
.openAll();
This is how the pattern looks in action:
As you can see due to the pattern and the 'O' only there items are placed.
Furthermore, we see that we have 12 Magma Creams there. This is because we added 12 Magma Creams at the top using the Pagination#addItem method. If we added only 10 Magma Creams, the last row would be completely empty.
Method overview
builder
Calls a new SlotIterator Builder object.
copy
You can pass an already existing SlotIterator object. The properties will be taken over.
blackList
You want some slots to be ignored? Then transfer the slots and no items will be placed there.
endPosition
Here you specify the last slot where he should stop placing items. Attention! If you use this method the entry in Pagination#setItemsPerPage will be ignored.
startPosition
Defines where the first item should be placed. From there it proceeds based on the type.
withPattern
The items can be placed based on a pattern you specify.
type
Definiert wie die Items platziert werden sollen, entweder Vertikal oder Horizontal.
override
If this method was called, it is no longer checked within the slot whether an item is already there. The item is simply overwritten with the new item.
Last updated