From ddf041aa30dce708afd0a058217811ea84f83b9c Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 28 May 2023 06:59:08 +0100 Subject: [PATCH] Fixed issue related to wrong display for skill tree paths. --- .../comp/placeholder/RPGPlaceholders.java | 358 ++++++++---------- .../gui/skilltree/SkillTreeViewer.java | 8 +- .../mmocore/skilltree/tree/SkillTree.java | 4 + 3 files changed, 175 insertions(+), 195 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java index 69dd6de0..df5b4239 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java @@ -12,12 +12,12 @@ import net.Indyuce.mmocore.api.quest.PlayerQuests; import net.Indyuce.mmocore.experience.PlayerProfessions; import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.party.AbstractParty; +import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Player; import javax.annotation.Nullable; @@ -26,47 +26,47 @@ import java.util.UUID; public class RPGPlaceholders extends PlaceholderExpansion { - @Override - public boolean persist() { - return true; - } + @Override + public boolean persist() { + return true; + } - @Override - public boolean canRegister() { - return true; - } + @Override + public boolean canRegister() { + return true; + } - @Override - public String getAuthor() { - return "Indyuce"; - } + @Override + public String getAuthor() { + return "Indyuce"; + } - @Override - public String getIdentifier() { - return "mmocore"; - } + @Override + public String getIdentifier() { + return "mmocore"; + } - @Override - public String getVersion() { - return MMOCore.plugin.getDescription().getVersion(); - } + @Override + public String getVersion() { + return MMOCore.plugin.getDescription().getVersion(); + } private static final String ERROR_PLACEHOLDER = " "; - @SuppressWarnings("DuplicateExpressions") - @Override - public String onRequest(OfflinePlayer player, String identifier) { - if (!PlayerData.has(player.getUniqueId())) - return null; + @SuppressWarnings("DuplicateExpressions") + @Override + public String onRequest(OfflinePlayer player, String identifier) { + if (!PlayerData.has(player.getUniqueId())) + return null; - PlayerData playerData = PlayerData.get(player); - if (identifier.equals("mana_icon")) - return playerData.getProfess().getManaDisplay().getIcon(); - if (identifier.equals("mana_name")) - return playerData.getProfess().getManaDisplay().getName(); + PlayerData playerData = PlayerData.get(player); + if (identifier.equals("mana_icon")) + return playerData.getProfess().getManaDisplay().getIcon(); + if (identifier.equals("mana_name")) + return playerData.getProfess().getManaDisplay().getName(); - if (identifier.equals("level")) - return String.valueOf(playerData.getLevel()); + if (identifier.equals("level")) + return String.valueOf(playerData.getLevel()); else if (identifier.startsWith("skill_level_")) { String id = identifier.substring(12); @@ -90,62 +90,60 @@ public class RPGPlaceholders extends PlaceholderExpansion { } else if (identifier.equals("health")) return StatManager.format("MAX_HEALTH", player.getPlayer().getHealth()); - else if (identifier.equals("max_health")) - return StatManager.format("MAX_HEALTH", player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + else if (identifier.equals("max_health")) + return StatManager.format("MAX_HEALTH", player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - else if (identifier.equals("health_bar") && player.isOnline()) { - StringBuilder format = new StringBuilder(); - double ratio = 20 * player.getPlayer().getHealth() / player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); - for (double j = 1; j < 20; j++) - format.append(ratio >= j ? ChatColor.RED : ratio >= j - .5 ? ChatColor.DARK_RED : ChatColor.DARK_GRAY).append(AltChar.listSquare); - return format.toString(); - } else if (identifier.equals("class")) - return playerData.getProfess().getName(); + else if (identifier.equals("health_bar") && player.isOnline()) { + StringBuilder format = new StringBuilder(); + double ratio = 20 * player.getPlayer().getHealth() / player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + for (double j = 1; j < 20; j++) + format.append(ratio >= j ? ChatColor.RED : ratio >= j - .5 ? ChatColor.DARK_RED : ChatColor.DARK_GRAY).append(AltChar.listSquare); + return format.toString(); + } else if (identifier.equals("class")) + return playerData.getProfess().getName(); - else if (identifier.startsWith("profession_percent_")) { - PlayerProfessions professions = playerData.getCollectionSkills(); - String name = identifier.substring(19).replace(" ", "-").replace("_", "-").toLowerCase(); - Profession profession = MMOCore.plugin.professionManager.get(name); - double current = professions.getExperience(profession), next = professions.getLevelUpExperience(profession); - return MythicLib.plugin.getMMOConfig().decimal.format(current / next * 100); + else if (identifier.startsWith("profession_percent_")) { + PlayerProfessions professions = playerData.getCollectionSkills(); + String name = identifier.substring(19).replace(" ", "-").replace("_", "-").toLowerCase(); + Profession profession = MMOCore.plugin.professionManager.get(name); + double current = professions.getExperience(profession), next = professions.getLevelUpExperience(profession); + return MythicLib.plugin.getMMOConfig().decimal.format(current / next * 100); - } else if (identifier.equals("is_casting")) - return String.valueOf(playerData.isCasting()); + } else if (identifier.equals("is_casting")) + return String.valueOf(playerData.isCasting()); - else if (identifier.equals("in_combat")) - return String.valueOf(playerData.isInCombat()); + else if (identifier.equals("in_combat")) + return String.valueOf(playerData.isInCombat()); - else if (identifier.equals("pvp_mode")) - return String.valueOf(playerData.getCombat().isInPvpMode()); + else if (identifier.equals("pvp_mode")) + return String.valueOf(playerData.getCombat().isInPvpMode()); - else if (identifier.startsWith("since_enter_combat")) - return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getLastEntry()) / 1000.) : "-1"; + else if (identifier.startsWith("since_enter_combat")) + return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getLastEntry()) / 1000.) : "-1"; - else if (identifier.startsWith("invulnerability_left")) - return MythicLib.plugin.getMMOConfig().decimal.format(Math.max(0, (playerData.getCombat().getInvulnerableTill() - System.currentTimeMillis()) / 1000.)); + else if (identifier.startsWith("invulnerability_left")) + return MythicLib.plugin.getMMOConfig().decimal.format(Math.max(0, (playerData.getCombat().getInvulnerableTill() - System.currentTimeMillis()) / 1000.)); - else if (identifier.startsWith("since_last_hit")) - return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getLastHit()) / 1000.) : "-1"; + else if (identifier.startsWith("since_last_hit")) + return playerData.isInCombat() ? MythicLib.plugin.getMMOConfig().decimal.format((System.currentTimeMillis() - playerData.getCombat().getLastHit()) / 1000.) : "-1"; - else if (identifier.startsWith("bound_")) { - int slot = Math.max(0, Integer.parseInt(identifier.substring(6))); - return playerData.hasSkillBound(slot) ? playerData.getBoundSkill(slot).getSkill().getName() - : MMOCore.plugin.configManager.noSkillBoundPlaceholder; + else if (identifier.startsWith("bound_")) { + int slot = Math.max(0, Integer.parseInt(identifier.substring(6))); + return playerData.hasSkillBound(slot) ? playerData.getBoundSkill(slot).getSkill().getName() + : MMOCore.plugin.configManager.noSkillBoundPlaceholder; - } else if (identifier.startsWith("profession_experience_")) - return MythicLib.plugin.getMMOConfig().decimal.format( - playerData.getCollectionSkills().getExperience(identifier.substring(22).replace(" ", "-").replace("_", "-").toLowerCase())); + } else if (identifier.startsWith("profession_experience_")) + return MythicLib.plugin.getMMOConfig().decimal.format( + playerData.getCollectionSkills().getExperience(identifier.substring(22).replace(" ", "-").replace("_", "-").toLowerCase())); - else if (identifier.startsWith("profession_next_level_")) - return String.valueOf(PlayerData.get(player).getCollectionSkills() - .getLevelUpExperience(identifier.substring(22).replace(" ", "-").replace("_", "-").toLowerCase())); + else if (identifier.startsWith("profession_next_level_")) + return String.valueOf(PlayerData.get(player).getCollectionSkills() + .getLevelUpExperience(identifier.substring(22).replace(" ", "-").replace("_", "-").toLowerCase())); - else if (identifier.startsWith("party_count")) { - final @Nullable AbstractParty party = playerData.getParty(); - return party == null ? "0" : String.valueOf(party.countMembers()); - } - - else if (identifier.startsWith("party_member_")) { + else if (identifier.startsWith("party_count")) { + final @Nullable AbstractParty party = playerData.getParty(); + return party == null ? "0" : String.valueOf(party.countMembers()); + } else if (identifier.startsWith("party_member_")) { final int n = Integer.parseInt(identifier.substring(13)) - 1; final @Nullable AbstractParty party = playerData.getParty(); if (party == null) return ERROR_PLACEHOLDER; @@ -153,129 +151,107 @@ public class RPGPlaceholders extends PlaceholderExpansion { final @Nullable PlayerData member = party.getMember(n); if (member == null) return ERROR_PLACEHOLDER; return member.getPlayer().getName(); - } - - else if (identifier.equals("online_friends")) { + } else if (identifier.equals("online_friends")) { int count = 0; for (UUID friendId : playerData.getFriends()) if (Bukkit.getPlayer(friendId) != null) count++; return String.valueOf(count); - } - - else if (identifier.startsWith("online_friend_")) { + } else if (identifier.startsWith("online_friend_")) { final int n = Integer.parseInt(identifier.substring(14)) - 1; if (n >= playerData.getFriends().size()) return ERROR_PLACEHOLDER; final @Nullable Player friend = Bukkit.getPlayer(playerData.getFriends().get(n)); if (friend == null) return ERROR_PLACEHOLDER; return friend.getName(); + } else if (identifier.startsWith("profession_")) + return String + .valueOf(playerData.getCollectionSkills().getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase())); + + else if (identifier.equals("experience")) + return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getExperience()); + + else if (identifier.equals("next_level")) + return String.valueOf(playerData.getLevelUpExperience()); + + else if (identifier.equals("class_points")) + return String.valueOf(playerData.getClassPoints()); + + else if (identifier.equals("skill_points")) + return String.valueOf(playerData.getSkillPoints()); + + else if (identifier.equals("attribute_points")) + return String.valueOf(playerData.getAttributePoints()); + + else if (identifier.equals("attribute_reallocation_points")) + return String.valueOf(playerData.getAttributeReallocationPoints()); + + else if (identifier.startsWith("attribute_")) + return String.valueOf(playerData.getAttributes() + .getAttribute(MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-")))); + + else if (identifier.equals("mana")) + return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getMana()); + + else if (identifier.equals("mana_bar")) + return playerData.getProfess().getManaDisplay().generateBar(playerData.getMana(), playerData.getStats().getStat("MAX_MANA")); + + else if (identifier.startsWith("exp_multiplier_")) { + String format = identifier.substring(15).toLowerCase().replace("_", "-").replace(" ", "-"); + Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format); + return MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.boosterManager.getMultiplier(profession) * 100); + } else if (identifier.startsWith("exp_boost_")) { + String format = identifier.substring(10).toLowerCase().replace("_", "-").replace(" ", "-"); + Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format); + return MythicLib.plugin.getMMOConfig().decimal.format((MMOCore.plugin.boosterManager.getMultiplier(profession) - 1) * 100); + } else if (identifier.equals("stamina")) + return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getStamina()); + + else if (identifier.equals("stamina_bar")) { + StringBuilder format = new StringBuilder(); + double ratio = 20 * playerData.getStamina() / playerData.getStats().getStat("MAX_STAMINA"); + for (double j = 1; j < 20; j++) + format.append(ratio >= j ? MMOCore.plugin.configManager.staminaFull + : ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf : MMOCore.plugin.configManager.staminaEmpty) + .append(AltChar.listSquare); + return format.toString(); + } else if (identifier.startsWith("stat_")) { + final String stat = UtilityMethods.enumName(identifier.substring(5)); + return StatManager.format(stat, playerData.getMMOPlayerData()); + } else if (identifier.equals("stellium")) + return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getStellium()); + + else if (identifier.equals("stellium_bar")) { + StringBuilder format = new StringBuilder(); + double ratio = 20 * playerData.getStellium() / playerData.getStats().getStat("MAX_STELLIUM"); + for (double j = 1; j < 20; j++) + format.append(ratio >= j ? ChatColor.BLUE : ratio >= j - .5 ? ChatColor.AQUA : ChatColor.WHITE).append(AltChar.listSquare); + return format.toString(); + } else if (identifier.equals("quest")) { + PlayerQuests data = playerData.getQuestData(); + return data.hasCurrent() ? data.getCurrent().getQuest().getName() : "None"; + } else if (identifier.equals("quest_progress")) { + PlayerQuests data = playerData.getQuestData(); + return data.hasCurrent() ? MythicLib.plugin.getMMOConfig().decimal + .format((double) data.getCurrent().getObjectiveNumber() / data.getCurrent().getQuest().getObjectives().size() * 100L) : "0"; + } else if (identifier.equals("quest_objective")) { + PlayerQuests data = playerData.getQuestData(); + return data.hasCurrent() ? data.getCurrent().getFormattedLore() : "None"; + } else if (identifier.startsWith("guild_")) { + String placeholder = identifier.substring(6); + if (playerData.getGuild() == null) + return ""; + + if (placeholder.equalsIgnoreCase("name")) + return playerData.getGuild().getName(); + else if (placeholder.equalsIgnoreCase("tag")) + return playerData.getGuild().getTag(); + else if (placeholder.equalsIgnoreCase("leader")) + return Bukkit.getOfflinePlayer(playerData.getGuild().getOwner()).getName(); + else if (placeholder.equalsIgnoreCase("members")) + return String.valueOf(playerData.getGuild().countMembers()); + else if (placeholder.equalsIgnoreCase("online_members")) + return String.valueOf(playerData.getGuild().countOnlineMembers()); } - else if (identifier.startsWith("profession_")) - return String - .valueOf(playerData.getCollectionSkills().getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase())); - - else if (identifier.equals("experience")) - return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getExperience()); - - else if (identifier.equals("next_level")) - return String.valueOf(playerData.getLevelUpExperience()); - - else if (identifier.equals("class_points")) - return String.valueOf(playerData.getClassPoints()); - - else if (identifier.equals("skill_points")) - return String.valueOf(playerData.getSkillPoints()); - - else if (identifier.equals("attribute_points")) - return String.valueOf(playerData.getAttributePoints()); - - else if (identifier.equals("attribute_reallocation_points")) - return String.valueOf(playerData.getAttributeReallocationPoints()); - - else if (identifier.startsWith("attribute_")) - return String.valueOf(playerData.getAttributes() - .getAttribute(MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-")))); - - else if (identifier.equals("mana")) - return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getMana()); - - else if (identifier.equals("mana_bar")) - return playerData.getProfess().getManaDisplay().generateBar(playerData.getMana(), playerData.getStats().getStat("MAX_MANA")); - - else if (identifier.startsWith("exp_multiplier_")) { - String format = identifier.substring(15).toLowerCase().replace("_", "-").replace(" ", "-"); - Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format); - return MythicLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.boosterManager.getMultiplier(profession) * 100); - } - - else if (identifier.startsWith("exp_boost_")) { - String format = identifier.substring(10).toLowerCase().replace("_", "-").replace(" ", "-"); - Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format); - return MythicLib.plugin.getMMOConfig().decimal.format((MMOCore.plugin.boosterManager.getMultiplier(profession) - 1) * 100); - } - - else if (identifier.equals("stamina")) - return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getStamina()); - - else if (identifier.equals("stamina_bar")) { - StringBuilder format = new StringBuilder(); - double ratio = 20 * playerData.getStamina() / playerData.getStats().getStat("MAX_STAMINA"); - for (double j = 1; j < 20; j++) - format.append(ratio >= j ? MMOCore.plugin.configManager.staminaFull - : ratio >= j - .5 ? MMOCore.plugin.configManager.staminaHalf : MMOCore.plugin.configManager.staminaEmpty) - .append(AltChar.listSquare); - return format.toString(); - } - - else if (identifier.startsWith("stat_")) { - final String stat = UtilityMethods.enumName(identifier.substring(5)); - return StatManager.format(stat, playerData.getMMOPlayerData()); - } - - else if (identifier.equals("stellium")) - return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getStellium()); - - else if (identifier.equals("stellium_bar")) { - StringBuilder format = new StringBuilder(); - double ratio = 20 * playerData.getStellium() / playerData.getStats().getStat("MAX_STELLIUM"); - for (double j = 1; j < 20; j++) - format.append(ratio >= j ? ChatColor.BLUE : ratio >= j - .5 ? ChatColor.AQUA : ChatColor.WHITE).append(AltChar.listSquare); - return format.toString(); - } - - else if (identifier.equals("quest")) { - PlayerQuests data = playerData.getQuestData(); - return data.hasCurrent() ? data.getCurrent().getQuest().getName() : "None"; - } - - else if (identifier.equals("quest_progress")) { - PlayerQuests data = playerData.getQuestData(); - return data.hasCurrent() ? MythicLib.plugin.getMMOConfig().decimal - .format( (double) data.getCurrent().getObjectiveNumber() / data.getCurrent().getQuest().getObjectives().size() * 100L) : "0"; - } - - else if (identifier.equals("quest_objective")) { - PlayerQuests data = playerData.getQuestData(); - return data.hasCurrent() ? data.getCurrent().getFormattedLore() : "None"; - } - - else if (identifier.startsWith("guild_")) { - String placeholder = identifier.substring(6); - if (playerData.getGuild() == null) - return ""; - - if (placeholder.equalsIgnoreCase("name")) - return playerData.getGuild().getName(); - else if (placeholder.equalsIgnoreCase("tag")) - return playerData.getGuild().getTag(); - else if (placeholder.equalsIgnoreCase("leader")) - return Bukkit.getOfflinePlayer(playerData.getGuild().getOwner()).getName(); - else if (placeholder.equalsIgnoreCase("members")) - return String.valueOf(playerData.getGuild().countMembers()); - else if (placeholder.equalsIgnoreCase("online_members")) - return String.valueOf(playerData.getGuild().countOnlineMembers()); - } - - return null; - } + return null; + } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java index b62d67fd..b6b803a5 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/gui/skilltree/SkillTreeViewer.java @@ -340,10 +340,10 @@ public class SkillTreeViewer extends EditableInventory { public Icon getIcon(IntegerCoordinates coordinates) { - boolean hasUpPath = skillTree.isPath(new IntegerCoordinates(coordinates.getX(), coordinates.getY() - 1)); - boolean hasDownPath = skillTree.isPath(new IntegerCoordinates(coordinates.getX(), coordinates.getY() + 1)); - boolean hasRightPath = skillTree.isPath(new IntegerCoordinates(coordinates.getX() + 1, coordinates.getY())); - boolean hasLeftPath = skillTree.isPath(new IntegerCoordinates(coordinates.getX() - 1, coordinates.getY())); + boolean hasUpPath = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() - 1)); + boolean hasDownPath = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX(), coordinates.getY() + 1)); + boolean hasRightPath = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX() + 1, coordinates.getY())); + boolean hasLeftPath = skillTree.isPathOrNode(new IntegerCoordinates(coordinates.getX() - 1, coordinates.getY())); if (skillTree.isNode(coordinates)) { SkillTreeNode node = skillTree.getNode(coordinates); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/tree/SkillTree.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/tree/SkillTree.java index d129f4aa..86b9ed64 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/tree/SkillTree.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/tree/SkillTree.java @@ -232,6 +232,10 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje return coordinatesPaths.keySet().contains(coordinates); } + public boolean isPathOrNode(IntegerCoordinates coordinates) { + return isNode(coordinates) || isPath(coordinates); + } + public Material getItem() { return item; }