mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
SavingPlayerData. Object to store all the data of an offline player. Restructuration for /mmocore admin transferdata
This commit is contained in:
parent
5589609750
commit
6af4c2ee46
@ -1,5 +1,6 @@
|
|||||||
package net.Indyuce.mmocore.manager.data.mysql;
|
package net.Indyuce.mmocore.manager.data.mysql;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
@ -14,6 +15,7 @@ import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
|||||||
import net.Indyuce.mmocore.guild.provided.Guild;
|
import net.Indyuce.mmocore.guild.provided.Guild;
|
||||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -238,12 +240,14 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
result.getString("class_info"));
|
result.getString("class_info"));
|
||||||
|
|
||||||
savingPlayerDataList.add(data);
|
savingPlayerDataList.add(data);
|
||||||
|
Bukkit.broadcastMessage(new Gson().toJson(data));
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import net.Indyuce.mmocore.guild.provided.Guild;
|
|||||||
import net.Indyuce.mmocore.manager.data.DataProvider;
|
import net.Indyuce.mmocore.manager.data.DataProvider;
|
||||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -166,9 +167,10 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
config.set("level", data.level());
|
config.set("level", data.level());
|
||||||
config.set("experience", data.experience());
|
config.set("experience", data.experience());
|
||||||
config.set("class", data.classId());
|
config.set("class", data.classId());
|
||||||
config.set("waypoints", data.waypoints());
|
config.set("waypoints", data.waypoints().stream().toList());
|
||||||
config.set("friends", data.friends());
|
config.set("friends", data.friends());
|
||||||
config.set("last-login", data.lastLogin());
|
config.set("last-login", data.lastLogin());
|
||||||
|
if (data.guildId() != null)
|
||||||
config.set("guild", data.guildId());
|
config.set("guild", data.guildId());
|
||||||
|
|
||||||
config.set("skill", null);
|
config.set("skill", null);
|
||||||
@ -185,7 +187,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
for (Map.Entry<String, JsonElement> entry : jo.entrySet()) {
|
for (Map.Entry<String, JsonElement> entry : jo.entrySet()) {
|
||||||
try {
|
try {
|
||||||
String id = entry.getKey().toLowerCase().replace("_", "-").replace(" ", "-");
|
String id = entry.getKey().toLowerCase().replace("_", "-").replace(" ", "-");
|
||||||
config.set("attributes." + id, entry.getValue().getAsInt());
|
config.set("attribute." + id, entry.getValue().getAsInt());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -248,6 +250,8 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bukkit.broadcastMessage("SAVED");
|
||||||
file.save();
|
file.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,9 +266,11 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
FileConfiguration config = new ConfigFile(uuid).getConfig();
|
FileConfiguration config = new ConfigFile(uuid).getConfig();
|
||||||
|
|
||||||
Map<String, Integer> skills = new HashMap<>();
|
Map<String, Integer> skills = new HashMap<>();
|
||||||
|
if (config.contains("skill"))
|
||||||
config.getConfigurationSection("skill").getKeys(false).forEach(id -> skills.put(id, config.getInt("skill." + id)));
|
config.getConfigurationSection("skill").getKeys(false).forEach(id -> skills.put(id, config.getInt("skill." + id)));
|
||||||
|
|
||||||
Map<String, Integer> itemClaims = new HashMap<>();
|
Map<String, Integer> itemClaims = new HashMap<>();
|
||||||
|
if (config.contains("times-claimed"))
|
||||||
for (String key : config.getConfigurationSection("times-claimed").getKeys(true))
|
for (String key : config.getConfigurationSection("times-claimed").getKeys(true))
|
||||||
itemClaims.put(key, config.getInt("times-claimed." + key));
|
itemClaims.put(key, config.getInt("times-claimed." + key));
|
||||||
|
|
||||||
@ -274,6 +280,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
|
|
||||||
ConfigurationSection section = config.getConfigurationSection("attributes");
|
ConfigurationSection section = config.getConfigurationSection("attributes");
|
||||||
JsonObject attributesJson = new JsonObject();
|
JsonObject attributesJson = new JsonObject();
|
||||||
|
if (section != null)
|
||||||
for (String key : section.getKeys(false)) {
|
for (String key : section.getKeys(false)) {
|
||||||
String id = key.toLowerCase().replace("-", "_").replace(" ", "_");
|
String id = key.toLowerCase().replace("-", "_").replace(" ", "_");
|
||||||
attributesJson.addProperty(id, section.getInt(key));
|
attributesJson.addProperty(id, section.getInt(key));
|
||||||
@ -285,8 +292,8 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
|
|
||||||
section = config.getConfigurationSection("profession");
|
section = config.getConfigurationSection("profession");
|
||||||
JsonObject collectionSkillsJson = new JsonObject();
|
JsonObject collectionSkillsJson = new JsonObject();
|
||||||
;
|
if (section != null)
|
||||||
for (String key : config.getKeys(false)) {
|
for (String key : section.getKeys(false)) {
|
||||||
if (MMOCore.plugin.professionManager.has(key)) {
|
if (MMOCore.plugin.professionManager.has(key)) {
|
||||||
JsonObject object = new JsonObject();
|
JsonObject object = new JsonObject();
|
||||||
object.addProperty("exp", section.getDouble(key + ".exp"));
|
object.addProperty("exp", section.getDouble(key + ".exp"));
|
||||||
|
Loading…
Reference in New Issue
Block a user