forked from Upstream/mmocore
Fixed SQL things
Requires MMOLib 1.3.7.1
This commit is contained in:
parent
54ba6b89b8
commit
239d70117d
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>net.Indyuce</groupId>
|
<groupId>net.Indyuce</groupId>
|
||||||
<artifactId>MMOCore</artifactId>
|
<artifactId>MMOCore</artifactId>
|
||||||
<version>1.4.9</version>
|
<version>1.4.9.1</version>
|
||||||
<name>MMOCore</name>
|
<name>MMOCore</name>
|
||||||
<description>Offer your players a brand new RPG experience.</description>
|
<description>Offer your players a brand new RPG experience.</description>
|
||||||
|
|
||||||
|
@ -363,6 +363,7 @@ public class MMOCore extends JavaPlugin {
|
|||||||
|
|
||||||
for (Guild guild : dataProvider.getGuildManager().getAll())
|
for (Guild guild : dataProvider.getGuildManager().getAll())
|
||||||
dataProvider.getGuildManager().save(guild);
|
dataProvider.getGuildManager().save(guild);
|
||||||
|
dataProvider.close();
|
||||||
|
|
||||||
mineManager.resetRemainingBlocks();
|
mineManager.resetRemainingBlocks();
|
||||||
|
|
||||||
|
@ -11,4 +11,5 @@ public interface DataProvider {
|
|||||||
|
|
||||||
PlayerDataManager getDataManager();
|
PlayerDataManager getDataManager();
|
||||||
GuildDataManager getGuildManager();
|
GuildDataManager getGuildManager();
|
||||||
|
void close();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.Indyuce.mmocore.manager.data.mysql;
|
package net.Indyuce.mmocore.manager.data.mysql;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -36,7 +35,9 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
@Override
|
@Override
|
||||||
public void loadData(PlayerData data) {
|
public void loadData(PlayerData data) {
|
||||||
try {
|
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()) {
|
if (!result.first()) {
|
||||||
data.setLevel(getDefaultData().getLevel());
|
data.setLevel(getDefaultData().getLevel());
|
||||||
data.setClassPoints(getDefaultData().getClassPoints());
|
data.setClassPoints(getDefaultData().getClassPoints());
|
||||||
@ -64,7 +65,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
||||||
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
||||||
if (!isEmpty(result.getString("guild")))
|
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")))
|
if (!isEmpty(result.getString("attributes")))
|
||||||
data.getAttributes().load(result.getString("attributes"));
|
data.getAttributes().load(result.getString("attributes"));
|
||||||
if (!isEmpty(result.getString("professions")))
|
if (!isEmpty(result.getString("professions")))
|
||||||
@ -75,9 +77,11 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
if (!isEmpty(result.getString("waypoints")))
|
if (!isEmpty(result.getString("waypoints")))
|
||||||
data.getWaypoints().addAll(getJSONArray(result.getString("waypoints")));
|
data.getWaypoints().addAll(getJSONArray(result.getString("waypoints")));
|
||||||
if (!isEmpty(result.getString("friends")))
|
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"))) {
|
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())
|
for (Entry<String, JsonElement> entry : object.entrySet())
|
||||||
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
|
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
|
||||||
}
|
}
|
||||||
@ -86,24 +90,32 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
if (data.getProfess().hasSkill(skill))
|
if (data.getProfess().hasSkill(skill))
|
||||||
data.getBoundSkills().add(data.getProfess().getSkill(skill));
|
data.getBoundSkills().add(data.getProfess().getSkill(skill));
|
||||||
if (!isEmpty(result.getString("class_info"))) {
|
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()) {
|
for (Entry<String, JsonElement> entry : object.entrySet()) {
|
||||||
try {
|
try {
|
||||||
PlayerClass profess = MMOCore.plugin.classManager.get(entry.getKey());
|
PlayerClass profess = MMOCore.plugin.classManager.get(entry.getKey());
|
||||||
Validate.notNull(profess, "Could not find class '" + 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) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmpty(String s) {
|
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
|
@Override
|
||||||
@ -121,8 +133,10 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
sql.updateData("guild", data.hasGuild() ? data.getGuild().getId() : null);
|
sql.updateData("guild", data.hasGuild() ? data.getGuild().getId() : null);
|
||||||
|
|
||||||
sql.updateJSONArray("waypoints", data.getWaypoints());
|
sql.updateJSONArray("waypoints", data.getWaypoints());
|
||||||
sql.updateJSONArray("friends", data.getFriends().stream().map(uuid -> uuid.toString()).collect(Collectors.toList()));
|
sql.updateJSONArray("friends",
|
||||||
sql.updateJSONArray("bound_skills", data.getBoundSkills().stream().map(skill -> skill.getSkill().getId()).collect(Collectors.toList()));
|
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());
|
sql.updateJSONObject("skills", data.mapSkillLevels().entrySet());
|
||||||
|
|
||||||
@ -182,7 +196,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
super(uuid);
|
super(uuid);
|
||||||
|
|
||||||
try {
|
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()) {
|
if (!result.first()) {
|
||||||
level = 0;
|
level = 0;
|
||||||
lastLogin = 0;
|
lastLogin = 0;
|
||||||
@ -194,11 +209,16 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass()
|
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass()
|
||||||
: MMOCore.plugin.classManager.get(result.getString("class"));
|
: MMOCore.plugin.classManager.get(result.getString("class"));
|
||||||
if (!isEmpty(result.getString("friends")))
|
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
|
else
|
||||||
friends = new ArrayList<UUID>();
|
friends = new ArrayList<UUID>();
|
||||||
}
|
}
|
||||||
} catch (SQLException | InterruptedException | ExecutionException e) {
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,7 @@ public class YAMLDataProvider implements DataProvider {
|
|||||||
public GuildDataManager getGuildManager() {
|
public GuildDataManager getGuildManager() {
|
||||||
return guildManager;
|
return guildManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user