SkillTree debug and support for SQL

This commit is contained in:
Ka0rX 2022-06-19 12:02:06 +02:00
parent a5ab2c9269
commit d1bb2406de
8 changed files with 287 additions and 238 deletions

View File

@ -62,6 +62,7 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -220,6 +221,15 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
} }
public Set<Map.Entry<String,Integer>> getNodeLevelsEntrySet() {
HashMap<String,Integer> nodeLevelsString=new HashMap<>();
for(SkillTreeNode node:nodeLevels.keySet()) {
nodeLevelsString.put(node.getFullId(),nodeLevels.get(node));
}
return nodeLevelsString.entrySet();
}
public void removeModifiersFrom(SkillTree skillTree) { public void removeModifiersFrom(SkillTree skillTree) {
for (SkillTreeNode node : skillTree.getNodes()) { for (SkillTreeNode node : skillTree.getNodes()) {
for (int i = 0; i < node.getMaxLevel(); i++) { for (int i = 0; i < node.getMaxLevel(); i++) {
@ -331,6 +341,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
} }
public int getNodeLevel(SkillTreeNode node) { public int getNodeLevel(SkillTreeNode node) {
return nodeLevels.get(node); return nodeLevels.get(node);
} }

View File

@ -332,7 +332,7 @@ public class SkillTreeViewer extends EditableInventory {
int xOffset=offset%9-middleSlot%9; int xOffset=offset%9-middleSlot%9;
int yOffset=offset/9-middleSlot/9; int yOffset=offset/9-middleSlot/9;
x += xOffset; x += xOffset;
y += yOffset; y += yOffset-1;
open(); open();
event.setCancelled(true); event.setCancelled(true);
return; return;

View File

@ -7,36 +7,39 @@ import net.Indyuce.mmocore.tree.skilltree.SkillTree;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class SkillTreeManager extends MMOCoreRegister<SkillTree> { public class SkillTreeManager extends MMOCoreRegister<SkillTree> {
private final ArrayList<SkillTreeNode> skillTreeNodes = new ArrayList<>(); private final HashMap<String,SkillTreeNode> skillTreeNodes = new HashMap<>();
@Override @Override
public void register(SkillTree tree){ public void register(SkillTree tree){
super.register(tree); super.register(tree);
tree.getNodes().forEach((node)->skillTreeNodes.add(node)); tree.getNodes().forEach((node)->skillTreeNodes.put(node.getFullId(),node));
} }
public boolean has(int index) { public boolean has(int index) {
return index>=0 &&index<registered.values().stream().collect(Collectors.toList()).size(); return index>=0 &&index<registered.values().stream().collect(Collectors.toList()).size();
} }
public SkillTreeNode getNode(String fullId) {
return skillTreeNodes.get(fullId);
}
/** /**
* Useful to recursively go trough trees * Useful to recursively go trough trees
* *
* @return The list of all the roots (e.g the nodes without any parents * @return The list of all the roots (e.g the nodes without any parents
*/ */
public List<SkillTreeNode> getRootNodes() { public List<SkillTreeNode> getRootNodes() {
return skillTreeNodes.stream().filter(treeNode -> treeNode.getSoftParents().size()==0).collect(Collectors.toList()); return skillTreeNodes.values().stream().filter(treeNode -> treeNode.getSoftParents().size()==0).collect(Collectors.toList());
} }
public ArrayList<SkillTreeNode> getAllNodes() { public Collection<SkillTreeNode> getAllNodes() {
return skillTreeNodes; return skillTreeNodes.values();
} }
public SkillTree get(int index) { public SkillTree get(int index) {

View File

@ -42,7 +42,8 @@ getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '"
+ "experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG," + "experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,"
+ "attributes LONGTEXT,professions LONGTEXT,times_claimed LONGTEXT,quests LONGTEXT," + "attributes LONGTEXT,professions LONGTEXT,times_claimed LONGTEXT,quests LONGTEXT,"
+ "waypoints LONGTEXT,friends LONGTEXT,skills LONGTEXT,bound_skills LONGTEXT," + "waypoints LONGTEXT,friends LONGTEXT,skills LONGTEXT,bound_skills LONGTEXT,"
+ "class_info LONGTEXT,PRIMARY KEY (uuid));"); + "class_info LONGTEXT,skill_tree_reallocation_points INT(11) DEFAULT 0,skill_tree_points"
+ " LONGTEXT,skill_tree_nodes_level LONGTEXT,PRIMARY KEY (uuid));");
} }
@Override @Override

View File

@ -23,231 +23,247 @@ import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class MySQLPlayerDataManager extends PlayerDataManager { public class MySQLPlayerDataManager extends PlayerDataManager {
private final MySQLDataProvider provider; private final MySQLDataProvider provider;
public MySQLPlayerDataManager(MySQLDataProvider provider) { public MySQLPlayerDataManager(MySQLDataProvider provider) {
this.provider = provider; this.provider = provider;
} }
//TODO SkillTree pour SQL @Override
@Override public void loadData(PlayerData data) {
public void loadData(PlayerData data) { provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';", (result) -> {
provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';", (result) -> { try {
try { MMOCore.sqlDebug("Loading data for: '" + data.getUniqueId() + "'...");
MMOCore.sqlDebug("Loading data for: '" + data.getUniqueId() + "'...");
if (!result.next()) { if (!result.next()) {
data.setLevel(getDefaultData().getLevel()); data.setLevel(getDefaultData().getLevel());
data.setClassPoints(getDefaultData().getClassPoints()); data.setClassPoints(getDefaultData().getClassPoints());
data.setSkillPoints(getDefaultData().getSkillPoints()); data.setSkillPoints(getDefaultData().getSkillPoints());
data.setAttributePoints(getDefaultData().getAttributePoints()); data.setAttributePoints(getDefaultData().getAttributePoints());
data.setAttributeReallocationPoints(getDefaultData().getAttrReallocPoints()); data.setAttributeReallocationPoints(getDefaultData().getAttrReallocPoints());
data.setExperience(0); data.setExperience(0);
data.getQuestData().updateBossBar(); data.getQuestData().updateBossBar();
if (!data.hasUsedTemporaryData()) { if (!data.hasUsedTemporaryData()) {
data.setMana(data.getStats().getStat(StatType.MAX_MANA)); data.setMana(data.getStats().getStat(StatType.MAX_MANA));
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
} }
data.setFullyLoaded(); data.setFullyLoaded();
MMOCore.sqlDebug("Loaded DEFAULT data for: '" + data.getUniqueId() + "' as no saved data was found."); MMOCore.sqlDebug("Loaded DEFAULT data for: '" + data.getUniqueId() + "' as no saved data was found.");
return; return;
} }
data.setClassPoints(result.getInt("class_points")); data.setClassPoints(result.getInt("class_points"));
data.setSkillPoints(result.getInt("skill_points")); data.setSkillPoints(result.getInt("skill_points"));
data.setAttributePoints(result.getInt("attribute_points")); data.setAttributePoints(result.getInt("attribute_points"));
data.setAttributeReallocationPoints(result.getInt("attribute_realloc_points")); data.setAttributeReallocationPoints(result.getInt("attribute_realloc_points"));
data.setLevel(result.getInt("level")); data.setLevel(result.getInt("level"));
data.setExperience(result.getInt("experience")); data.setExperience(result.getInt("experience"));
if (!isEmpty(result.getString("class"))) if (!isEmpty(result.getString("class")))
data.setClass(MMOCore.plugin.classManager.get(result.getString("class"))); data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
if (!isEmpty(result.getString("times_claimed"))) { if (!isEmpty(result.getString("times_claimed"))) {
JsonObject json = new JsonParser().parse(result.getString("times_claimed")).getAsJsonObject(); JsonObject json = new JsonParser().parse(result.getString("times_claimed")).getAsJsonObject();
json.entrySet().forEach(entry -> data.getItemClaims().put(entry.getKey(), entry.getValue().getAsInt())); json.entrySet().forEach(entry -> data.getItemClaims().put(entry.getKey(), entry.getValue().getAsInt()));
} }
if (!data.hasUsedTemporaryData()) { if (!data.hasUsedTemporaryData()) {
data.setMana(data.getStats().getStat(StatType.MAX_MANA)); data.setMana(data.getStats().getStat(StatType.MAX_MANA));
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
} }
if (!isEmpty(result.getString("guild"))) { if (!isEmpty(result.getString("guild"))) {
Guild guild = provider.getGuildManager().getGuild(result.getString("guild")); Guild guild = provider.getGuildManager().getGuild(result.getString("guild"));
data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null); data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null);
} }
if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes")); if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes"));
if (!isEmpty(result.getString("professions"))) if (!isEmpty(result.getString("professions")))
data.getCollectionSkills().load(result.getString("professions")); data.getCollectionSkills().load(result.getString("professions"));
if (!isEmpty(result.getString("quests"))) data.getQuestData().load(result.getString("quests")); if (!isEmpty(result.getString("quests"))) data.getQuestData().load(result.getString("quests"));
data.getQuestData().updateBossBar(); data.getQuestData().updateBossBar();
if (!isEmpty(result.getString("waypoints"))) if (!isEmpty(result.getString("waypoints")))
data.getWaypoints().addAll(getJSONArray(result.getString("waypoints"))); data.getWaypoints().addAll(getJSONArray(result.getString("waypoints")));
if (!isEmpty(result.getString("friends"))) if (!isEmpty(result.getString("friends")))
getJSONArray(result.getString("friends")).forEach(str -> data.getFriends().add(UUID.fromString(str))); getJSONArray(result.getString("friends")).forEach(str -> data.getFriends().add(UUID.fromString(str)));
if (!isEmpty(result.getString("skills"))) { if (!isEmpty(result.getString("skills"))) {
JsonObject object = MythicLib.plugin.getJson().parse(result.getString("skills"), JsonObject.class); JsonObject object = MythicLib.plugin.getJson().parse(result.getString("skills"), JsonObject.class);
for (Entry<String, JsonElement> entry : object.entrySet()) for (Entry<String, JsonElement> entry : object.entrySet())
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt()); data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
} }
if (!isEmpty(result.getString("bound_skills"))) if (!isEmpty(result.getString("bound_skills")))
for (String skill : getJSONArray(result.getString("bound_skills"))) for (String skill : getJSONArray(result.getString("bound_skills")))
if (data.getProfess().hasSkill(skill)) if (data.getProfess().hasSkill(skill))
data.getBoundSkills().add(data.getProfess().getSkill(skill)); data.getBoundSkills().add(data.getProfess().getSkill(skill));
if (!isEmpty(result.getString("class_info"))) { if (!isEmpty(result.getString("class_info"))) {
JsonObject object = MythicLib.plugin.getJson().parse(result.getString("class_info"), JsonObject.class); JsonObject object = MythicLib.plugin.getJson().parse(result.getString("class_info"), JsonObject.class);
for (Entry<String, JsonElement> entry : object.entrySet()) { for (Entry<String, JsonElement> entry : object.entrySet()) {
try { try {
PlayerClass profess = MMOCore.plugin.classManager.get(entry.getKey()); PlayerClass profess = MMOCore.plugin.classManager.get(entry.getKey());
Validate.notNull(profess, "Could not find class '" + entry.getKey() + "'"); Validate.notNull(profess, "Could not find class '" + entry.getKey() + "'");
data.applyClassInfo(profess, new SavedClassInformation(entry.getValue().getAsJsonObject())); data.applyClassInfo(profess, new SavedClassInformation(entry.getValue().getAsJsonObject()));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not load class info '" + entry.getKey() + "': " + exception.getMessage()); MMOCore.log(Level.WARNING, "Could not load class info '" + entry.getKey() + "': " + exception.getMessage());
} }
} }
} }
//We load the skill trees
data.setSkillTreeReallocationPoints(result.getInt("skill_tree_reallocation_points"));
data.setFullyLoaded(); JsonObject object = MythicLib.plugin.getJson().parse(result.getString("skill_tree_points"), JsonObject.class);
MMOCore.sqlDebug("Loaded saved data for: '" + data.getUniqueId() + "'!"); for (Entry<String, JsonElement> entry : object.entrySet()) {
MMOCore.sqlDebug(String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel())); data.setSkillTreePoints(entry.getKey(), entry.getValue().getAsInt());
} catch (SQLException e) { }
e.printStackTrace(); object = MythicLib.plugin.getJson().parse(result.getString("skill_tree_nodes_level"), JsonObject.class);
} for (Entry<String, JsonElement> entry : object.entrySet()) {
}); data.setNodeLevel(MMOCore.plugin.skillTreeManager.getNode(entry.getKey()),entry.getValue().getAsInt());
} }
private boolean isEmpty(String s) { data.setFullyLoaded();
return s == null || s.equalsIgnoreCase("null") || s.equalsIgnoreCase("{}") || s.equalsIgnoreCase("[]") || s.equalsIgnoreCase(""); MMOCore.sqlDebug("Loaded saved data for: '" + data.getUniqueId() + "'!");
} MMOCore.sqlDebug(String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
} catch (SQLException e) {
e.printStackTrace();
}
});
}
@Override private boolean isEmpty(String s) {
public void saveData(PlayerData data) { return s == null || s.equalsIgnoreCase("null") || s.equalsIgnoreCase("{}") || s.equalsIgnoreCase("[]") || s.equalsIgnoreCase("");
MySQLTableEditor sql = new MySQLTableEditor(Table.PLAYERDATA, data.getUniqueId()); }
MMOCore.sqlDebug("Saving data for: '" + data.getUniqueId() + "'...");
sql.updateData("class_points", data.getClassPoints()); @Override
sql.updateData("skill_points", data.getSkillPoints()); public void saveData(PlayerData data) {
sql.updateData("attribute_points", data.getAttributePoints()); MySQLTableEditor sql = new MySQLTableEditor(Table.PLAYERDATA, data.getUniqueId());
sql.updateData("attribute_realloc_points", data.getAttributeReallocationPoints()); MMOCore.sqlDebug("Saving data for: '" + data.getUniqueId() + "'...");
sql.updateData("level", data.getLevel());
sql.updateData("experience", data.getExperience());
sql.updateData("class", data.getProfess().getId());
sql.updateData("last_login", data.getLastLogin());
sql.updateData("guild", data.hasGuild() ? data.getGuild().getId() : null);
sql.updateJSONArray("waypoints", data.getWaypoints()); sql.updateData("class_points", data.getClassPoints());
sql.updateJSONArray("friends", data.getFriends().stream().map(UUID::toString).collect(Collectors.toList())); sql.updateData("skill_points", data.getSkillPoints());
sql.updateJSONArray("bound_skills", data.getBoundSkills().stream().map(skill -> skill.getSkill().getHandler().getId()).collect(Collectors.toList())); sql.updateData("attribute_points", data.getAttributePoints());
sql.updateData("attribute_realloc_points", data.getAttributeReallocationPoints());
sql.updateData("level", data.getLevel());
sql.updateData("experience", data.getExperience());
sql.updateData("class", data.getProfess().getId());
sql.updateData("last_login", data.getLastLogin());
sql.updateData("guild", data.hasGuild() ? data.getGuild().getId() : null);
sql.updateJSONObject("skills", data.mapSkillLevels().entrySet()); sql.updateJSONArray("waypoints", data.getWaypoints());
sql.updateJSONObject("times_claimed", data.getItemClaims().entrySet()); sql.updateJSONArray("friends", data.getFriends().stream().map(UUID::toString).collect(Collectors.toList()));
sql.updateJSONArray("bound_skills", data.getBoundSkills().stream().map(skill -> skill.getSkill().getHandler().getId()).collect(Collectors.toList()));
sql.updateData("attributes", data.getAttributes().toJsonString()); sql.updateJSONObject("skills", data.mapSkillLevels().entrySet());
sql.updateData("professions", data.getCollectionSkills().toJsonString()); sql.updateJSONObject("times_claimed", data.getItemClaims().entrySet());
sql.updateData("quests", data.getQuestData().toJsonString());
sql.updateData("class_info", createClassInfoData(data).toString()); sql.updateData("attributes", data.getAttributes().toJsonString());
sql.updateData("professions", data.getCollectionSkills().toJsonString());
sql.updateData("quests", data.getQuestData().toJsonString());
MMOCore.sqlDebug("Saved data for: " + data.getUniqueId()); sql.updateData("class_info", createClassInfoData(data).toString());
MMOCore.sqlDebug(String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
}
private JsonObject createClassInfoData(PlayerData data) { //Load skill tree on
JsonObject json = new JsonObject(); sql.updateData("skill_tree_reallocation_points", data.getSkillTreeReallocationPoints());
for (String c : data.getSavedClasses()) { sql.updateJSONObject("skill_tree_points", data.getSkillTreePoints().entrySet());
SavedClassInformation info = data.getClassInfo(c); sql.updateJSONObject("skill_tree_nodes_level", data.getNodeLevelsEntrySet());
JsonObject classinfo = new JsonObject();
classinfo.addProperty("level", info.getLevel());
classinfo.addProperty("experience", info.getExperience());
classinfo.addProperty("skill-points", info.getSkillPoints());
classinfo.addProperty("attribute-points", info.getAttributePoints());
classinfo.addProperty("attribute-realloc-points", info.getAttributeReallocationPoints());
JsonObject skillinfo = new JsonObject();
for (String skill : info.getSkillKeys())
skillinfo.addProperty(skill, info.getSkillLevel(skill));
classinfo.add("skill", skillinfo);
JsonObject attributeinfo = new JsonObject();
for (String attribute : info.getAttributeKeys())
attributeinfo.addProperty(attribute, info.getAttributeLevel(attribute));
classinfo.add("attribute", attributeinfo);
json.add(c, classinfo);
}
return json; MMOCore.sqlDebug("Saved data for: " + data.getUniqueId());
} MMOCore.sqlDebug(String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
}
@NotNull private JsonObject createClassInfoData(PlayerData data) {
@Override JsonObject json = new JsonObject();
public OfflinePlayerData getOffline(UUID uuid) { for (String c : data.getSavedClasses()) {
return isLoaded(uuid) ? get(uuid) : new MySQLOfflinePlayerData(uuid); SavedClassInformation info = data.getClassInfo(c);
} JsonObject classinfo = new JsonObject();
classinfo.addProperty("level", info.getLevel());
classinfo.addProperty("experience", info.getExperience());
classinfo.addProperty("skill-points", info.getSkillPoints());
classinfo.addProperty("attribute-points", info.getAttributePoints());
classinfo.addProperty("attribute-realloc-points", info.getAttributeReallocationPoints());
JsonObject skillinfo = new JsonObject();
for (String skill : info.getSkillKeys())
skillinfo.addProperty(skill, info.getSkillLevel(skill));
classinfo.add("skill", skillinfo);
JsonObject attributeinfo = new JsonObject();
for (String attribute : info.getAttributeKeys())
attributeinfo.addProperty(attribute, info.getAttributeLevel(attribute));
classinfo.add("attribute", attributeinfo);
private Collection<String> getJSONArray(String json) { json.add(c, classinfo);
return new ArrayList<>(Arrays.asList(MythicLib.plugin.getJson().parse(json, String[].class))); }
}
public class MySQLOfflinePlayerData extends OfflinePlayerData { return json;
private int level; }
private long lastLogin;
private PlayerClass profess;
private List<UUID> friends;
public MySQLOfflinePlayerData(UUID uuid) { @NotNull
super(uuid); @Override
public OfflinePlayerData getOffline(UUID uuid) {
return isLoaded(uuid) ? get(uuid) : new MySQLOfflinePlayerData(uuid);
}
provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';", (result) -> { private Collection<String> getJSONArray(String json) {
try { return new ArrayList<>(Arrays.asList(MythicLib.plugin.getJson().parse(json, String[].class)));
MMOCore.sqlDebug("Loading OFFLINE data for '" + uuid + "'."); }
if (!result.next()) {
level = 0;
lastLogin = 0;
profess = MMOCore.plugin.classManager.getDefaultClass();
friends = new ArrayList<>();
MMOCore.sqlDebug("Default OFFLINE data loaded.");
} else {
level = result.getInt("level");
lastLogin = result.getLong("last_login");
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(result.getString("class"));
if (!isEmpty(result.getString("friends")))
getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
else friends = new ArrayList<>();
MMOCore.sqlDebug("Saved OFFLINE data loaded.");
}
} catch (SQLException e) {
e.printStackTrace();
}
});
}
@Override public class MySQLOfflinePlayerData extends OfflinePlayerData {
public void removeFriend(UUID uuid) { private int level;
friends.remove(uuid); private long lastLogin;
new MySQLTableEditor(Table.PLAYERDATA, uuid).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList())); private PlayerClass profess;
} private List<UUID> friends;
@Override public MySQLOfflinePlayerData(UUID uuid) {
public boolean hasFriend(UUID uuid) { super(uuid);
return friends.contains(uuid);
}
@Override provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';", (result) -> {
public PlayerClass getProfess() { try {
return profess; MMOCore.sqlDebug("Loading OFFLINE data for '" + uuid + "'.");
} if (!result.next()) {
level = 0;
lastLogin = 0;
profess = MMOCore.plugin.classManager.getDefaultClass();
friends = new ArrayList<>();
MMOCore.sqlDebug("Default OFFLINE data loaded.");
} else {
level = result.getInt("level");
lastLogin = result.getLong("last_login");
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(result.getString("class"));
if (!isEmpty(result.getString("friends")))
getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
else friends = new ArrayList<>();
MMOCore.sqlDebug("Saved OFFLINE data loaded.");
}
} catch (SQLException e) {
e.printStackTrace();
}
});
}
@Override @Override
public int getLevel() { public void removeFriend(UUID uuid) {
return level; friends.remove(uuid);
} new MySQLTableEditor(Table.PLAYERDATA, uuid).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList()));
}
@Override @Override
public long getLastLogin() { public boolean hasFriend(UUID uuid) {
return lastLogin; return friends.contains(uuid);
} }
}
@Override
public PlayerClass getProfess() {
return profess;
}
@Override
public int getLevel() {
return level;
}
@Override
public long getLastLogin() {
return lastLogin;
}
}
} }

