diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
new file mode 100644
index 00000000..df91c0e3
--- /dev/null
+++ b/dependency-reduced-pom.xml
@@ -0,0 +1,183 @@
+
+
+ 4.0.0
+ net.Indyuce
+ MMOCore
+ MMOCore
+ 1.4.6
+ Offer your players a brand new RPG experience.
+
+
+
+ true
+ ${basedir}/src/main/resources/
+
+
+ ${project.name}-${project.version}
+
+
+ maven-compiler-plugin
+
+
+ 1.8
+ junit:junit
+ UTF-8
+ UTF-8
+ UTF-8
+ -ea -Dfile.encoding=UTF-8
+
+
+
+ maven-shade-plugin
+ 3.2.4
+
+
+ package
+
+ shade
+
+
+
+
+
+
+ io.papermc.lib
+ net.indyuce.mmocore.shaded.paperlib
+
+
+ com.github.jasync.sql.db
+ eu.asangarin.sqltest
+
+
+
+
+
+
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+ sk89q-repo
+ https://maven.enginehub.org/repo/
+
+
+ papermc
+ https://papermc.io/repo/repository/maven-public/
+
+
+
+
+ org.jetbrains
+ annotations
+ 19.0.0
+ provided
+
+
+ com.github.MilkBowl
+ VaultAPI
+ 1.7
+ provided
+
+
+ com.sk89q.worldguard
+ worldguard-bukkit
+ 7.0.2-SNAPSHOT
+ provided
+
+
+ net.Indyuce
+ mmoitems
+ 6.1.2
+ system
+ ${basedir}/lib/MMOItems.jar
+
+
+ net.Indyuce
+ MMOLib
+ 1.3
+ system
+ ${basedir}/lib/MMOLib.jar
+
+
+ org.spigotmc
+ spigot-api
+ 1.12-R1-1.16-R2
+ system
+ ${basedir}/lib/spigot.jar
+
+
+ com.bekvon.bukkit
+ Residence
+ 4.8.7.2
+ system
+ ${basedir}/lib/Residence.jar
+
+
+ com.Zrips
+ CMI
+ 8.6.5.0
+ system
+ ${basedir}/lib/CMI.jar
+
+
+ com.sainttx.holograms
+ holograms
+ 2.9.1
+ system
+ ${basedir}/lib/Holograms.jar
+
+
+ com.gmail.filoghost
+ HolographicDisplays
+ 6.9.1
+ system
+ ${basedir}/lib/HolographicDisplays.jar
+
+
+ io.lumine.xikage
+ MythicMobs
+ 4.8.0
+ system
+ ${basedir}/lib/MythicMobs.jar
+
+
+ net.citizensnpcs
+ citizens
+ 2.0.25-SNAPSHOT
+ system
+ ${basedir}/lib/Citizens.jar
+
+
+ me.clip
+ placeholderapi
+ 2.10.7
+ system
+ ${basedir}/lib/PlaceholderAPI.jar
+
+
+
+
+ nexus
+ Lumine Releases
+ http://mvn.lumine.io/repository/maven-releases/
+
+
+ nexus
+ Lumine Snapshots
+ http://mvn.lumine.io/repository/maven-snapshots/
+
+
+
+ false
+ false
+ UTF-8
+ SNAPSHOT
+ UTF-8
+
+
diff --git a/lib/MMOLib.jar b/lib/MMOLib.jar
index 67da4a11..a185ea16 100644
Binary files a/lib/MMOLib.jar and b/lib/MMOLib.jar differ
diff --git a/pom.xml b/pom.xml
index 969ad011..fd0e6e83 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
net.Indyuce
MMOCore
- 1.4.6
+ 1.4.7
MMOCore
Offer your players a brand new RPG experience.
@@ -61,6 +61,10 @@
io.papermc.lib
net.indyuce.mmocore.shaded.paperlib
+
+ com.github.jasync.sql.db
+ eu.asangarin.sqltest
+
@@ -126,12 +130,11 @@
19.0.0
provided
-
- mysql
- mysql-connector-java
- 5.1.41
- provided
-
+
+ com.github.jasync-sql
+ jasync-mysql
+ 1.1.3
+
io.papermc
paperlib
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 62cb63c8..4322f7a3 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
@@ -1,12 +1,16 @@
package net.Indyuce.mmocore.manager.data.mysql;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
import org.bukkit.configuration.ConfigurationSection;
+import com.github.jasync.sql.db.QueryResult;
+import com.github.jasync.sql.db.ResultSet;
+import com.github.jasync.sql.db.mysql.MySQLConnection;
+import com.github.jasync.sql.db.mysql.MySQLConnectionBuilder;
+import com.github.jasync.sql.db.pool.ConnectionPool;
+
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.manager.data.DataProvider;
import net.Indyuce.mmocore.manager.data.GuildDataManager;
@@ -18,51 +22,33 @@ public class MySQLDataProvider implements DataProvider {
private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager();
private final MySQLConfig config;
- private Connection connection;
+ private ConnectionPool connection;
public MySQLDataProvider() {
config = new MySQLConfig(MMOCore.plugin.getConfig().getConfigurationSection("mysql"));
- initialize();
+ connection = MySQLConnectionBuilder.createConnectionPool(config.getConnectionString());
executeUpdate("CREATE TABLE IF NOT EXISTS mmocore_playerdata (uuid VARCHAR(36),class_points INT(11) DEFAULT 0,skill_points INT(11) DEFAULT 0,attribute_points INT(11) DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,level INT(11) DEFAULT 0,experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,attributes JSON,professions JSON,quests JSON,waypoints JSON,friends JSON,skills JSON,bound_skills JSON,class_info JSON,PRIMARY KEY (uuid));");
}
- private void initialize() {
- try {
- connection = DriverManager.getConnection(config.getConnectionString(), config.getUser(), config.getPassword());
- } catch (SQLException exception) {
- throw new IllegalArgumentException("Could not initialize MySQL support: " + exception.getMessage());
- }
- }
-
public ResultSet getResult(String sql) {
try {
- return getConnection().prepareStatement(sql).executeQuery();
- } catch (SQLException exception) {
- exception.printStackTrace();
+ CompletableFuture future = connection.sendPreparedStatement(sql);
+ return future.get().getRows();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
return null;
}
}
public void executeUpdate(String sql) {
try {
- getConnection().prepareStatement(sql).executeUpdate();
- } catch (SQLException exception) {
- exception.printStackTrace();
+ connection.sendPreparedStatement(sql).get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
}
}
- private Connection getConnection() {
- try {
- if(connection.isClosed())
- initialize();
- } catch (SQLException e) {
- initialize();
- }
-
- return connection;
- }
-
@Override
public PlayerDataManager getDataManager() {
return playerManager;
@@ -74,28 +60,22 @@ public class MySQLDataProvider implements DataProvider {
}
public class MySQLConfig {
- private final String database, hostname, userid, password, flags;
+ private final String db, host, user, pass;
private final int port;
public MySQLConfig(ConfigurationSection config) {
- database = config.getString("database", "minecraft");
- hostname = config.getString("host", "localhost");
+ db = config.getString("database", "minecraft");
+ host = config.getString("host", "localhost");
port = config.getInt("port", 3306);
- userid = config.getString("user", "mmolover");
- password = config.getString("pass", "ILoveAria");
- flags = config.getString("flags", "?allowReconnect=true&useSSL=false");
+ user = config.getString("user", "mmolover");
+ pass = config.getString("pass", "ILoveAria");
}
public String getConnectionString() {
- return "jdbc:mysql://" + hostname + ":" + port + "/" + database + flags;
- }
-
- public String getUser() {
- return userid;
- }
-
- public String getPassword() {
- return password;
+ StringBuilder sb = new StringBuilder("jdbc:mysql://");
+ sb.append(host).append(":").append(port).append("/").append(db)
+ .append("?user=").append(user).append("&password=").append(pass);
+ return sb.toString();
}
}
}
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 f126bdfd..5c0bf666 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,7 +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;
import java.util.List;
@@ -12,7 +10,8 @@ import java.util.stream.Collectors;
import org.apache.commons.lang.Validate;
-import com.google.gson.Gson;
+import com.github.jasync.sql.db.ResultSet;
+import com.github.jasync.sql.db.RowData;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -24,6 +23,7 @@ import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
import net.Indyuce.mmocore.manager.data.mysql.MySQLTableEditor.Table;
+import net.mmogroup.mmolib.MMOLib;
public class MySQLPlayerDataManager extends PlayerDataManager {
private final MySQLDataProvider provider;
@@ -34,74 +34,73 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
@Override
public void loadData(PlayerData data) {
- ResultSet result = provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';");
+ ResultSet result = provider
+ .getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';");
if (result == null) {
- MMOCore.log(Level.SEVERE, "Failed to load playerdata of '" + data.getPlayer().getName() + "' from MySQL server");
+ MMOCore.log(Level.SEVERE,
+ "Failed to load playerdata of '" + data.getPlayer().getName() + "' from MySQL server");
return;
}
- try {
+ // player data not initialized yet
+ if (result.size() < 1)
+ return;
- // player data not initialized yet
- if (!result.next())
- return;
+ RowData row = result.get(0);
- Gson parser = new Gson();
-
- 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"));
- String quests = result.getString("quests");
- if (!isEmpty(quests))
- data.getQuestData().load(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 = parser.fromJson(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 = parser.fromJson(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());
- }
+ data.setClassPoints(row.getInt("class_points"));
+ data.setSkillPoints(row.getInt("skill_points"));
+ data.setAttributePoints(row.getInt("attribute_points"));
+ data.setAttributeReallocationPoints(row.getInt("attribute_realloc_points"));
+ data.setLevel(row.getInt("level"));
+ data.setExperience(row.getInt("experience"));
+ if (!isEmpty(row.getString("class")))
+ data.setClass(MMOCore.plugin.classManager.get(row.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(row.getString("guild")))
+ data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(),
+ row.getString("guild")));
+ if (!isEmpty(row.getString("attributes")))
+ data.getAttributes().load(row.getString("attributes"));
+ if (!isEmpty(row.getString("professions")))
+ data.getCollectionSkills().load(row.getString("professions"));
+ String quests = row.getString("quests");
+ if (!isEmpty(quests))
+ data.getQuestData().load(quests);
+ data.getQuestData().updateBossBar();
+ if (!isEmpty(row.getString("waypoints")))
+ data.getWaypoints().addAll(getJSONArray(row.getString("waypoints")));
+ if (!isEmpty(row.getString("friends")))
+ getJSONArray(row.getString("friends")).forEach(str -> data.getFriends().add(UUID.fromString(str)));
+ if (!isEmpty(row.getString("skills"))) {
+ JsonObject object = MMOLib.plugin.getJson().parse(row.getString("skills"), JsonObject.class);
+ for (Entry entry : object.entrySet())
+ data.setSkillLevel(entry.getKey(), entry.getValue().getAsInt());
+ }
+ if (!isEmpty(row.getString("bound_skills")))
+ for (String skill : getJSONArray(row.getString("bound_skills")))
+ if (data.getProfess().hasSkill(skill))
+ data.getBoundSkills().add(data.getProfess().getSkill(skill));
+ if (!isEmpty(row.getString("class_info"))) {
+ JsonObject object = MMOLib.plugin.getJson().parse(row.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) {
- MMOCore.log(Level.SEVERE, "Failed to load playerdata from MySQL!");
- e.printStackTrace();
}
}
private boolean isEmpty(String s) {
- return s.equalsIgnoreCase("null") || s.equalsIgnoreCase("{}") || s.equalsIgnoreCase("[]") || s.equalsIgnoreCase("");
+ return s.equalsIgnoreCase("null") || s.equalsIgnoreCase("{}") || s.equalsIgnoreCase("[]")
+ || s.equalsIgnoreCase("");
}
@Override
@@ -119,8 +118,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());
@@ -163,9 +164,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
private Collection getJSONArray(String json) {
Collection collection = new ArrayList();
- Gson parser = new Gson();
- for (String s : parser.fromJson(json, String[].class))
+ for (String s : MMOLib.plugin.getJson().parse(json, String[].class))
collection.add(s);
return collection;
@@ -181,26 +181,23 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
super(uuid);
ResultSet result = provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';");
- try {
- if (!result.next()) {
- level = 0;
- lastLogin = 0;
- profess = MMOCore.plugin.classManager.getDefaultClass();
+ if (result.size() < 1) {
+ level = 0;
+ lastLogin = 0;
+ profess = MMOCore.plugin.classManager.getDefaultClass();
+ friends = new ArrayList();
+ } else {
+ RowData row = result.get(0);
+
+ level = row.getInt("level");
+ lastLogin = row.getLong("last_login");
+ profess = row.getString("class").equalsIgnoreCase("null")
+ ? MMOCore.plugin.classManager.getDefaultClass()
+ : MMOCore.plugin.classManager.get(row.getString("class"));
+ if (!row.getString("friends").equalsIgnoreCase("null"))
+ getJSONArray(row.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
+ else
friends = new ArrayList();
- } else
- while (result.next()) {
- level = result.getInt("level");
- lastLogin = result.getLong("last_login");
- profess = result.getString("class").equalsIgnoreCase("null") ? MMOCore.plugin.classManager.getDefaultClass()
- : MMOCore.plugin.classManager.get(result.getString("class"));
- if (!result.getString("friends").equalsIgnoreCase("null"))
- getJSONArray(result.getString("friends")).forEach(str -> friends.add(UUID.fromString(str)));
- else
- friends = new ArrayList();
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
}
diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLTableEditor.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLTableEditor.java
index 509c290b..8bfab75b 100644
--- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLTableEditor.java
+++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLTableEditor.java
@@ -14,15 +14,13 @@ public class MySQLTableEditor {
private final Table table;
private final UUID uuid;
- private static final MySQLDataProvider dataProvider = (MySQLDataProvider) MMOCore.plugin.dataProvider;
-
public MySQLTableEditor(Table table, UUID uuid) {
this.table = table;
this.uuid = uuid;
}
public void updateData(String key, Object value) {
- dataProvider.executeUpdate("INSERT INTO " + table + "(uuid, " + key + ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
+ ((MySQLDataProvider) MMOCore.plugin.dataProvider).executeUpdate("INSERT INTO " + table + "(uuid, " + key + ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
}
public void updateJSONArray(String key, Collection collection) {
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 6790f7d7..bba5044d 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -13,7 +13,6 @@ mysql:
port: 3306
user: mmolover
pass: ILoveAria
- flags: '?allowReconnect=true&useSSL=false'
# The list of all conditions which must be met for the
# BLOCK REGEN and BLOCK RESTRICTIONS to apply. Set to