From 1d1d28958fb887362a8f63bdb643a94f6ea65001 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 19 Mar 2023 20:20:24 +0100 Subject: [PATCH] Bug Fixing --- .../net/Indyuce/mmocore/api/player/PlayerData.java | 5 +++-- .../api/player/profess/skillbinding/SkillSlot.java | 7 ++++--- .../main/java/net/Indyuce/mmocore/gui/SkillList.java | 12 +++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index df27d52e..886702f5 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -1140,11 +1140,12 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public boolean hasSkillBound(int slot) { - return slot < boundSkills.size(); + Bukkit.broadcastMessage("slot:"+slot+" "+boundSkills.containsKey(slot)); + return boundSkills.containsKey(slot); } public ClassSkill getBoundSkill(int slot) { - return slot >= boundSkills.size() ? null : boundSkills.get(slot).getClassSkill(); + return boundSkills.containsKey(slot) ? boundSkills.get(slot).getClassSkill():null; } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java index b3dc33c5..a1853363 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/skillbinding/SkillSlot.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.api.player.profess.skillbinding; +import bsh.EvalError; import io.lumine.mythic.lib.MythicLib; import net.Indyuce.mmocore.comp.mythicmobs.MythicHook; import net.Indyuce.mmocore.skill.ClassSkill; @@ -27,7 +28,7 @@ public class SkillSlot { public SkillSlot(ConfigurationSection section) { this.slot = Integer.parseInt(section.getName()); - this.expression = section.getString("expression"); + this.expression = section.contains("expression") ? section.getString("expression") : "true"; this.name = section.getString("name"); this.lore = section.getStringList("lore"); if (section.contains("item")) @@ -66,9 +67,9 @@ public class SkillSlot { parsedExpression = parsedExpression.replace("<" + category + ">", "true"); parsedExpression = parsedExpression.replaceAll("<.*>", "false"); try { - boolean res = (boolean) MythicLib.plugin.getScriptEngine().eval(parsedExpression); + boolean res = (boolean) MythicLib.plugin.getInterpreter().eval(parsedExpression); return res; - } catch (ScriptException e) { + } catch (EvalError e) { throw new RuntimeException(e); } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index 3061afb9..b0b4b5be 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -17,6 +17,7 @@ import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.api.SoundEvent; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; @@ -67,12 +68,12 @@ public class SkillList extends EditableInventory { return new SlotItem(config) { @Override public ItemStack display(SkillViewerInventory inv, int n) { - if (!inv.getPlayerData().getProfess().hasSlot(n)) { + if (!inv.getPlayerData().getProfess().hasSlot(n+1)) { return new ItemStack(Material.AIR); } - SkillSlot skillSlot = inv.getPlayerData().getProfess().getSkillSlot(n); + SkillSlot skillSlot = inv.getPlayerData().getProfess().getSkillSlot(n+1); ItemStack item = super.display(inv, n); - if (!inv.getPlayerData().hasSkillBound(n)) { + 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; @@ -101,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) ? inv.getPlayerData().getBoundSkill(n).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; } @@ -394,7 +395,7 @@ public class SkillList extends EditableInventory { * binding or unbinding skills. */ if (item.getFunction().equals("slot")) { - int index = slotSlots.indexOf(context.getSlot()); + 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) { @@ -427,6 +428,7 @@ public class SkillList extends EditableInventory { player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); playerData.bindSkill(index, selected); + Bukkit.broadcastMessage("SKILL BOUND: "+index); open(); return; }