View File

@ -77,8 +77,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
//Load skill tree nodes //Load skill tree nodes
for (SkillTreeNode node : MMOCore.plugin.skillTreeManager.getAllNodes()) { for (SkillTreeNode node : MMOCore.plugin.skillTreeManager.getAllNodes()) {
String path = "skill-tree-nodes." + node.getTree().getId() + "." + node.getId(); String path = "skill-tree-nodes." + node.getFullId();
if (config.contains(path)) if (config.contains(path))
data.setNodeLevel(node, config.getInt(path)); data.setNodeLevel(node, config.getInt(path));
else { else {
@ -92,7 +91,6 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
if (section != null) { if (section != null) {
for (String key : section.getKeys(false)) for (String key : section.getKeys(false))
data.setSkillTreePoints(key, section.getInt(key)); data.setSkillTreePoints(key, section.getInt(key));
} }
//Put 0 to the rest of the values if nothing has been given //Put 0 to the rest of the values if nothing has been given
List<String> skillTreeIds = MMOCore.plugin.skillTreeManager.getAll().stream().map(SkillTree::getId).collect(Collectors.toList()); List<String> skillTreeIds = MMOCore.plugin.skillTreeManager.getAll().stream().map(SkillTree::getId).collect(Collectors.toList());
@ -102,7 +100,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
data.setSkillTreePoints(treeId, 0); data.setSkillTreePoints(treeId, 0);
} }
data.setSkillTreeReallocationPoints(config.getInt("skill-tree-reallocation-points",0)); data.setSkillTreeReallocationPoints(config.getInt("skill-tree-reallocation-points", 0));
// Load class slots, use try so the player can log in. // Load class slots, use try so the player can log in.
if (config.contains("class-info")) if (config.contains("class-info"))
@ -149,7 +147,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
for (String treeId : data.getSkillTreePoints().keySet()) { for (String treeId : data.getSkillTreePoints().keySet()) {
config.set("skill-tree-points." + treeId, data.getSkillTreePoint(treeId)); config.set("skill-tree-points." + treeId, data.getSkillTreePoint(treeId));
} }
config.set("skill-tree-reallocation-points",data.getSkillTreeReallocationPoints()); config.set("skill-tree-reallocation-points", data.getSkillTreeReallocationPoints());
List<String> boundSkills = new ArrayList<>(); List<String> boundSkills = new ArrayList<>();
data.getBoundSkills().forEach(skill -> boundSkills.add(skill.getSkill().getHandler().getId())); data.getBoundSkills().forEach(skill -> boundSkills.add(skill.getSkill().getHandler().getId()));

View File

@ -52,6 +52,7 @@ public class SkillTreeNode implements Unlockable {
public SkillTreeNode(SkillTree tree, ConfigurationSection config) { public SkillTreeNode(SkillTree tree, ConfigurationSection config) {
Validate.notNull(config, "Config cannot be null"); Validate.notNull(config, "Config cannot be null");
this.id = config.getName(); this.id = config.getName();
this.tree = tree; this.tree = tree;
@ -106,7 +107,7 @@ public class SkillTreeNode implements Unlockable {
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Couldn't load modifiers for the skill node " + tree.getId() + "." + id+ " :Problem with the Number Format."); MMOCore.plugin.getLogger().log(Level.WARNING, "Couldn't load modifiers for the skill node " + tree.getId() + "." + id + " :Problem with the Number Format.");
} }
} }
@ -114,9 +115,12 @@ public class SkillTreeNode implements Unlockable {
maxLevel = config.contains("max-level") ? config.getInt("max-level") : 1; maxLevel = config.contains("max-level") ? config.getInt("max-level") : 1;
maxChildren = config.contains("max-children") ? config.getInt("max-children") : 1; maxChildren = config.contains("max-children") ? config.getInt("max-children") : 1;
//If coordinates are precised adn we are not wiht an automaticTree we set them up //If coordinates are precised adn we are not wiht an automaticTree we set them up
if ((!(tree instanceof AutomaticSkillTree)) && config.contains("coordinates.x") && config.contains("coordinates.y")) { if ((!(tree instanceof AutomaticSkillTree))) {
Validate.isTrue(config.contains("coordinates.x") && config.contains("coordinates.y"),"No coordinates specified");
coordinates = new IntegerCoordinates(config.getInt("coordinates.x"), config.getInt("coordinates.y")); coordinates = new IntegerCoordinates(config.getInt("coordinates.x"), config.getInt("coordinates.y"));
} }
}
/* /*
if (config.contains("modifiers")) { if (config.contains("modifiers")) {
for (String key : config.getConfigurationSection("modifiers").getKeys(false)) { for (String key : config.getConfigurationSection("modifiers").getKeys(false)) {
@ -126,8 +130,6 @@ public class SkillTreeNode implements Unlockable {
} }
*/ */
}
public SkillTree getTree() { public SkillTree getTree() {
return tree; return tree;
@ -195,6 +197,11 @@ public class SkillTreeNode implements Unlockable {
return id; return id;
} }
public String getFullId() {
return tree.getId() + "." + id;
}
public String getName() { public String getName() {
return MythicLib.plugin.parseColors(name); return MythicLib.plugin.parseColors(name);
} }

View File

@ -55,15 +55,24 @@ public abstract class SkillTree extends PostLoadObject implements RegisterObject
protected final List<SkillTreeNode> roots = new ArrayList<>(); protected final List<SkillTreeNode> roots = new ArrayList<>();
public SkillTree(ConfigurationSection config) { public SkillTree(ConfigurationSection config) {
super(config); super(config);
this.id = Objects.requireNonNull(config.getString("id"), "Could not find skill tree id"); this.id = Objects.requireNonNull(config.getString("id"), "Could not find skill tree id");
this.name = MythicLib.plugin.parseColors(Objects.requireNonNull(config.getString("name"), "Could not find skill tree name")); this.name = MythicLib.plugin.parseColors(Objects.requireNonNull(config.getString("name"), "Could not find skill tree name"));
Objects.requireNonNull(config.getStringList("lore"), "Could not find skill tree lore").forEach(str -> lore.add(MythicLib.plugin.parseColors(str))); Objects.requireNonNull(config.getStringList("lore"), "Could not find skill tree lore").forEach(str -> lore.add(MythicLib.plugin.parseColors(str)));
this.item = Material.valueOf(MMOCoreUtils.toEnumName(Objects.requireNonNull(config.getString("item")))); this.item = Material.valueOf(MMOCoreUtils.toEnumName(Objects.requireNonNull(config.getString("item"))));
Validate.isTrue(config.isConfigurationSection("nodes"), "Could not find any nodes in the tree"); Validate.isTrue(config.isConfigurationSection("nodes"), "Could not find any nodes in the tree");
for (String key : config.getConfigurationSection("nodes").getKeys(false)) { for (String key : config.getConfigurationSection("nodes").getKeys(false)) {
SkillTreeNode node = new SkillTreeNode(this, config.getConfigurationSection("nodes." + key)); try {
nodes.put(node.getId(), node);
SkillTreeNode node = new SkillTreeNode(this, config.getConfigurationSection("nodes." + key));
nodes.put(node.getId(), node);
} catch (Exception e) {
MMOCore.plugin.getLogger().log(Level.SEVERE,"Couldn't load skill tree node "+id+"."+key+": "+e.getMessage());
}
} }
try { try {
if (config.contains("paths")) { if (config.contains("paths")) {
@ -141,24 +150,28 @@ public abstract class SkillTree extends PostLoadObject implements RegisterObject
} }
public static SkillTree loadSkillTree(ConfigurationSection config) { public static SkillTree loadSkillTree(ConfigurationSection config) {
String string = config.getString("type");
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'");
SkillTree skillTree = null; SkillTree skillTree = null;
if (string.equals("automatic")) {
skillTree = new AutomaticSkillTree(config);
skillTree.postLoad();
}
if (string.equals("linked")) {
skillTree = new LinkedSkillTree(config);
skillTree.postLoad();
}
if (string.equals("custom")) {
skillTree = new CustomSkillTree(config);
skillTree.postLoad();
}
try {
String string = config.getString("type");
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")) {
skillTree = new AutomaticSkillTree(config);
skillTree.postLoad();
}
if (string.equals("linked")) {
skillTree = new LinkedSkillTree(config);
skillTree.postLoad();
}
if (string.equals("custom")) {
skillTree = new CustomSkillTree(config);
skillTree.postLoad();
}
} catch (Exception e) {
MMOCore.plugin.getLogger().log(Level.SEVERE, "Couldn't load skill tree " + config.getName() + ": " + e.getMessage());
}
return skillTree; return skillTree;
} }
@ -189,10 +202,10 @@ public abstract class SkillTree extends PostLoadObject implements RegisterObject
} else if (playerData.getNodeLevel(node) == 0 && node.isRoot()) { } else if (playerData.getNodeLevel(node) == 0 && node.isRoot()) {
playerData.setNodeState(node, NodeState.UNLOCKABLE); playerData.setNodeState(node, NodeState.UNLOCKABLE);
} else { } else {
boolean isUnlockableFromStrongParent = node.getStrongParents().size()==0?true:true; boolean isUnlockableFromStrongParent = node.getStrongParents().size() == 0 ? true : true;
boolean isUnlockableFromSoftParent = node.getSoftParents().size()==0?true:false; boolean isUnlockableFromSoftParent = node.getSoftParents().size() == 0 ? true : false;
boolean isFullyLockedFromStrongParent = node.getStrongParents().size()==0?false:false; boolean isFullyLockedFromStrongParent = node.getStrongParents().size() == 0 ? false : false;
boolean isFullyLockedFromSoftParent = node.getSoftParents().size()==0?false:true; boolean isFullyLockedFromSoftParent = node.getSoftParents().size() == 0 ? false : true;
for (SkillTreeNode strongParent : node.getStrongParents()) { for (SkillTreeNode strongParent : node.getStrongParents()) {
if (playerData.getNodeLevel(strongParent) < node.getParentNeededLevel(strongParent)) { if (playerData.getNodeLevel(strongParent) < node.getParentNeededLevel(strongParent)) {
@ -210,7 +223,6 @@ public abstract class SkillTree extends PostLoadObject implements RegisterObject
} }
for (SkillTreeNode softParent : node.getSoftParents()) { for (SkillTreeNode softParent : node.getSoftParents()) {
if (playerData.getNodeLevel(softParent) > node.getParentNeededLevel(softParent)) { if (playerData.getNodeLevel(softParent) > node.getParentNeededLevel(softParent)) {
isUnlockableFromSoftParent = true; isUnlockableFromSoftParent = true;