!fixed some SQL things

This commit is contained in:
ASangarin 2020-10-06 15:31:59 +02:00
parent 2302743961
commit 54ba6b89b8
5 changed files with 22 additions and 10 deletions

Binary file not shown.

View File

@ -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"));

View File

@ -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

View File

@ -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()));
}

View File

@ -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();