Hello, I am having a problem with the Pagination#setItems method.
I will provide the code:
@Override public void init(Player player, InventoryContents contents) {
Pagination pagination = contents.pagination();
List<ClientedPlayer> registry = main.getManager().getRegistry(targetNickname);
ClickableItem[] items = new ClickableItem[registry.size()];
//Creating item (this will loop two times)
for (int i = 0; i < registry.size(); i++) {
ClientedPlayer iterationPlayer = registry.get(i);
Bukkit.broadcastMessage("NEW ITEM");
items[i] = ClickableItem.of(ItemType.formatItem(iterationPlayer), onClick -> {
new ClientInventory(player, iterationPlayer, main).open();
});
//On the first iteration it will print a DATE, and on the second it will say "CONECTADO" Till here, everything is OK.
//This VERIFIES the item was created correctly
Bukkit.broadcastMessage("ITEM SAVED: " + items[i].getItem().getItemMeta().getLore().get(5));
}
// Notice these lines being printed on the console showing that the lines at index 5 ARE BOTH IN GREEN SAYING "CONECTADO"
// In the loop comment we said only the SECOND iteration (index 1 of the array) will print "CONECTADO". But here we see it's being printed both times.
Bukkit.broadcastMessage("OUT OF LOOP FIRST ITEM: " + items[0].getItem().getItemMeta().getLore().get(5));
Bukkit.broadcastMessage("OUT OF LOOP SECOND ITEM: " + items[1].getItem().getItemMeta().getLore().get(5));
pagination.setItems(items);
pagination.setItemsPerPage(8);
pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 0, 0));
The problem here, is that the items are the same. In the slot 0, the lore should contain a DATE in LIGHT_RED. But instead, it says "CONECTADO" in GREEN.
I kept the debug, to verify the problem is not in my end (or at least that is what I think).
As you can see, all is working well inside the loop.
I find it pretty strange, as it duplicates outside the loop, when it is finished.
The last two broadcast messages are driving me crazy, I cannot figure out what is happening. Everything works well until the loop finishes...
I have even contacted a friend of mine, and he could not figure it out either.
Here are the debugs and the problem in video:
And this is how it SHOULD BE:
Thanks, and sorry if I am missing something, I have been dealing with this problem 3 hours xD
Hello, I am having a problem with the
Pagination#setItems
method.I will provide the code:
The problem here, is that the items are the same. In the slot 0, the lore should contain a DATE in LIGHT_RED. But instead, it says "CONECTADO" in GREEN. I kept the debug, to verify the problem is not in my end (or at least that is what I think). As you can see, all is working well inside the loop. I find it pretty strange, as it duplicates outside the loop, when it is finished. The last two broadcast messages are driving me crazy, I cannot figure out what is happening. Everything works well until the loop finishes... I have even contacted a friend of mine, and he could not figure it out either.
Here are the debugs and the problem in video:
And this is how it SHOULD BE:
Thanks, and sorry if I am missing something, I have been dealing with this problem 3 hours xD