Fixed skill list pagination

This commit is contained in:
Indyuce 2022-05-24 15:27:03 +02:00
parent 7d2af8d787
commit 1f344dbe02

View File

@ -11,10 +11,8 @@ import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.manager.SkillManager;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -39,7 +37,6 @@ public class SkillList extends EditableInventory {
if (function.equals("skill"))
return new SkillItem(config);
if (function.equals("level"))
return new LevelItem(config);
@ -57,7 +54,6 @@ public class SkillList extends EditableInventory {
return holders;
}
};
if (function.equals("slot"))
@ -115,7 +111,8 @@ public class SkillList extends EditableInventory {
@Override
public boolean canDisplay(SkillViewerInventory inv) {
return inv.page < inv.skills.size() / 12;
final int perPage = inv.skillSlots.size();
return inv.page < (inv.skills.size() - 1) / perPage;
}
};
}
@ -172,21 +169,15 @@ public class SkillList extends EditableInventory {
return NBTItem.get(item).addTag(new ItemTag("skillId", skill.getSkill().getHandler().getId())).toItem();
}
@Override
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
return new Placeholders();
}
}
public class SkillItem extends InventoryItem<SkillViewerInventory> {
public SkillItem(ConfigurationSection config) {
super(Material.BARRIER, config);
}
@Override
@ -197,9 +188,7 @@ public class SkillList extends EditableInventory {
@Override
public ItemStack display(SkillViewerInventory inv, int n) {
/*
* calculate placeholders
*/
// Calculate placeholders
int index = n + inv.skillSlots.size() * inv.page;
if (index >= inv.skills.size())
return new ItemStack(Material.AIR);
@ -222,9 +211,7 @@ public class SkillList extends EditableInventory {
for (int j = 0; j < lore.size(); j++)
lore.set(j, ChatColor.GRAY + holders.apply(inv.getPlayer(), lore.get(j)));
/*
* generate item
*/
// Generate item
ItemStack item = skill.getSkill().getIcon();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(holders.apply(inv.getPlayer(), getName()));