forked from Upstream/mmocore
Cleanup i guess
This commit is contained in:
parent
95ea032dfa
commit
056d1f57ec
@ -24,12 +24,22 @@ public class MySQLDataProvider extends MMODataSource implements DataProvider {
|
|||||||
executeUpdateAsync(
|
executeUpdateAsync(
|
||||||
"CREATE TABLE IF NOT EXISTS mmocore_playerdata(uuid VARCHAR(36),class_points "
|
"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) "
|
+ "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,"
|
+ "DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,skill_reallocation_points INT(11) DEFAULT 0,level INT(11) DEFAULT 1,"
|
||||||
+ "experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,"
|
+ "experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,"
|
||||||
+ "attributes LONGTEXT,professions LONGTEXT,times_claimed LONGTEXT,quests LONGTEXT,"
|
+ "attributes LONGTEXT,professions LONGTEXT,times_claimed LONGTEXT,quests LONGTEXT,"
|
||||||
+ "waypoints LONGTEXT,friends LONGTEXT,skills LONGTEXT,bound_skills LONGTEXT,"
|
+ "waypoints LONGTEXT,friends LONGTEXT,skills LONGTEXT,bound_skills LONGTEXT,"
|
||||||
+ "class_info LONGTEXT, is_saved TINYINT, PRIMARY KEY (uuid));");
|
+ "class_info LONGTEXT, is_saved TINYINT, PRIMARY KEY (uuid));");
|
||||||
|
|
||||||
|
// Add 'skill_reallocation_points' if it doesn't exist
|
||||||
|
getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'mmocore_playerdata' AND COLUMN_NAME = 'skill_reallocation_points'", result -> {
|
||||||
|
try {
|
||||||
|
if (!result.next())
|
||||||
|
executeUpdateAsync("ALTER TABLE mmocore_playerdata ADD COLUMN skill_reallocation_points INT(11) DEFAULT 0");
|
||||||
|
} catch (SQLException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add 'times_claimed' if it doesn't exist
|
// Add 'times_claimed' if it doesn't exist
|
||||||
getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'mmocore_playerdata' AND COLUMN_NAME = 'times_claimed'", result -> {
|
getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'mmocore_playerdata' AND COLUMN_NAME = 'times_claimed'", result -> {
|
||||||
try {
|
try {
|
||||||
|
@ -1,56 +1,55 @@
|
|||||||
package net.Indyuce.mmocore.manager.data.mysql;
|
package net.Indyuce.mmocore.manager.data.mysql;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
public class MySQLTableEditor {
|
public class MySQLTableEditor {
|
||||||
private final Table table;
|
private final Table table;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
private final MySQLDataProvider provider;
|
||||||
|
|
||||||
private final MySQLDataProvider provider;
|
public MySQLTableEditor(Table table, UUID uuid, MySQLDataProvider provider) {
|
||||||
|
this.table = table;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
public MySQLTableEditor(Table table, UUID uuid,MySQLDataProvider provider) {
|
public void updateData(String key, Object value) {
|
||||||
this.table = table;
|
provider.executeUpdate("INSERT INTO " + table + "(uuid, " + key
|
||||||
this.uuid = uuid;
|
+ ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
|
||||||
this.provider=provider;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateData(String key, Object value) {
|
public void updateJSONArray(String key, Collection<String> collection) {
|
||||||
provider.executeUpdate("INSERT INTO " + table + "(uuid, " + key
|
JsonArray json = new JsonArray();
|
||||||
+ ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
|
for (String s : collection)
|
||||||
}
|
json.add(s);
|
||||||
|
updateData(key, json.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void updateJSONArray(String key, Collection<String> collection) {
|
public void updateJSONObject(String key, Set<Entry<String, Integer>> collection) {
|
||||||
JsonArray json = new JsonArray();
|
JsonObject json = new JsonObject();
|
||||||
for (String s : collection)
|
for (Entry<String, Integer> entry : collection)
|
||||||
json.add(s);
|
json.addProperty(entry.getKey(), entry.getValue());
|
||||||
updateData(key, json.toString());
|
updateData(key, json.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateJSONObject(String key, Set<Entry<String, Integer>> collection) {
|
public enum Table {
|
||||||
JsonObject json = new JsonObject();
|
PLAYERDATA("mmocore_playerdata"), GUILDDATA("mmocore_guilddata");
|
||||||
for (Entry<String, Integer> entry : collection)
|
|
||||||
json.addProperty(entry.getKey(), entry.getValue());
|
|
||||||
updateData(key, json.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Table {
|
final String tableName;
|
||||||
PLAYERDATA("mmocore_playerdata"), GUILDDATA("mmocore_guilddata");
|
|
||||||
|
|
||||||
final String tableName;
|
Table(String tN) {
|
||||||
|
tableName = tN;
|
||||||
|
}
|
||||||
|
|
||||||
Table(String tN) {
|
@Override
|
||||||
tableName = tN;
|
public String toString() {
|
||||||
}
|
return tableName;
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public String toString() {
|
|
||||||
return tableName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user