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