diff --git a/lib/MMOLib.jar b/lib/MMOLib.jar
index e404e7a8..0bdd3f2a 100644
Binary files a/lib/MMOLib.jar and b/lib/MMOLib.jar differ
diff --git a/pom.xml b/pom.xml
index 3d2f9c8f..d1a3e5ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
net.Indyuce
MMOCore
- 1.4.9
+ 1.4.9.1
MMOCore
Offer your players a brand new RPG experience.
diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java
index d1062557..ef62e600 100644
--- a/src/main/java/net/Indyuce/mmocore/MMOCore.java
+++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java
@@ -363,7 +363,8 @@ public class MMOCore extends JavaPlugin {
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
-
+ dataProvider.close();
+
mineManager.resetRemainingBlocks();
lootChests.getActive().forEach(chest -> chest.unregister(false));
diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/DataProvider.java b/src/main/java/net/Indyuce/mmocore/manager/data/DataProvider.java
index f1afaf38..7c4926a7 100644
--- a/src/main/java/net/Indyuce/mmocore/manager/data/DataProvider.java
+++ b/src/main/java/net/Indyuce/mmocore/manager/data/DataProvider.java
@@ -11,4 +11,5 @@ public interface DataProvider {
PlayerDataManager getDataManager();
GuildDataManager getGuildManager();
+ void close();
}
diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java
index 6c8f0ef8..57c28557 100644
--- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java
+++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java
@@ -11,7 +11,7 @@ import net.mmogroup.mmolib.sql.MMODataSource;
public class MySQLDataProvider extends MMODataSource implements DataProvider {
private final MySQLPlayerDataManager playerManager = new MySQLPlayerDataManager(this);
private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager();
-
+
public MySQLDataProvider(FileConfiguration config) {
this.setup(config);
}
diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java
index d55985c2..57d0e913 100644
--- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java
+++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java
@@ -1,6 +1,5 @@
package net.Indyuce.mmocore.manager.data.mysql;
-import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
@@ -36,74 +35,87 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
@Override
public void loadData(PlayerData data) {
try {
- ResultSet result = provider.getResultAsync("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';").get();
- if (!result.first()) {
- data.setLevel(getDefaultData().getLevel());
- data.setClassPoints(getDefaultData().getClassPoints());
- data.setSkillPoints(getDefaultData().getSkillPoints());
- data.setAttributePoints(getDefaultData().getAttributePoints());
- data.setAttributeReallocationPoints(getDefaultData().getAttributeReallocationPoints());
- data.setExperience(0);
- data.setMana(data.getStats().getStat(StatType.MAX_MANA));
- data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
- data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
- data.getQuestData().updateBossBar();
+ provider.getResultAsync("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';",
+ (result) -> {
+ try {
+ if (!result.first()) {
+ data.setLevel(getDefaultData().getLevel());
+ data.setClassPoints(getDefaultData().getClassPoints());
+ data.setSkillPoints(getDefaultData().getSkillPoints());
+ data.setAttributePoints(getDefaultData().getAttributePoints());
+ data.setAttributeReallocationPoints(getDefaultData().getAttributeReallocationPoints());
+ data.setExperience(0);
+ data.setMana(data.getStats().getStat(StatType.MAX_MANA));
+ data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
+ data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
+ data.getQuestData().updateBossBar();
- return;
- }
+ return;
+ }
- data.setClassPoints(result.getInt("class_points"));
- data.setSkillPoints(result.getInt("skill_points"));
- data.setAttributePoints(result.getInt("attribute_points"));
- data.setAttributeReallocationPoints(result.getInt("attribute_realloc_points"));
- data.setLevel(result.getInt("level"));
- data.setExperience(result.getInt("experience"));
- if (!isEmpty(result.getString("class")))
- data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
- data.setMana(data.getStats().getStat(StatType.MAX_MANA));
- data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
- data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
- if (!isEmpty(result.getString("guild")))
- data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(), result.getString("guild")));
- if (!isEmpty(result.getString("attributes")))
- data.getAttributes().load(result.getString("attributes"));
- if (!isEmpty(result.getString("professions")))
- data.getCollectionSkills().load(result.getString("professions"));
- 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")));
- if (!isEmpty(result.getString("friends")))
- getJSONArray(result.getString("friends")).forEach(str -> data.getFriends().add(UUID.fromString(str)));
- if (!isEmpty(result.getString("skills"))) {
- JsonObject object = MMOLib.plugin.getJson().parse(result.getString("skills"), JsonObject.class);
- for (Entry entry : object.entrySet())
- data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
- }
- if (!isEmpty(result.getString("bound_skills")))
- for (String skill : getJSONArray(result.getString("bound_skills")))
- if (data.getProfess().hasSkill(skill))
- data.getBoundSkills().add(data.getProfess().getSkill(skill));
- if (!isEmpty(result.getString("class_info"))) {
- JsonObject object = MMOLib.plugin.getJson().parse(result.getString("class_info"), JsonObject.class);
- for (Entry entry : object.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());
- }
- }
- }
- } catch (SQLException | InterruptedException | ExecutionException e) {
+ data.setClassPoints(result.getInt("class_points"));
+ data.setSkillPoints(result.getInt("skill_points"));
+ data.setAttributePoints(result.getInt("attribute_points"));
+ data.setAttributeReallocationPoints(result.getInt("attribute_realloc_points"));
+ data.setLevel(result.getInt("level"));
+ data.setExperience(result.getInt("experience"));
+ if (!isEmpty(result.getString("class")))
+ data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
+ data.setMana(data.getStats().getStat(StatType.MAX_MANA));
+ data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
+ data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
+ if (!isEmpty(result.getString("guild")))
+ data.setGuild(MMOCore.plugin.dataProvider.getGuildManager()
+ .stillInGuild(data.getUniqueId(), result.getString("guild")));
+ if (!isEmpty(result.getString("attributes")))
+ data.getAttributes().load(result.getString("attributes"));
+ if (!isEmpty(result.getString("professions")))
+ data.getCollectionSkills().load(result.getString("professions"));
+ 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")));
+ if (!isEmpty(result.getString("friends")))
+ getJSONArray(result.getString("friends"))
+ .forEach(str -> data.getFriends().add(UUID.fromString(str)));
+ if (!isEmpty(result.getString("skills"))) {
+ JsonObject object = MMOLib.plugin.getJson().parse(result.getString("skills"),
+ JsonObject.class);
+ for (Entry entry : object.entrySet())
+ data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
+ }
+ if (!isEmpty(result.getString("bound_skills")))
+ for (String skill : getJSONArray(result.getString("bound_skills")))
+ if (data.getProfess().hasSkill(skill))
+ data.getBoundSkills().add(data.getProfess().getSkill(skill));
+ if (!isEmpty(result.getString("class_info"))) {
+ JsonObject object = MMOLib.plugin.getJson().parse(result.getString("class_info"),
+ JsonObject.class);
+ for (Entry entry : object.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());
+ }
+ }
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }).get();
+ } catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
private boolean isEmpty(String s) {
- return s.equalsIgnoreCase("null") || s.equalsIgnoreCase("{}") || s.equalsIgnoreCase("[]") || s.equalsIgnoreCase("");
+ return s == null || s.equalsIgnoreCase("null") || s.equalsIgnoreCase("{}") || s.equalsIgnoreCase("[]")
+ || s.equalsIgnoreCase("");
}
@Override
@@ -121,8 +133,10 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
sql.updateData("guild", data.hasGuild() ? data.getGuild().getId() : null);
sql.updateJSONArray("waypoints", data.getWaypoints());
- sql.updateJSONArray("friends", data.getFriends().stream().map(uuid -> uuid.toString()).collect(Collectors.toList()));
- sql.updateJSONArray("bound_skills", data.getBoundSkills().stream().map(skill -> skill.getSkill().getId()).collect(Collectors.toList()));
+ sql.updateJSONArray("friends",
+ data.getFriends().stream().map(uuid -> uuid.toString()).collect(Collectors.toList()));
+ sql.updateJSONArray("bound_skills",
+ data.getBoundSkills().stream().map(skill -> skill.getSkill().getId()).collect(Collectors.toList()));
sql.updateJSONObject("skills", data.mapSkillLevels().entrySet());
@@ -182,23 +196,29 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
super(uuid);
try {
- ResultSet result = provider.getResultAsync("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';").get();
- if (!result.first()) {
- level = 0;
- lastLogin = 0;
- profess = MMOCore.plugin.classManager.getDefaultClass();
- friends = new ArrayList();
- } 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();
- }
- } catch (SQLException | InterruptedException | ExecutionException e) {
+ provider.getResultAsync("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';", (result) -> {
+ try {
+ if (!result.first()) {
+ level = 0;
+ lastLogin = 0;
+ profess = MMOCore.plugin.classManager.getDefaultClass();
+ friends = new ArrayList();
+ } 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();
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }).get();
+ } catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLDataProvider.java b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLDataProvider.java
index bcf89817..4c615c30 100644
--- a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLDataProvider.java
+++ b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLDataProvider.java
@@ -17,4 +17,7 @@ public class YAMLDataProvider implements DataProvider {
public GuildDataManager getGuildManager() {
return guildManager;
}
+
+ @Override
+ public void close() {}
}