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,7 +363,8 @@ 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();
|
||||||
|
|
||||||
lootChests.getActive().forEach(chest -> chest.unregister(false));
|
lootChests.getActive().forEach(chest -> chest.unregister(false));
|
||||||
|
@ -11,4 +11,5 @@ public interface DataProvider {
|
|||||||
|
|
||||||
PlayerDataManager getDataManager();
|
PlayerDataManager getDataManager();
|
||||||
GuildDataManager getGuildManager();
|
GuildDataManager getGuildManager();
|
||||||
|
void close();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import net.mmogroup.mmolib.sql.MMODataSource;
|
|||||||
public class MySQLDataProvider extends MMODataSource implements DataProvider {
|
public class MySQLDataProvider extends MMODataSource implements DataProvider {
|
||||||
private final MySQLPlayerDataManager playerManager = new MySQLPlayerDataManager(this);
|
private final MySQLPlayerDataManager playerManager = new MySQLPlayerDataManager(this);
|
||||||
private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager();
|
private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager();
|
||||||
|
|
||||||
public MySQLDataProvider(FileConfiguration config) {
|
public MySQLDataProvider(FileConfiguration config) {
|
||||||
this.setup(config);
|
this.setup(config);
|
||||||
}
|
}
|
||||||
|
@ -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,74 +35,87 @@ 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() + "';",
|
||||||
if (!result.first()) {
|
(result) -> {
|
||||||
data.setLevel(getDefaultData().getLevel());
|
try {
|
||||||
data.setClassPoints(getDefaultData().getClassPoints());
|
if (!result.first()) {
|
||||||
data.setSkillPoints(getDefaultData().getSkillPoints());
|
data.setLevel(getDefaultData().getLevel());
|
||||||
data.setAttributePoints(getDefaultData().getAttributePoints());
|
data.setClassPoints(getDefaultData().getClassPoints());
|
||||||
data.setAttributeReallocationPoints(getDefaultData().getAttributeReallocationPoints());
|
data.setSkillPoints(getDefaultData().getSkillPoints());
|
||||||
data.setExperience(0);
|
data.setAttributePoints(getDefaultData().getAttributePoints());
|
||||||
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
data.setAttributeReallocationPoints(getDefaultData().getAttributeReallocationPoints());
|
||||||
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
data.setExperience(0);
|
||||||
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
||||||
data.getQuestData().updateBossBar();
|
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.setClassPoints(result.getInt("class_points"));
|
||||||
data.setSkillPoints(result.getInt("skill_points"));
|
data.setSkillPoints(result.getInt("skill_points"));
|
||||||
data.setAttributePoints(result.getInt("attribute_points"));
|
data.setAttributePoints(result.getInt("attribute_points"));
|
||||||
data.setAttributeReallocationPoints(result.getInt("attribute_realloc_points"));
|
data.setAttributeReallocationPoints(result.getInt("attribute_realloc_points"));
|
||||||
data.setLevel(result.getInt("level"));
|
data.setLevel(result.getInt("level"));
|
||||||
data.setExperience(result.getInt("experience"));
|
data.setExperience(result.getInt("experience"));
|
||||||
if (!isEmpty(result.getString("class")))
|
if (!isEmpty(result.getString("class")))
|
||||||
data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
|
data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
|
||||||
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
||||||
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()
|
||||||
if (!isEmpty(result.getString("attributes")))
|
.stillInGuild(data.getUniqueId(), result.getString("guild")));
|
||||||
data.getAttributes().load(result.getString("attributes"));
|
if (!isEmpty(result.getString("attributes")))
|
||||||
if (!isEmpty(result.getString("professions")))
|
data.getAttributes().load(result.getString("attributes"));
|
||||||
data.getCollectionSkills().load(result.getString("professions"));
|
if (!isEmpty(result.getString("professions")))
|
||||||
if (!isEmpty(result.getString("quests")))
|
data.getCollectionSkills().load(result.getString("professions"));
|
||||||
data.getQuestData().load(result.getString("quests"));
|
if (!isEmpty(result.getString("quests")))
|
||||||
data.getQuestData().updateBossBar();
|
data.getQuestData().load(result.getString("quests"));
|
||||||
if (!isEmpty(result.getString("waypoints")))
|
data.getQuestData().updateBossBar();
|
||||||
data.getWaypoints().addAll(getJSONArray(result.getString("waypoints")));
|
if (!isEmpty(result.getString("waypoints")))
|
||||||
if (!isEmpty(result.getString("friends")))
|
data.getWaypoints().addAll(getJSONArray(result.getString("waypoints")));
|
||||||
getJSONArray(result.getString("friends")).forEach(str -> data.getFriends().add(UUID.fromString(str)));
|
if (!isEmpty(result.getString("friends")))
|
||||||
if (!isEmpty(result.getString("skills"))) {
|
getJSONArray(result.getString("friends"))
|
||||||
JsonObject object = MMOLib.plugin.getJson().parse(result.getString("skills"), JsonObject.class);
|
.forEach(str -> data.getFriends().add(UUID.fromString(str)));
|
||||||
for (Entry<String, JsonElement> entry : object.entrySet())
|
if (!isEmpty(result.getString("skills"))) {
|
||||||
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
|
JsonObject object = MMOLib.plugin.getJson().parse(result.getString("skills"),
|
||||||
}
|
JsonObject.class);
|
||||||
if (!isEmpty(result.getString("bound_skills")))
|
for (Entry<String, JsonElement> entry : object.entrySet())
|
||||||
for (String skill : getJSONArray(result.getString("bound_skills")))
|
data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
|
||||||
if (data.getProfess().hasSkill(skill))
|
}
|
||||||
data.getBoundSkills().add(data.getProfess().getSkill(skill));
|
if (!isEmpty(result.getString("bound_skills")))
|
||||||
if (!isEmpty(result.getString("class_info"))) {
|
for (String skill : getJSONArray(result.getString("bound_skills")))
|
||||||
JsonObject object = MMOLib.plugin.getJson().parse(result.getString("class_info"), JsonObject.class);
|
if (data.getProfess().hasSkill(skill))
|
||||||
for (Entry<String, JsonElement> entry : object.entrySet()) {
|
data.getBoundSkills().add(data.getProfess().getSkill(skill));
|
||||||
try {
|
if (!isEmpty(result.getString("class_info"))) {
|
||||||
PlayerClass profess = MMOCore.plugin.classManager.get(entry.getKey());
|
JsonObject object = MMOLib.plugin.getJson().parse(result.getString("class_info"),
|
||||||
Validate.notNull(profess, "Could not find class '" + entry.getKey() + "'");
|
JsonObject.class);
|
||||||
data.applyClassInfo(profess, new SavedClassInformation(entry.getValue().getAsJsonObject()));
|
for (Entry<String, JsonElement> entry : object.entrySet()) {
|
||||||
} catch (IllegalArgumentException exception) {
|
try {
|
||||||
MMOCore.log(Level.WARNING, "Could not load class info '" + entry.getKey() + "': " + exception.getMessage());
|
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 (SQLException | InterruptedException | ExecutionException e) {
|
} 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();
|
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,23 +196,29 @@ 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) -> {
|
||||||
if (!result.first()) {
|
try {
|
||||||
level = 0;
|
if (!result.first()) {
|
||||||
lastLogin = 0;
|
level = 0;
|
||||||
profess = MMOCore.plugin.classManager.getDefaultClass();
|
lastLogin = 0;
|
||||||
friends = new ArrayList<UUID>();
|
profess = MMOCore.plugin.classManager.getDefaultClass();
|
||||||
} else {
|
friends = new ArrayList<UUID>();
|
||||||
level = result.getInt("level");
|
} else {
|
||||||
lastLogin = result.getLong("last_login");
|
level = result.getInt("level");
|
||||||
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass()
|
lastLogin = result.getLong("last_login");
|
||||||
: MMOCore.plugin.classManager.get(result.getString("class"));
|
profess = isEmpty(result.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass()
|
||||||
if (!isEmpty(result.getString("friends")))
|
: MMOCore.plugin.classManager.get(result.getString("class"));
|
||||||
getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
|
if (!isEmpty(result.getString("friends")))
|
||||||
else
|
getJSONArray(result.getString("friends"))
|
||||||
friends = new ArrayList<UUID>();
|
.forEach(str -> friends.add(UUID.fromString(str)));
|
||||||
}
|
else
|
||||||
} catch (SQLException | InterruptedException | ExecutionException e) {
|
friends = new ArrayList<UUID>();
|
||||||
|
}
|
||||||
|
} 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