mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-28 05:37:44 +01:00
MySQL is now done async!
This commit is contained in:
parent
fff574c0dd
commit
ee7970edaa
183
dependency-reduced-pom.xml
Normal file
183
dependency-reduced-pom.xml
Normal file
@ -0,0 +1,183 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.Indyuce</groupId>
|
||||
<artifactId>MMOCore</artifactId>
|
||||
<name>MMOCore</name>
|
||||
<version>1.4.6</version>
|
||||
<description>Offer your players a brand new RPG experience.</description>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<junitArtifactName>junit:junit</junitArtifactName>
|
||||
<encoding>UTF-8</encoding>
|
||||
<inputEncoding>UTF-8</inputEncoding>
|
||||
<outputEncoding>UTF-8</outputEncoding>
|
||||
<argLine>-ea -Dfile.encoding=UTF-8</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>net.indyuce.mmocore.shaded.paperlib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.jasync.sql.db</pattern>
|
||||
<shadedPattern>eu.asangarin.sqltest</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>19.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.Indyuce</groupId>
|
||||
<artifactId>mmoitems</artifactId>
|
||||
<version>6.1.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/MMOItems.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.Indyuce</groupId>
|
||||
<artifactId>MMOLib</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/MMOLib.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R1-1.16-R2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/spigot.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bekvon.bukkit</groupId>
|
||||
<artifactId>Residence</artifactId>
|
||||
<version>4.8.7.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/Residence.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.Zrips</groupId>
|
||||
<artifactId>CMI</artifactId>
|
||||
<version>8.6.5.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/CMI.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sainttx.holograms</groupId>
|
||||
<artifactId>holograms</artifactId>
|
||||
<version>2.9.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/Holograms.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost</groupId>
|
||||
<artifactId>HolographicDisplays</artifactId>
|
||||
<version>6.9.1</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/HolographicDisplays.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.lumine.xikage</groupId>
|
||||
<artifactId>MythicMobs</artifactId>
|
||||
<version>4.8.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/MythicMobs.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.citizensnpcs</groupId>
|
||||
<artifactId>citizens</artifactId>
|
||||
<version>2.0.25-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/Citizens.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.7</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/PlaceholderAPI.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>Lumine Releases</name>
|
||||
<url>http://mvn.lumine.io/repository/maven-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>nexus</id>
|
||||
<name>Lumine Snapshots</name>
|
||||
<url>http://mvn.lumine.io/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<properties>
|
||||
<downloadSources>false</downloadSources>
|
||||
<downloadJavadocs>false</downloadJavadocs>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<build.number>SNAPSHOT</build.number>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
13
pom.xml
13
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.Indyuce</groupId>
|
||||
<artifactId>MMOCore</artifactId>
|
||||
<version>1.4.6</version>
|
||||
<version>1.4.7</version>
|
||||
<name>MMOCore</name>
|
||||
<description>Offer your players a brand new RPG experience.</description>
|
||||
|
||||
@ -61,6 +61,10 @@
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>net.indyuce.mmocore.shaded.paperlib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.jasync.sql.db</pattern>
|
||||
<shadedPattern>eu.asangarin.sqltest</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
@ -127,10 +131,9 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.41</version>
|
||||
<scope>provided</scope>
|
||||
<groupId>com.github.jasync-sql</groupId>
|
||||
<artifactId>jasync-mysql</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
|
@ -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<MySQLConnection> 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<QueryResult> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.next())
|
||||
if (result.size() < 1)
|
||||
return;
|
||||
|
||||
Gson parser = new Gson();
|
||||
RowData row = result.get(0);
|
||||
|
||||
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.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(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(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(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);
|
||||
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<String, JsonElement> 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 (!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(result.getString("class_info"))) {
|
||||
JsonObject object = parser.fromJson(result.getString("class_info"), JsonObject.class);
|
||||
if (!isEmpty(row.getString("class_info"))) {
|
||||
JsonObject object = MMOLib.plugin.getJson().parse(row.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()));
|
||||
} 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 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<String> getJSONArray(String json) {
|
||||
Collection<String> collection = new ArrayList<String>();
|
||||
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,27 +181,24 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
||||
super(uuid);
|
||||
|
||||
ResultSet result = provider.getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + uuid + "';");
|
||||
try {
|
||||
if (!result.next()) {
|
||||
if (result.size() < 1) {
|
||||
level = 0;
|
||||
lastLogin = 0;
|
||||
profess = MMOCore.plugin.classManager.getDefaultClass();
|
||||
friends = new ArrayList<UUID>();
|
||||
} 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 {
|
||||
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<UUID>();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<String> collection) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user