Fixed SQL things

Requires MMOLib 1.3.7.1
This commit is contained in:
ASangarin 2020-10-06 18:59:05 +02:00
parent 54ba6b89b8
commit 239d70117d
7 changed files with 109 additions and 84 deletions

Binary file not shown.

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.4.9</version>
<version>1.4.9.1</version>
<name>MMOCore</name>
<description>Offer your players a brand new RPG experience.</description>

View File

@ -363,6 +363,7 @@ public class MMOCore extends JavaPlugin {
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
dataProvider.close();
mineManager.resetRemainingBlocks();

View File

@ -11,4 +11,5 @@ public interface DataProvider {
PlayerDataManager getDataManager();
GuildDataManager getGuildManager();
void close();
}

View File

@ -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,7 +35,9 @@ 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();
provider.getResultAsync("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';",
(result) -> {
try {
if (!result.first()) {
data.setLevel(getDefaultData().getLevel());
data.setClassPoints(getDefaultData().getClassPoints());
@ -64,7 +65,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
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")));
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")))
@ -75,9 +77,11 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
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)));
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);
JsonObject object = MMOLib.plugin.getJson().parse(result.getString("skills"),
JsonObject.class);
for (Entry<String, JsonElement> entry : object.entrySet())
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
}
@ -86,24 +90,32 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
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);
JsonObject object = MMOLib.plugin.getJson().parse(result.getString("class_info"),
JsonObject.class);
for (Entry<String, JsonElement> 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()));
data.applyClassInfo(profess,
new SavedClassInformation(entry.getValue().getAsJsonObject()));
} 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());
}
}
}
} catch (SQLException | InterruptedException | ExecutionException e) {
} 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,7 +196,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
super(uuid);
try {
ResultSet result = provider.getResultAsync("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';").get();
provider.getResultAsync("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';", (result) -> {
try {
if (!result.first()) {
level = 0;
lastLogin = 0;
@ -194,11 +209,16 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
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)));
getJSONArray(result.getString("friends"))
.forEach(str -> friends.add(UUID.fromString(str)));
else
friends = new ArrayList<UUID>();
}
} catch (SQLException | InterruptedException | ExecutionException e) {
} catch (SQLException e) {
e.printStackTrace();
}
}).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}

View File

@ -17,4 +17,7 @@ public class YAMLDataProvider implements DataProvider {
public GuildDataManager getGuildManager() {
return guildManager;
}
@Override
public void close() {}
}