Bungee update

This commit is contained in:
Ka0rX 2022-06-19 21:46:16 +02:00
parent 617c2a3713
commit 5dd060abc6
12 changed files with 939 additions and 588 deletions

View File

@ -27,6 +27,7 @@ import net.Indyuce.mmocore.comp.vault.VaultEconomy;
import net.Indyuce.mmocore.comp.vault.VaultMMOLoader;
import net.Indyuce.mmocore.guild.provided.Guild;
import net.Indyuce.mmocore.listener.*;
import net.Indyuce.mmocore.listener.bungee.GetMMOCorePlayerListener;
import net.Indyuce.mmocore.listener.event.PlayerPressKeyListener;
import net.Indyuce.mmocore.listener.option.*;
import net.Indyuce.mmocore.listener.profession.FishingListener;
@ -51,6 +52,7 @@ import org.bukkit.command.CommandMap;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import org.spigotmc.SpigotConfig;
import java.io.File;
import java.lang.reflect.Field;
@ -99,7 +101,7 @@ public class MMOCore extends LuminePlugin {
public PartyModule partyModule;
public boolean shouldDebugSQL = false;
public boolean hasBungee=false;
private static final int MYTHICLIB_COMPATIBILITY_INDEX = 7;
public MMOCore() {
@ -174,6 +176,22 @@ public class MMOCore extends LuminePlugin {
MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs");
}
//Checks if the server runs with bungee
boolean bungee = SpigotConfig.bungee;
boolean onlineMode = Bukkit.getServer().getOnlineMode();
if (bungee && (!(onlineMode)))
hasBungee=true;
else
hasBungee=false;
//Setups the channel for Bungee
if(hasBungee) {
getServer().getMessenger().registerOutgoingPluginChannel(this,"namespace:give_mmocore_player");
getServer().getMessenger().registerOutgoingPluginChannel(this,"namespace:get_mmocore_player");
getServer().getMessenger().registerIncomingPluginChannel(this,"namespace:get_mmocore_player",new GetMMOCorePlayerListener());
}
/*
* Resource regeneration. Must check if entity is dead otherwise regen will make
* the 'respawn' button glitched plus HURT entity effect bug
@ -226,7 +244,6 @@ public class MMOCore extends LuminePlugin {
}
// Load party module
try {
String partyPluginName = UtilityMethods.enumName(getConfig().getString("party-plugin"));
@ -375,7 +392,7 @@ public class MMOCore extends LuminePlugin {
* Called either when the server starts when initializing the manager for
* the first time, or when issuing a plugin reload; in that case, stuff
* like listeners must all be cleared before.
*
* <p>
* Also see {@link MMOCoreManager}
*
* @param clearBefore True when issuing a plugin reload

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.api.player;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.api.player.MMOPlayerData;
import io.lumine.mythic.lib.player.TemporaryPlayerData;
import io.lumine.mythic.lib.player.cooldown.CooldownMap;
@ -28,6 +29,7 @@ import net.Indyuce.mmocore.experience.droptable.ExperienceItem;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.guild.provided.Guild;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import net.Indyuce.mmocore.manager.data.mysql.MySQLTableEditor;
import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.party.provided.Party;
import net.Indyuce.mmocore.player.Unlockable;
@ -50,6 +52,7 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class PlayerData extends OfflinePlayerData implements Closable, ExperienceTableClaimer {
@ -508,6 +511,64 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
}.runTaskTimer(MMOCore.plugin, 0, 1);
}
public String toJson() {
//We create the JSON correspondign to player Data
JsonObject jsonObject = new JsonObject();
MySQLTableEditor sql = new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, getUniqueId());
MMOCore.sqlDebug("Saving data for: '" + getUniqueId() + "'...");
jsonObject.addProperty("class_points", getClassPoints());
jsonObject.addProperty("skill_points", getSkillPoints());
jsonObject.addProperty("attribute_points", getAttributePoints());
jsonObject.addProperty("attribute_realloc_points", getAttributeReallocationPoints());
jsonObject.addProperty("level", getLevel());
jsonObject.addProperty("experience", getExperience());
jsonObject.addProperty("class", getProfess().getId());
jsonObject.addProperty("last_login", getLastLogin());
jsonObject.addProperty("guild", hasGuild() ? getGuild().getId() : null);
jsonObject.addProperty("waypoints", MMOCoreUtils.arrayToJsonString(getWaypoints()));
jsonObject.addProperty("friends", MMOCoreUtils.arrayToJsonString(getFriends().stream().map(UUID::toString).collect(Collectors.toList())));
jsonObject.addProperty("bound_skills", MMOCoreUtils.arrayToJsonString(getBoundSkills().stream().map(skill -> skill.getSkill().getHandler().getId()).collect(Collectors.toList())));
jsonObject.addProperty("skills", MMOCoreUtils.entrySetToJsonString(mapSkillLevels().entrySet()));
jsonObject.addProperty("times_claimed", MMOCoreUtils.entrySetToJsonString(getItemClaims().entrySet()));
jsonObject.addProperty("attributes", getAttributes().toJsonString());
jsonObject.addProperty("professions", getCollectionSkills().toJsonString());
jsonObject.addProperty("quests", getQuestData().toJsonString());
jsonObject.addProperty("class_info", createClassInfoData(this).toString());
return jsonObject.toString();
}
public static JsonObject createClassInfoData(PlayerData data) {
JsonObject json = new JsonObject();
for (String c : data.getSavedClasses()) {
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);
json.add(c, classinfo);
}
return json;
}
public boolean hasReachedMaxLevel() {
return getProfess().getMaxLevel() > 0 && getLevel() >= getProfess().getMaxLevel();
}

View File

@ -1,5 +1,7 @@
package net.Indyuce.mmocore.api.util;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.version.VersionMaterial;
import io.lumine.mythic.utils.holograms.Hologram;
@ -26,9 +28,7 @@ import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
public class MMOCoreUtils {
public static boolean pluginItem(ItemStack item) {
@ -140,6 +140,27 @@ public class MMOCoreUtils {
return result.toString();
}
public static Collection<String> jsonArrayToList(String json) {
return new ArrayList<>(Arrays.asList(MythicLib.plugin.getJson().parse(json, String[].class)));
}
public static String arrayToJsonString(Collection<String> array) {
JsonArray object = new JsonArray();
for (String str : array) {
object.add(str);
}
return object.toString();
}
public static String entrySetToJsonString(Set<Map.Entry<String, Integer>> entrySet) {
JsonObject object = new JsonObject();
for (Map.Entry<String, Integer> entry : entrySet) {
object.addProperty(entry.getKey(), entry.getValue());
}
return object.toString();
}
/**
* Method to get all entities surrounding a location. This method does not
* take every entity in the world but rather takes all the entities from the

View File

@ -0,0 +1,52 @@
package net.Indyuce.mmocore.bungee;
import net.md_5.bungee.api.plugin.Plugin;
import org.checkerframework.checker.units.qual.C;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
public class Bungee extends Plugin {
public static Bungee plugin;
public CacheManager cacheManager = new CacheManager();
@Override
public void onEnable() {
//Register a new communication channel
getProxy().registerChannel("give_mmocore_player");
getProxy().registerChannel("get_mmocore_player");
getProxy().getPluginManager().registerListener(this, new MessageListener());
try {
getProxy().getLogger().log(Level.WARNING,"enabling socket");
ServerSocket serverSocket= new ServerSocket(25580);
Socket clientSocket=serverSocket.accept();
getProxy().getLogger().log(Level.WARNING,"port: "+clientSocket.getPort());
BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String line;
while((line=bufferedReader.readLine())!=null) {
getProxy().getLogger().log(Level.WARNING,line);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void onDisable() {
}
@Override
public void onLoad() {
plugin = this;
}
}

View File

@ -0,0 +1,28 @@
package net.Indyuce.mmocore.bungee;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.manager.data.mysql.MySQLTableEditor;
import java.util.HashMap;
import java.util.UUID;
import java.util.stream.Collectors;
public class CacheManager {
private final HashMap<UUID,String> cachedPlayers= new HashMap<>();
public String getCachedPlayer(UUID uuid) {
return cachedPlayers.get(uuid);
}
public boolean hasCachedPlayer(UUID uuid) {
return cachedPlayers.containsKey(uuid);
}
public void addCachedPlayer(UUID uuid,String playerData) {
cachedPlayers.put(uuid,playerData);
}
public void save() {
}
}

View File

@ -0,0 +1,65 @@
package net.Indyuce.mmocore.bungee;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.Collection;
import java.util.UUID;
public class MessageListener implements Listener {
/**
* Used to register in the cached Players the data that is sent
*/
@EventHandler
public void onPluginMessage(PluginMessageEvent e) throws IOException {
//When a server gives the player data
if (e.getTag().equals("give_mmocore_player")) {
byte[] data = e.getData();
ByteArrayInputStream in = new ByteArrayInputStream(e.getData());
DataInputStream inputStream = new DataInputStream(in);
UUID uuid = UUID.fromString(inputStream.readUTF());
String jsonMsg = inputStream.readUTF();
//We put this data into the CacheManager
Bungee.plugin.cacheManager.addCachedPlayer(uuid,jsonMsg);
}
//When a server asks for the player data
if (e.getTag().equals("get_mmocore_player")) {
byte[] data = e.getData();
ByteArrayInputStream in = new ByteArrayInputStream(e.getData());
DataInputStream inputStream = new DataInputStream(in);
UUID uuid = UUID.fromString(inputStream.readUTF());
String response=Bungee.plugin.cacheManager.hasCachedPlayer(uuid)?
Bungee.plugin.cacheManager.getCachedPlayer(uuid):"{}";
//We format the data corresponding to the player
ByteArrayOutputStream out=new ByteArrayOutputStream();
DataOutputStream outputStream= new DataOutputStream(out);
outputStream.writeChars(response);
//We get the corresponding player
ProxiedPlayer proxiedPlayer= Bungee.plugin.getProxy().getPlayer(uuid);
//We send the answer
proxiedPlayer.getServer().getInfo().sendData("get_mmocore_player",out.toByteArray());
}
}
}

View File

@ -30,8 +30,8 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
else {
String str = config.getString("type").toUpperCase().replace("-", "_");
Validate.isTrue(str.equals("LADDER") ||
str.equals("VINE") || str.equals("TWISTING_VINES_PLANT") || str.equals("WEEPING_VINES"),
"ClimbExperienceSource problem: The type must be ladder, vine, twisted-vines or weeping-vines");
str.equals("VINE") || str.equals("TWISTING_VINES") || str.equals("WEEPING_VINES"),
"ClimbExperienceSource problem: The type must be ladder, vine, twisting-vines or weeping-vines");
type = Material.valueOf(str);
}

