Handling of unlockedItems on MySQLPlayerDataManager when loading/saving playerData.

This commit is contained in:
Ka0rX 2023-03-21 21:03:35 +01:00
parent 1deed752f4
commit 713146d9dd
3 changed files with 21 additions and 14 deletions

View File

@ -1,9 +1,6 @@
package net.Indyuce.mmocore.manager.data.mysql;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.*;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.sql.DataSynchronizer;
import net.Indyuce.mmocore.MMOCore;
@ -20,8 +17,7 @@ import org.jetbrains.annotations.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;
public class MMOCoreDataSynchronizer extends DataSynchronizer {
@ -74,8 +70,11 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer {
}
}
data.setupSkillTree();
Set<String> unlockedItems = new HashSet<>();
JsonArray unlockedItemsArray = new JsonParser().parse(result.getString("unlocked_items")).getAsJsonArray();
for (JsonElement item : unlockedItemsArray)
unlockedItems.add(item.getAsString());
data.setUnlockedItems(unlockedItems);
if (!isEmpty(result.getString("guild"))) {
Guild guild = MMOCore.plugin.dataProvider.getGuildManager().getGuild(result.getString("guild"));
data.setGuild(guild.hasMember(data.getUniqueId()) ? guild : null);

View File

@ -21,6 +21,7 @@ public class MySQLDataProvider extends MMODataSource implements DataProvider {
"skill_tree_reallocation_points", "INT(11)",
"skill_tree_points", "LONGTEXT",
"skill_tree_levels", "LONGTEXT",
"unlocked_items","LONGTEXT",
"mana","FLOAT",
"stamina","FLOAT",
"stellium","FLOAT"};
@ -56,6 +57,7 @@ public class MySQLDataProvider extends MMODataSource implements DataProvider {
"friends LONGTEXT," +
"skills LONGTEXT," +
"bound_skills LONGTEXT," +
"unlocked_items LONGTEXT," +
"class_info LONGTEXT," +
"is_saved TINYINT," +
"PRIMARY KEY (uuid));");

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.manager.data.mysql;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore;
@ -54,7 +55,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
updater.addData("guild", data.hasGuild() ? data.getGuild().getId() : null);
updater.addJSONArray("waypoints", data.getWaypoints());
updater.addJSONArray("friends", data.getFriends().stream().map(UUID::toString).collect(Collectors.toList()));
updater.addJSONObject("bound_skills",data.mapBoundSkills().entrySet());
updater.addJSONObject("bound_skills", data.mapBoundSkills().entrySet());
updater.addJSONObject("skills", data.mapSkillLevels().entrySet());
updater.addJSONObject("times_claimed", data.getItemClaims().entrySet());
updater.addJSONObject("skill_tree_points", data.mapSkillTreePoints().entrySet());
@ -63,6 +64,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
updater.addData("professions", data.getCollectionSkills().toJsonString());
updater.addData("quests", data.getQuestData().toJsonString());
updater.addData("class_info", createClassInfoData(data).toString());
updater.addJSONArray("unlocked_items", data.getUnlockedItems());
if (logout)
updater.addData("is_saved", 1);
@ -88,7 +90,11 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
classinfo.addProperty("mana", info.getMana());
classinfo.addProperty("stamina", info.getStamina());
classinfo.addProperty("stellium", info.getStellium());
JsonArray array = new JsonArray();
for (String unlockedItem : playerData.getUnlockedItems()) {
array.add(unlockedItem);
}
classinfo.add("unlocked-items", array);
JsonObject skillinfo = new JsonObject();
for (String skill : info.getSkillKeys())
skillinfo.addProperty(skill, info.getSkillLevel(skill));
@ -109,8 +115,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
classinfo.add("skill-tree-points", skillTreePointsInfo);
JsonObject boundSkillInfo = new JsonObject();
for(int slot:info.getBoundSkills().keySet())
boundSkillInfo.addProperty(slot+"",info.getBoundSkills().get(slot));
for (int slot : info.getBoundSkills().keySet())
boundSkillInfo.addProperty(slot + "", info.getBoundSkills().get(slot));
classinfo.add("bound-skills", boundSkillInfo);
json.add(c, classinfo);
@ -165,8 +171,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
@Override
public void removeFriend(UUID uuid) {
// TODO recode
// friends.remove(uuid);
// new PlayerDataTableUpdater(provider, uuid).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList()));
// friends.remove(uuid);
// new PlayerDataTableUpdater(provider, uuid).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList()));
}
@Override