From a7231d948ee40bf76b206df9e31c1fefe1640b63 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 21 Mar 2023 20:58:50 +0100 Subject: [PATCH] Made unlockedItems class based. --- .../player/profess/SavedClassInformation.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index a1db0223..ab0bd9c9 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -6,15 +6,17 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; import net.Indyuce.mmocore.player.ClassDataContainer; -import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skilltree.SkillTreeNode; import net.Indyuce.mmocore.skilltree.tree.SkillTree; import org.bukkit.attribute.Attribute; import org.bukkit.configuration.ConfigurationSection; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; public class SavedClassInformation { private final int level, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints; @@ -25,7 +27,7 @@ public class SavedClassInformation { private final Map nodeLevels = new HashMap<>(); private final Map nodeTimesClaimed = new HashMap<>(); private final Map boundSkills = new HashMap<>(); - + private final Set unlockedItems= new HashSet<>(); /** * Used by YAML storage */ @@ -60,6 +62,7 @@ public class SavedClassInformation { if (config.isConfigurationSection("bound-skills")) config.getConfigurationSection("bound-skills").getKeys(false) .forEach(key -> boundSkills.put(Integer.parseInt(key), config.getString("bound-skills." + key))); + unlockedItems.addAll(config.getStringList("unlocked-items")); } /** @@ -96,6 +99,11 @@ public class SavedClassInformation { if (json.has("bound-skills") && json.get("bound-skills").isJsonObject()) for (Entry entry : json.getAsJsonObject("bound-skills").entrySet()) boundSkills.put(Integer.parseInt(entry.getKey()), entry.getValue().getAsString()); + if(json.has("unlocked-items")){ + for(JsonElement unlockedItem: json.get("unlocked-items").getAsJsonArray()){ + unlockedItems.add(unlockedItem.getAsString()); + } + } } public SavedClassInformation(ClassDataContainer data) { @@ -115,8 +123,8 @@ public class SavedClassInformation { data.mapSkillTreePoints().forEach((key, val) -> skillTreePoints.put(key, val)); data.getNodeLevels().forEach((node, level) -> nodeLevels.put(node.getFullId(), level)); data.getNodeTimesClaimed().forEach((key, val) -> nodeTimesClaimed.put(key, val)); - data.mapBoundSkills().forEach((slot, skill) -> boundSkills.put(slot, skill)); + data.getUnlockedItems().forEach(item->unlockedItems.add(item)); } public int getLevel() { @@ -203,6 +211,10 @@ public class SavedClassInformation { return stamina; } + public Set getUnlockedItems() { + return unlockedItems; + } + public Set getAttributeKeys() { return attributeLevels.keySet(); } @@ -265,6 +277,7 @@ public class SavedClassInformation { player.setAttributeReallocationPoints(attributeReallocationPoints); player.setSkillTreeReallocationPoints(skillTreeReallocationPoints); player.setSkillReallocationPoints(skillReallocationPoints); + player.setUnlockedItems(unlockedItems); for (int slot : boundSkills.keySet()) player.bindSkill(slot, profess.getSkill(boundSkills.get(slot)));