From e5ecd46611eb1c80f21948828dfc46f656ad8ee7 Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 14 Oct 2025 00:37:27 +0200 Subject: [PATCH] Support for old 'paths' syntax for skill trees. Warning if usage of old syntax is detected. Logs if problems are detected with the config --- .../mmocore/skilltree/ParentInformation.java | 7 +++++ .../mmocore/skilltree/SkillTreeNode.java | 26 +++++++++++++++++ .../mmocore/skilltree/tree/SkillTree.java | 28 ++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/ParentInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/ParentInformation.java index edd67094..3d07ec0c 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/ParentInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/ParentInformation.java @@ -74,6 +74,13 @@ public class ParentInformation { return shape; } + @Deprecated + public void addElement(@NotNull IntCoords coordinates) { + Validate.isTrue(!this.elements.containsKey(coordinates), "Path element already present at " + coordinates); + this.elements.put(coordinates, null); // Place new + this.elements.replaceAll((e, v) -> computePathShape(e)); // Update all + } + /** * Defines the method for computing the shape of a path element ie * whether it goes up, right, up-right, etc. based on the presence diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java index c397416d..28730015 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java @@ -277,6 +277,32 @@ public class SkillTreeNode implements ExperienceObject { //region Deprecated + @Deprecated + public void loadLegacyPathSection(@NotNull ConfigurationSection section) { + for (var childId : section.getKeys(false)) { + final var child = tree.getNode(childId); + Validate.notNull(child, "Could not find child node '" + childId + "' for path"); + + // Find corresponding edge + ParentInformation edge = null; + for (var existingEdge : children) + if (existingEdge.getChild().equals(child)) { + edge = existingEdge; + break; + } + if (edge == null) { + MMOCore.log("Could not find parent-child relation between '" + id + "' and '" + childId + "'. Did you forget to add it in the 'parents' or 'children' section?"); + continue; + } + + final var subsection = section.getConfigurationSection(childId); + for (var pathKey : subsection.getKeys(false)) { + final var coords = IntCoords.from(subsection.get(pathKey)); + edge.addElement(coords); + } + } + } + @Deprecated public int getParentNeededLevel(SkillTreeNode parent) { for (var edge : parents) 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 246ae63e..2b277896 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 @@ -65,7 +65,7 @@ public abstract class SkillTree implements RegisteredObject { MMOCore.log(Level.WARNING, "Couldn't load skill tree node " + id + "." + key + ": " + exception.getMessage()); } - // Post load all nodes + // Post load all nodes (relatives) for (var node : nodes.values()) try { node.getPostLoadAction().performAction(); @@ -75,6 +75,9 @@ public abstract class SkillTree implements RegisteredObject { exception.printStackTrace(); // TODO remove } + // [Syntax Deprecated] Load legacy "paths" section + loadLegacyPaths(config); + // Resolve node shapes resolveNodeShapes(); @@ -415,6 +418,29 @@ public abstract class SkillTree implements RegisteredObject { //region Deprecated + @Deprecated + private void loadLegacyPaths(ConfigurationSection config) { + + int warnings = 0; + + for (var node : nodes.values()) { + final var section = config.getConfigurationSection("nodes." + node.getId() + ".paths"); + if (section == null) continue; + if (warnings++ < 3) { + // Warn max 3 times + MMOCore.log("You are using deprecated syntax for skill tree node '" + id + "' of skill tree '" + + this.getId() + "'. You may update your config to use the 'parents' section instead of the 'paths' section. " + + "Please visit 'https://gitlab.com/phoenix-dvpmt/mmocore/-/wikis/Skill%20Trees' to read about this new syntax"); + } + node.loadLegacyPathSection(section); + } + + // Repopulate pathByCoordinate map + if (warnings > 0) + for (var node : nodes.values()) + node.getParents().forEach(parentInfo -> parentInfo.getElements().forEach(coords -> this.pathByCoordinate.put(coords, parentInfo))); + } + @Deprecated public boolean isNode(@NotNull IntCoords coordinates) { // TODO remove usage