Fixed issue #920 about placeholder API placeholders not working in skill-list.yml & fixed other bugs related to selected item in skill-list

This commit is contained in:
Ka0rX 2023-09-06 16:37:40 +01:00
parent 40b59e4b70
commit a794f81a5f
2 changed files with 36 additions and 3 deletions

View File

@ -108,15 +108,40 @@ public class SkillList extends EditableInventory {
public ItemStack display(SkillViewerInventory inv, int n) { public ItemStack display(SkillViewerInventory inv, int n) {
if (inv.selected == null) if (inv.selected == null)
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
return new ItemStack(inv.selected.getSkill().getIcon()); Placeholders holders = getPlaceholders(inv, n);
ItemStack item = new ItemStack(inv.selected.getSkill().getIcon());
ItemMeta meta = item.getItemMeta();
int skillLevel = inv.getPlayerData().getSkillLevel(inv.selected.getSkill());
List<String> lore = new ArrayList<>();
boolean unlocked = inv.selected.getUnlockLevel() <= inv.getPlayerData().getLevel();
for (String str : getLore()) {
if ((str.startsWith("{unlocked}") && !unlocked) || (str.startsWith("{locked}") && unlocked) || (str.startsWith("{max_level}") && (!inv.selected.hasMaxLevel() || inv.selected.getMaxLevel() > inv.getPlayerData().getSkillLevel(inv.selected.getSkill()))))
continue;
if (str.contains("{lore}"))
for (String loreLine : inv.selected.calculateLore(inv.getPlayerData()))
lore.add(ChatColor.GRAY + loreLine);
else
lore.add(holders.apply(inv.getPlayer(), str));
}
meta.setDisplayName(MMOCore.plugin.placeholderParser.parse(inv.getPlayer(), getName().replace("{skill}", inv.selected.getSkill().getName())
.replace("{roman}", MMOCoreUtils.intToRoman(skillLevel)).replace("{level}", "" + skillLevel)));
meta.addItemFlags(ItemFlag.values());
meta.setLore(lore);
item.setItemMeta(meta);
return item;
} }
@Override @Override
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
Placeholders holders = new Placeholders(); Placeholders holders = new Placeholders();
holders.register("selected", inv.selected.getSkill().getName()); holders.register("selected", inv.selected.getSkill().getName());
holders.register("skill", inv.selected.getSkill().getName());
holders.register("unlock", "" + inv.selected.getUnlockLevel());
holders.register("level", "" + inv.getPlayerData().getSkillLevel(inv.selected.getSkill()));
return holders; return holders;
} }
} }
public class LevelItem extends InventoryItem<SkillViewerInventory> { public class LevelItem extends InventoryItem<SkillViewerInventory> {
@ -149,11 +174,11 @@ public class SkillList extends EditableInventory {
lore.add(index + j, skillLore.get(j)); lore.add(index + j, skillLore.get(j));
for (int j = 0; j < lore.size(); j++) for (int j = 0; j < lore.size(); j++)
lore.set(j, ChatColor.GRAY + MythicLib.plugin.parseColors(lore.get(j))); lore.set(j, ChatColor.GRAY + MMOCore.plugin.placeholderParser.parse(inv.getPlayer(), lore.get(j)));
ItemStack item = new ItemStack(getMaterial()); ItemStack item = new ItemStack(getMaterial());
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(MythicLib.plugin.parseColors(getName().replace("{skill}", skill.getSkill().getName()) meta.setDisplayName(MMOCore.plugin.placeholderParser.parse(inv.getPlayer(), getName().replace("{skill}", skill.getSkill().getName())
.replace("{roman}", MMOCoreUtils.intToRoman(skillLevel)).replace("{level}", "" + skillLevel))); .replace("{roman}", MMOCoreUtils.intToRoman(skillLevel)).replace("{level}", "" + skillLevel)));
meta.addItemFlags(ItemFlag.values()); meta.addItemFlags(ItemFlag.values());
meta.setLore(lore); meta.setLore(lore);

View File

@ -97,3 +97,11 @@ items:
- '&7Costs 1 skill point.' - '&7Costs 1 skill point.'
- '' - ''
- '&eCurrent Skill Points: {skill_points}' - '&eCurrent Skill Points: {skill_points}'
#This will display the selected item in the skill UI.
# selected:
# slots: []
# function: selected
# name: '&a{skill} &6[{level}]'
# lore:
# - ''
# - '{lore}'