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 a369d651..52cd1c64 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 @@ -283,7 +283,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc if (skillTree.isNode(coordinates)) { SkillTreeNode node = skillTree.getNode(coordinates); if (nodeStates.get(node) == null) { - skillTree.getNodes().forEach(nodee -> Bukkit.broadcastMessage(nodee.getId() + " " + nodeStates.get(nodee))); + skillTree.getNodes().forEach(nodee -> Bukkit.broadcastMessage(nodee.getFullId() + " " + nodeStates.get(nodee))); } DisplayInfo displayInfo = new DisplayInfo(nodeStates.get(node), node.getSize()); return skillTree.getIcon(displayInfo); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java index bf14f75e..b419c24b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java @@ -49,6 +49,24 @@ public class MySQLDataProvider extends MMODataSource implements DataProvider { exception.printStackTrace(); } }); + // Add 'skill_tree_realloc_points' if it doesn't exist + getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'mmocore_playerdata' AND COLUMN_NAME = 'skill_tree_realloc_points'", result -> { + try { + if (!result.next()) + executeUpdate("ALTER TABLE mmocore_playerdata ADD COLUMN is_saved TINYINT"); + } catch (SQLException exception) { + exception.printStackTrace(); + } + }); + // Add 'skill_tree_points' if it doesn't exist + getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'mmocore_playerdata' AND COLUMN_NAME = 'skill_tree_points'", result -> { + try { + if (!result.next()) + executeUpdate("ALTER TABLE mmocore_playerdata ADD COLUMN is_saved TINYINT"); + } catch (SQLException exception) { + exception.printStackTrace(); + } + }); } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index fab44dfb..706667c3 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -9,6 +9,7 @@ import net.Indyuce.mmocore.api.player.profess.SavedClassInformation; import net.Indyuce.mmocore.guild.provided.Guild; import net.Indyuce.mmocore.manager.data.DataProvider; import net.Indyuce.mmocore.manager.data.PlayerDataManager; +import net.Indyuce.mmocore.tree.SkillTreeNode; import org.apache.commons.lang.Validate; import org.bukkit.configuration.file.FileConfiguration; import org.jetbrains.annotations.NotNull; @@ -72,6 +73,14 @@ public class YAMLPlayerDataManager extends PlayerDataManager { } data.setSkillTreePoints("global", config.getInt("skill-tree-points.global", 0)); + for (SkillTreeNode node : MMOCore.plugin.skillTreeManager.getAllNodes()) { + data.setNodeLevel(node, config.getInt("skill-tree-level." + node.getFullId(), 0)); + } + data.setupNodeState(); + + for (SkillTreeNode node : MMOCore.plugin.skillTreeManager.getAllNodes()) { + MMOCore.log(node.getFullId()+" " +data.getNodeState(node)+""); + } if (config.contains("times-claimed")) for (String key : config.getConfigurationSection("times-claimed").getKeys(true)) @@ -112,6 +121,8 @@ public class YAMLPlayerDataManager extends PlayerDataManager { data.getSkillTreePoints().forEach((key1, value) -> config.set("skill-tree-points." + key1, value)); config.set("skill-tree-reallocation-points", data.getSkillTreeReallocationPoints()); config.set("skill", null); + //Saves the nodes levels + MMOCore.plugin.skillTreeManager.getAllNodes().forEach(node -> config.set("skill-tree-level." + node.getFullId(), data.getNodeLevel(node))); data.mapSkillLevels().forEach((key1, value) -> config.set("skill." + key1, value)); data.getItemClaims().forEach((key, times) -> config.set("times-claimed." + key, times)); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/AutomaticSkillTree.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/AutomaticSkillTree.java index 29d5ceb7..be8bc0d3 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/AutomaticSkillTree.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/AutomaticSkillTree.java @@ -44,7 +44,7 @@ public class AutomaticSkillTree extends SkillTree { } } - //We find the root of the tree wich is + //We find the root of the tree which is for (SkillTreeNode node : nodes.values()) { if (node.getSoftParents().size() == 0 && node.getStrongParents().size() == 0) { Validate.isTrue(roots.size() == 0, "You can't have 2 roots on one automatic skill tree. You have " + (roots.size() != 0 ? roots.get(0).getName() : "") + " and " + node.getName() + "."); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/CustomSkillTree.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/CustomSkillTree.java index b18b8c40..69de7b1b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/CustomSkillTree.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/CustomSkillTree.java @@ -1,10 +1,14 @@ package net.Indyuce.mmocore.tree.skilltree; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.tree.ParentType; import net.Indyuce.mmocore.tree.SkillTreeNode; +import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; import org.jetbrains.annotations.NotNull; +import java.util.logging.Level; + public class CustomSkillTree extends SkillTree{ public CustomSkillTree(ConfigurationSection config) { super(config); @@ -36,6 +40,17 @@ public class CustomSkillTree extends SkillTree{ } } } + //We find the roots of the tree which don't have any parents + for (SkillTreeNode node : nodes.values()) { + if (node.getSoftParents().size() == 0 && node.getStrongParents().size() == 0) { + Validate.isTrue(roots.size() == 0, "You can't have 2 roots on one automatic skill tree. You have " + (roots.size() != 0 ? roots.get(0).getName() : "") + " and " + node.getName() + "."); + //We mark the node as a root also + roots.add(node); + node.setIsRoot(); + } + } + MMOCore.plugin.getLogger().log(Level.SEVERE,roots.size()+" ROOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOoooT"); + } } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/SkillTree.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/SkillTree.java index 4bee8748..8baf9244 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/SkillTree.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/tree/skilltree/SkillTree.java @@ -152,7 +152,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje try { String string = config.getString("type"); - + Validate.notNull(string, "You must precise a type for the skill tree."); Validate.isTrue(string.equals("automatic") || string.equals("linked") || string.equals("custom"), "You must precise the type of the skill tree in the yml!" + "\nAllowed values: 'automatic','linked','custom'"); if (string.equals("automatic")) { @@ -168,7 +168,7 @@ public abstract class SkillTree extends PostLoadObject implements RegisteredObje skillTree.postLoad(); } } catch (Exception e) { - MMOCore.plugin.getLogger().log(Level.SEVERE, "Couldn't load skill tree " + config.getName() + ": " + e.getMessage()); + MMOCore.log("Couldn't load skill tree " + config.getString("id") + ": " + e.getMessage()); } return skillTree; }