diff --git a/lib/MMOLib.jar b/lib/MMOLib.jar index ebd23d74..e404e7a8 100644 Binary files a/lib/MMOLib.jar and b/lib/MMOLib.jar differ diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index e74ccc06..d1062557 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -165,8 +165,8 @@ public class MMOCore extends JavaPlugin { new Metrics(this); saveDefaultConfig(); - if (getConfig().contains("mysql") && getConfig().getBoolean("mysql.enabled")) - dataProvider = new MySQLDataProvider(); + if (getConfig().isConfigurationSection("mysql") && getConfig().getBoolean("mysql.enabled")) + dataProvider = new MySQLDataProvider(getConfig()); if(getConfig().isConfigurationSection("default-playerdata")) dataProvider.getDataManager().loadDefaultData(getConfig().getConfigurationSection("default-playerdata")); 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 ce8a7131..6c8f0ef8 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,5 +1,7 @@ package net.Indyuce.mmocore.manager.data.mysql; +import org.bukkit.configuration.file.FileConfiguration; + import net.Indyuce.mmocore.manager.data.DataProvider; import net.Indyuce.mmocore.manager.data.GuildDataManager; import net.Indyuce.mmocore.manager.data.PlayerDataManager; @@ -9,15 +11,20 @@ import net.mmogroup.mmolib.sql.MMODataSource; public class MySQLDataProvider extends MMODataSource implements DataProvider { private final MySQLPlayerDataManager playerManager = new MySQLPlayerDataManager(this); private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager(); - + + public MySQLDataProvider(FileConfiguration config) { + this.setup(config); + } + @Override public void load() { - executeUpdateAsync("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 1,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));"); + executeUpdateAsync( + "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 1," + + "experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG," + + "attributes LONGTEXT,professions LONGTEXT,quests LONGTEXT,waypoints LONGTEXT," + + "friends LONGTEXT,skills LONGTEXT,bound_skills LONGTEXT,class_info LONGTEXT,PRIMARY KEY (uuid));"); } @Override 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 24c9120f..d55985c2 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 @@ -206,7 +206,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { @Override public void removeFriend(UUID uuid) { friends.remove(uuid); - new MySQLTableEditor(Table.PLAYERDATA, uuid).updateData("friends", + new MySQLTableEditor(Table.PLAYERDATA, uuid).updateDataAsync("friends", friends.stream().map(friend -> friend.toString()).collect(Collectors.toList())); } 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 2c8b87f6..49cf99dc 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 @@ -21,6 +21,11 @@ public class MySQLTableEditor { } public void updateData(String key, Object value) { + ((MySQLDataProvider) MMOCore.plugin.dataProvider).executeUpdate("INSERT INTO " + table + "(uuid, " + key + + ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';"); + } + + public void updateDataAsync(String key, Object value) { try { ((MySQLDataProvider) MMOCore.plugin.dataProvider).executeUpdateAsync("INSERT INTO " + table + "(uuid, " + key + ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';").get();