Fixed error message when the class doesn't have any skills.

This commit is contained in:
Ka0rX 2023-04-02 20:02:56 +01:00
parent 8ce90c3363
commit c64b88e36d

View File

@ -68,21 +68,21 @@ public class SkillList extends EditableInventory {
return new SlotItem(config) { return new SlotItem(config) {
@Override @Override
public ItemStack display(SkillViewerInventory inv, int n) { public ItemStack display(SkillViewerInventory inv, int n) {
if (!inv.getPlayerData().getProfess().hasSlot(n+1)) { if (!inv.getPlayerData().getProfess().hasSlot(n + 1)) {
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
} }
SkillSlot skillSlot = inv.getPlayerData().getProfess().getSkillSlot(n+1); SkillSlot skillSlot = inv.getPlayerData().getProfess().getSkillSlot(n + 1);
ItemStack item = super.display(inv, n); ItemStack item = super.display(inv, n);
if (!inv.getPlayerData().hasSkillBound(n+1)) { if (!inv.getPlayerData().hasSkillBound(n + 1)) {
//If there is an item filled in the slot config it shows it, else shows the default item. //If there is an item filled in the slot config it shows it, else shows the default item.
Material material = skillSlot.hasItem() ? skillSlot.getItem() : super.emptyMaterial; Material material = skillSlot.hasItem() ? skillSlot.getItem() : super.emptyMaterial;
int customModelData = skillSlot.hasItem() ? skillSlot.getModelData() : super.emptyCMD; int customModelData = skillSlot.hasItem() ? skillSlot.getModelData() : super.emptyCMD;
item.setType(material); item.setType(material);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(MMOCore.plugin.placeholderParser.parse(inv.getPlayerData().getPlayer(),skillSlot.getName())); meta.setDisplayName(MMOCore.plugin.placeholderParser.parse(inv.getPlayerData().getPlayer(), skillSlot.getName()));
List<String> lore=skillSlot.getLore() List<String> lore = skillSlot.getLore()
.stream() .stream()
.map(str->MMOCore.plugin.placeholderParser.parse(inv.getPlayerData().getPlayer(),str)) .map(str -> MMOCore.plugin.placeholderParser.parse(inv.getPlayerData().getPlayer(), str))
.collect(Collectors.toList()); .collect(Collectors.toList());
meta.setLore(lore); meta.setLore(lore);
if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13)) { if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13)) {
@ -102,7 +102,7 @@ public class SkillList extends EditableInventory {
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
Placeholders holders = super.getPlaceholders(inv, n); Placeholders holders = super.getPlaceholders(inv, n);
String none = MythicLib.plugin.parseColors(config.getString("no-skill")); String none = MythicLib.plugin.parseColors(config.getString("no-skill"));
RegisteredSkill skill = inv.getPlayerData().hasSkillBound(n+1) ? inv.getPlayerData().getBoundSkill(n+1).getSkill() : null; RegisteredSkill skill = inv.getPlayerData().hasSkillBound(n + 1) ? inv.getPlayerData().getBoundSkill(n + 1).getSkill() : null;
holders.register("skill", skill == null ? none : skill.getName()); holders.register("skill", skill == null ? none : skill.getName());
return holders; return holders;
} }
@ -324,12 +324,13 @@ public class SkillList extends EditableInventory {
super(playerData, editable); super(playerData, editable);
skills = playerData.getProfess().getSkills() skills = playerData.getProfess().getSkills()
.stream() .stream()
.filter((classSkill)->playerData.hasUnlocked(classSkill.getSkill())) .filter((classSkill) -> playerData.hasUnlocked(classSkill.getSkill()))
.collect(Collectors.toList()); .collect(Collectors.toList());
skillSlots = getEditable().getByFunction("skill").getSlots(); skillSlots = getEditable().getByFunction("skill").getSlots();
Validate.notNull(getEditable().getByFunction("slot"), "Your skill GUI config file is out-of-date, please regenerate it."); Validate.notNull(getEditable().getByFunction("slot"), "Your skill GUI config file is out-of-date, please regenerate it.");
slotSlots = getEditable().getByFunction("slot").getSlots(); slotSlots = getEditable().getByFunction("slot").getSlots();
selected = skills.get(page * skillSlots.size()); if (skills.size() > page * skillSlots.size())
selected = skills.get(page * skillSlots.size());
} }
@Override @Override
@ -397,8 +398,8 @@ public class SkillList extends EditableInventory {
* binding or unbinding skills. * binding or unbinding skills.
*/ */
if (item.getFunction().equals("slot")) { if (item.getFunction().equals("slot")) {
int index = slotSlots.indexOf(context.getSlot())+1; int index = slotSlots.indexOf(context.getSlot()) + 1;
SkillSlot skillSlot=playerData.getProfess().getSkillSlot(index); SkillSlot skillSlot = playerData.getProfess().getSkillSlot(index);
// unbind if there is a current spell. // unbind if there is a current spell.
if (context.getClickType() == ClickType.RIGHT) { if (context.getClickType() == ClickType.RIGHT) {
if (!playerData.hasSkillBound(index)) { if (!playerData.hasSkillBound(index)) {
@ -421,7 +422,7 @@ public class SkillList extends EditableInventory {
return; return;
} }
if(!skillSlot.canPlaceSkill(selected)){ if (!skillSlot.canPlaceSkill(selected)) {
MMOCore.plugin.configManager.getSimpleMessage("not-compatible-skill").send(player); MMOCore.plugin.configManager.getSimpleMessage("not-compatible-skill").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
return; return;