forked from Upstream/mmocore
Fixed skill list pagination
This commit is contained in:
parent
7d2af8d787
commit
1f344dbe02
@ -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.InventoryItem;
|
||||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
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.ClassSkill;
|
||||||
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -39,7 +37,6 @@ public class SkillList extends EditableInventory {
|
|||||||
if (function.equals("skill"))
|
if (function.equals("skill"))
|
||||||
return new SkillItem(config);
|
return new SkillItem(config);
|
||||||
|
|
||||||
|
|
||||||
if (function.equals("level"))
|
if (function.equals("level"))
|
||||||
return new LevelItem(config);
|
return new LevelItem(config);
|
||||||
|
|
||||||
@ -48,7 +45,7 @@ public class SkillList extends EditableInventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
|
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
|
||||||
RegisteredSkill selected = inv.selected==null?null:inv.selected.getSkill();
|
RegisteredSkill selected = inv.selected == null ? null : inv.selected.getSkill();
|
||||||
Placeholders holders = new Placeholders();
|
Placeholders holders = new Placeholders();
|
||||||
|
|
||||||
holders.register("skill_caps", selected.getName().toUpperCase());
|
holders.register("skill_caps", selected.getName().toUpperCase());
|
||||||
@ -57,7 +54,6 @@ public class SkillList extends EditableInventory {
|
|||||||
|
|
||||||
return holders;
|
return holders;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (function.equals("slot"))
|
if (function.equals("slot"))
|
||||||
@ -69,7 +65,7 @@ public class SkillList extends EditableInventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
|
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
|
||||||
RegisteredSkill selected = inv.selected==null?null:inv.selected.getSkill();
|
RegisteredSkill selected = inv.selected == null ? null : inv.selected.getSkill();
|
||||||
RegisteredSkill skill = inv.getPlayerData().hasSkillBound(n) ? inv.getPlayerData().getBoundSkill(n).getSkill() : null;
|
RegisteredSkill skill = inv.getPlayerData().hasSkillBound(n) ? inv.getPlayerData().getBoundSkill(n).getSkill() : null;
|
||||||
|
|
||||||
Placeholders holders = new Placeholders();
|
Placeholders holders = new Placeholders();
|
||||||
@ -77,7 +73,7 @@ public class SkillList extends EditableInventory {
|
|||||||
holders.register("skill", skill == null ? none : skill.getName());
|
holders.register("skill", skill == null ? none : skill.getName());
|
||||||
holders.register("index", "" + (n + 1));
|
holders.register("index", "" + (n + 1));
|
||||||
holders.register("slot", MMOCoreUtils.intToRoman(n + 1));
|
holders.register("slot", MMOCoreUtils.intToRoman(n + 1));
|
||||||
holders.register("selected", selected==null?none:selected.getName());
|
holders.register("selected", selected == null ? none : selected.getName());
|
||||||
|
|
||||||
return holders;
|
return holders;
|
||||||
}
|
}
|
||||||
@ -115,7 +111,8 @@ public class SkillList extends EditableInventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDisplay(SkillViewerInventory inv) {
|
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();
|
return NBTItem.get(item).addTag(new ItemTag("skillId", skill.getSkill().getHandler().getId())).toItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
|
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
|
||||||
return new Placeholders();
|
return new Placeholders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SkillItem extends InventoryItem<SkillViewerInventory> {
|
public class SkillItem extends InventoryItem<SkillViewerInventory> {
|
||||||
|
|
||||||
|
|
||||||
public SkillItem(ConfigurationSection config) {
|
public SkillItem(ConfigurationSection config) {
|
||||||
super(Material.BARRIER, config);
|
super(Material.BARRIER, config);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -197,11 +188,9 @@ public class SkillList extends EditableInventory {
|
|||||||
@Override
|
@Override
|
||||||
public ItemStack display(SkillViewerInventory inv, int n) {
|
public ItemStack display(SkillViewerInventory inv, int n) {
|
||||||
|
|
||||||
/*
|
// Calculate placeholders
|
||||||
* calculate placeholders
|
int index = n + inv.skillSlots.size() * inv.page;
|
||||||
*/
|
if (index >= inv.skills.size())
|
||||||
int index=n+inv.skillSlots.size()*inv.page;
|
|
||||||
if(index>=inv.skills.size())
|
|
||||||
return new ItemStack(Material.AIR);
|
return new ItemStack(Material.AIR);
|
||||||
|
|
||||||
ClassSkill skill = inv.skills.get(index);
|
ClassSkill skill = inv.skills.get(index);
|
||||||
@ -222,9 +211,7 @@ public class SkillList extends EditableInventory {
|
|||||||
for (int j = 0; j < lore.size(); j++)
|
for (int j = 0; j < lore.size(); j++)
|
||||||
lore.set(j, ChatColor.GRAY + holders.apply(inv.getPlayer(), lore.get(j)));
|
lore.set(j, ChatColor.GRAY + holders.apply(inv.getPlayer(), lore.get(j)));
|
||||||
|
|
||||||
/*
|
// Generate item
|
||||||
* generate item
|
|
||||||
*/
|
|
||||||
ItemStack item = skill.getSkill().getIcon();
|
ItemStack item = skill.getSkill().getIcon();
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName(holders.apply(inv.getPlayer(), getName()));
|
meta.setDisplayName(holders.apply(inv.getPlayer(), getName()));
|
||||||
@ -266,7 +253,7 @@ public class SkillList extends EditableInventory {
|
|||||||
skills = new ArrayList<>(playerData.getProfess().getSkills());
|
skills = new ArrayList<>(playerData.getProfess().getSkills());
|
||||||
skillSlots = getEditable().getByFunction("skill").getSlots();
|
skillSlots = getEditable().getByFunction("skill").getSlots();
|
||||||
slotSlots = getEditable().getByFunction("slot").getSlots();
|
slotSlots = getEditable().getByFunction("slot").getSlots();
|
||||||
selected=skills.get(page*skillSlots.size());
|
selected = skills.get(page * skillSlots.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user