View File

@ -0,0 +1,21 @@
package net.Indyuce.mmocore.listener.bungee;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.util.UUID;
public class GetMMOCorePlayerListener implements PluginMessageListener {
@Override
public void onPluginMessageReceived( String channel, Player player, byte[] bytes) {
if(!channel.equals("give_mmocore_player"))
return;
ByteArrayDataInput input= ByteStreams.newDataInput(bytes);
UUID uuid=UUID.fromString(input.readUTF());
String Json=input.readUTF();
}
}

View File

@ -1,5 +1,9 @@
package net.Indyuce.mmocore.manager.data;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.player.MMOPlayerData;
import io.lumine.mythic.lib.player.TemporaryPlayerData;
import net.Indyuce.mmocore.MMOCore;
@ -7,12 +11,18 @@ import net.Indyuce.mmocore.api.event.AsyncPlayerDataLoadEvent;
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.guild.provided.Guild;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.logging.Level;
public abstract class PlayerDataManager {
private final static Map<UUID, PlayerData> data = Collections.synchronizedMap(new HashMap<>());
@ -35,6 +45,63 @@ public abstract class PlayerDataManager {
return Objects.requireNonNull(data.get(uuid), "Player data is not loaded");
}
public static void loadDataFromJson(PlayerData data, String json) {
JsonObject object = MythicLib.plugin.getJson().parse(json, JsonObject.class);
data.setClassPoints(object.get("class_points").getAsInt());
data.setSkillPoints(object.get("skill_points").getAsInt());
data.setAttributePoints(object.get("attribute_points").getAsInt());
data.setAttributeReallocationPoints(object.get("attribute_realloc_points").getAsInt());
data.setLevel(object.get("level").getAsInt());
data.setExperience(object.get("experience").getAsInt());
if (object.has("class"))
data.setClass(MMOCore.plugin.classManager.get(object.get(("class")).getAsString()));
if (object.has("times_claimed")) {
JsonObject timesClaimed =object.get(("times_claimed")).getAsJsonObject();
timesClaimed.entrySet().forEach(entry -> data.getItemClaims().put(entry.getKey(), entry.getValue().getAsInt()));
}
if (object.has(("guild"))) {
Guild guild = MMOCore.plugin.dataProvider.getGuildManager().getGuild(object.get("guild").getAsString());
data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null);
}
if (object.has(("attributes"))) data.getAttributes().load(object.get("attributes").getAsString());
if (object.has(("professions")))
data.getCollectionSkills().load(object.get("professions").getAsString());
if (object.has(("quests"))) data.getQuestData().load(object.get("quests").getAsString());
data.getQuestData().updateBossBar();
if (object.has(("waypoints")))
data.getWaypoints().addAll(MMOCoreUtils.jsonArrayToList(object.get("waypoints").getAsString()));
if (object.has(("friends")))
MMOCoreUtils.jsonArrayToList(object.get("friends").getAsString()).forEach(str -> data.getFriends().add(UUID.fromString(str)))
;
if (object.has(("skills"))) {
JsonObject skillsObject = object.get("skills").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : skillsObject.entrySet())
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
}
if (object.has(("bound_skills")))
for (String skill : MMOCoreUtils.jsonArrayToList(object.get("bound_skills").getAsString()))
if (data.getProfess().hasSkill(skill))
data.getBoundSkills().add(data.getProfess().getSkill(skill));
if (object.has(("class_info"))) {
JsonObject classObject = object.get("class_info").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : classObject.entrySet()) {
try {
PlayerClass profess = MMOCore.plugin.classManager.get(entry.getKey());
Validate.notNull(profess, "Could not find class '" + entry.getKey() + "'");
data.applyClassInfo(profess, new SavedClassInformation(entry.getValue().getAsJsonObject()));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not load class info '" + entry.getKey() + "': " + exception.getMessage());
}
}
}
}
/**
* Safely unregisters the player data from the map.
* This saves the player data either through SQL or YAML,

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.manager.data.mysql;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@ -9,18 +10,24 @@ import net.Indyuce.mmocore.api.player.OfflinePlayerData;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.guild.provided.Guild;
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
import net.Indyuce.mmocore.manager.data.mysql.MySQLTableEditor.Table;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.net.Socket;
import java.sql.SQLException;
import java.util.*;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static net.Indyuce.mmocore.api.player.PlayerData.createClassInfoData;
public class MySQLPlayerDataManager extends PlayerDataManager {
private final MySQLDataProvider provider;
@ -70,7 +77,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
}
if (!isEmpty(result.getString("guild"))) {
Guild guild = provider.getGuildManager().getGuild(result.getString("guild"));
Guild guild = MMOCore.plugin.dataProvider.getGuildManager().getGuild(result.getString("guild"));
data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null);
}
if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes"));
@ -79,16 +86,16 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
if (!isEmpty(result.getString("quests"))) data.getQuestData().load(result.getString("quests"));
data.getQuestData().updateBossBar();
if (!isEmpty(result.getString("waypoints")))
data.getWaypoints().addAll(getJSONArray(result.getString("waypoints")));
data.getWaypoints().addAll(MMOCoreUtils.jsonArrayToList(result.getString("waypoints")));
if (!isEmpty(result.getString("friends")))
getJSONArray(result.getString("friends")).forEach(str -> data.getFriends().add(UUID.fromString(str)));
MMOCoreUtils.jsonArrayToList(result.getString("friends")).forEach(str -> data.getFriends().add(UUID.fromString(str)));
if (!isEmpty(result.getString("skills"))) {
JsonObject object = MythicLib.plugin.getJson().parse(result.getString("skills"), JsonObject.class);
for (Entry<String, JsonElement> entry : object.entrySet())
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
}
if (!isEmpty(result.getString("bound_skills")))
for (String skill : getJSONArray(result.getString("bound_skills")))
for (String skill : MMOCoreUtils.jsonArrayToList(result.getString("bound_skills")))
if (data.getProfess().hasSkill(skill))
data.getBoundSkills().add(data.getProfess().getSkill(skill));
if (!isEmpty(result.getString("class_info"))) {
@ -104,6 +111,10 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
}
}
//We now change the saved status to false because the data on SQL won't be the same as in the RAM
MySQLTableEditor sql = new MySQLTableEditor(Table.PLAYERDATA, data.getUniqueId());
data.setFullyLoaded();
MMOCore.sqlDebug("Loaded saved data for: '" + data.getUniqueId() + "'!");
MMOCore.sqlDebug(String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
@ -119,7 +130,35 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
@Override
public void saveData(PlayerData data) {
MySQLTableEditor sql = new MySQLTableEditor(Table.PLAYERDATA, data.getUniqueId());
if (MMOCore.plugin.hasBungee) {
//Initialize a connection with bungee using Sockets
try {
Socket socket=new Socket("localhost",25580);
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
writer.write("BONJOUR");
} catch (IOException e) {
throw new RuntimeException(e);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputStream outStream = new DataOutputStream(out);
try {
outStream.writeChars(data.toJson());
} catch (IOException e) {
MMOCore.plugin.getLogger().log(Level.SEVERE, "Couldn't send the data to Bungee for player " + data.getPlayer().getName());
return;
}
MMOCore.plugin.getLogger().log(Level.WARNING, "BUNGEE"+ Bukkit.getOnlinePlayers().size());
MMOCore.sqlDebug("Sent data to bungee for: " + data.getUniqueId());
MMOCore.sqlDebug(String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
} else {
MySQLTableEditor sql = new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, data.getUniqueId());
MMOCore.sqlDebug("Saving data for: '" + data.getUniqueId() + "'...");
sql.updateData("class_points", data.getClassPoints());
@ -145,34 +184,14 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
sql.updateData("class_info", createClassInfoData(data).toString());
MMOCore.sqlDebug("Saved data for: " + data.getUniqueId());
MMOCore.sqlDebug(String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel()));
}
}
private JsonObject createClassInfoData(PlayerData data) {
JsonObject json = new JsonObject();
for (String c : data.getSavedClasses()) {
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);
json.add(c, classinfo);
}
return json;
}
@NotNull
@Override
@ -180,9 +199,6 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
return isLoaded(uuid) ? get(uuid) : new MySQLOfflinePlayerData(uuid);
}
private Collection<String> getJSONArray(String json) {
return new ArrayList<>(Arrays.asList(MythicLib.plugin.getJson().parse(json, String[].class)));
}
public class MySQLOfflinePlayerData extends OfflinePlayerData {
private int level;
@ -207,7 +223,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
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)));
MMOCoreUtils.jsonArrayToList(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
else friends = new ArrayList<>();
MMOCore.sqlDebug("Saved OFFLINE data loaded.");
}

View File

@ -0,0 +1,3 @@
name: MMOCore
main: net.Indyuce.mmocore.bungee.Bungee
author: Ka0rX