|
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
|
|
import java.sql.*;
|
|
import java.sql.*;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
+import java.util.logging.Logger;
|
|
|
|
|
|
public final class SQLDatabaseManager implements DatabaseManager {
|
|
public final class SQLDatabaseManager implements DatabaseManager {
|
|
private static final String ALL_QUERY_VERSION = "total";
|
|
private static final String ALL_QUERY_VERSION = "total";
|
|
@@ -32,6 +33,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
public static final String USER_VARCHAR = "VARCHAR(40)";
|
|
public static final String USER_VARCHAR = "VARCHAR(40)";
|
|
public static final int CHILD_SKILLS_SIZE = 2;
|
|
public static final int CHILD_SKILLS_SIZE = 2;
|
|
public static final String LEGACY_DRIVER_PATH = "com.mysql.jdbc.Driver";
|
|
public static final String LEGACY_DRIVER_PATH = "com.mysql.jdbc.Driver";
|
|
|
|
+ public static final int MAGIC_NUMBER = 44;
|
|
private final String tablePrefix = mcMMO.p.getGeneralConfig().getMySQLTablePrefix();
|
|
private final String tablePrefix = mcMMO.p.getGeneralConfig().getMySQLTablePrefix();
|
|
|
|
|
|
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
|
|
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
|
|
@@ -45,23 +47,19 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
private final ReentrantLock massUpdateLock = new ReentrantLock();
|
|
private final ReentrantLock massUpdateLock = new ReentrantLock();
|
|
|
|
|
|
private final String CHARSET_SQL = "utf8mb4"; //This is compliant with UTF-8 while "utf8" is not, confusing but this is how it is.
|
|
private final String CHARSET_SQL = "utf8mb4"; //This is compliant with UTF-8 while "utf8" is not, confusing but this is how it is.
|
|
- private String driverPath = "com.mysql.cj.jdbc.Driver"; //modern driver
|
|
|
|
|
|
+ private final Logger logger;
|
|
|
|
+ private final boolean h2;
|
|
|
|
|
|
- protected SQLDatabaseManager() {
|
|
|
|
- String connectionString = "jdbc:mysql://" + mcMMO.p.getGeneralConfig().getMySQLServerName()
|
|
|
|
- + ":" + mcMMO.p.getGeneralConfig().getMySQLServerPort() + "/" + mcMMO.p.getGeneralConfig().getMySQLDatabaseName();
|
|
|
|
|
|
+ SQLDatabaseManager(Logger logger, String driverPath) {
|
|
|
|
+ this(logger, driverPath, false);
|
|
|
|
+ }
|
|
|
|
|
|
- if(!mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 17, 0) //Temporary hack for SQL and 1.17 support
|
|
|
|
- && mcMMO.p.getGeneralConfig().getMySQLSSL())
|
|
|
|
- connectionString +=
|
|
|
|
- "?verifyServerCertificate=false"+
|
|
|
|
- "&useSSL=true"+
|
|
|
|
- "&requireSSL=true";
|
|
|
|
- else
|
|
|
|
- connectionString+=
|
|
|
|
- "?useSSL=false";
|
|
|
|
|
|
+ SQLDatabaseManager(Logger logger, String driverPath, boolean h2) {
|
|
|
|
+ this.logger = logger;
|
|
|
|
+ this.h2 = h2;
|
|
|
|
+ String connectionString = getConnectionString(h2);
|
|
|
|
|
|
- if(mcMMO.p.getGeneralConfig().getMySQLPublicKeyRetrieval()) {
|
|
|
|
|
|
+ if(!h2 && mcMMO.p.getGeneralConfig().getMySQLPublicKeyRetrieval()) {
|
|
connectionString+=
|
|
connectionString+=
|
|
"&allowPublicKeyRetrieval=true";
|
|
"&allowPublicKeyRetrieval=true";
|
|
}
|
|
}
|
|
@@ -76,7 +74,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
} catch (ClassNotFoundException ex) {
|
|
} catch (ClassNotFoundException ex) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
ex.printStackTrace();
|
|
ex.printStackTrace();
|
|
- mcMMO.p.getLogger().severe("Neither driver found");
|
|
|
|
|
|
+ logger.severe("Neither driver found");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//throw e; // aborts onEnable() Riking if you want to do this, fully implement it.
|
|
//throw e; // aborts onEnable() Riking if you want to do this, fully implement it.
|
|
@@ -133,9 +131,31 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
checkStructure();
|
|
checkStructure();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @NotNull
|
|
|
|
+ private static String getConnectionString(boolean h2) {
|
|
|
|
+ if (h2) {
|
|
|
|
+ return "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MySQL";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String connectionString = "jdbc:mysql://" + mcMMO.p.getGeneralConfig().getMySQLServerName()
|
|
|
|
+ + ":" + mcMMO.p.getGeneralConfig().getMySQLServerPort() + "/" + mcMMO.p.getGeneralConfig().getMySQLDatabaseName();
|
|
|
|
+
|
|
|
|
+ if(!mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 17, 0) //Temporary hack for SQL and 1.17 support
|
|
|
|
+ && mcMMO.p.getGeneralConfig().getMySQLSSL())
|
|
|
|
+ connectionString +=
|
|
|
|
+ "?verifyServerCertificate=false"+
|
|
|
|
+ "&useSSL=true"+
|
|
|
|
+ "&requireSSL=true";
|
|
|
|
+ else
|
|
|
|
+ connectionString+=
|
|
|
|
+ "?useSSL=false";
|
|
|
|
+ return connectionString;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO: unit tests
|
|
public int purgePowerlessUsers() {
|
|
public int purgePowerlessUsers() {
|
|
massUpdateLock.lock();
|
|
massUpdateLock.lock();
|
|
- mcMMO.p.getLogger().info("Purging powerless users...");
|
|
|
|
|
|
+ logger.info("Purging powerless users...");
|
|
|
|
|
|
Connection connection = null;
|
|
Connection connection = null;
|
|
Statement statement = null;
|
|
Statement statement = null;
|
|
@@ -149,7 +169,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
+ "taming = 0 AND mining = 0 AND woodcutting = 0 AND repair = 0 "
|
|
+ "taming = 0 AND mining = 0 AND woodcutting = 0 AND repair = 0 "
|
|
+ "AND unarmed = 0 AND herbalism = 0 AND excavation = 0 AND "
|
|
+ "AND unarmed = 0 AND herbalism = 0 AND excavation = 0 AND "
|
|
+ "archery = 0 AND swords = 0 AND axes = 0 AND acrobatics = 0 "
|
|
+ "archery = 0 AND swords = 0 AND axes = 0 AND acrobatics = 0 "
|
|
- + "AND fishing = 0 AND alchemy = 0;");
|
|
|
|
|
|
+ + "AND fishing = 0 AND alchemy = 0 AND crossbows = 0 AND tridents = 0;");
|
|
|
|
|
|
statement.executeUpdate("DELETE FROM `" + tablePrefix + "experience` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "skills` `s` WHERE `" + tablePrefix + "experience`.`user_id` = `s`.`user_id`)");
|
|
statement.executeUpdate("DELETE FROM `" + tablePrefix + "experience` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "skills` `s` WHERE `" + tablePrefix + "experience`.`user_id` = `s`.`user_id`)");
|
|
statement.executeUpdate("DELETE FROM `" + tablePrefix + "huds` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "skills` `s` WHERE `" + tablePrefix + "huds`.`user_id` = `s`.`user_id`)");
|
|
statement.executeUpdate("DELETE FROM `" + tablePrefix + "huds` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "skills` `s` WHERE `" + tablePrefix + "huds`.`user_id` = `s`.`user_id`)");
|
|
@@ -165,13 +185,13 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
massUpdateLock.unlock();
|
|
massUpdateLock.unlock();
|
|
}
|
|
}
|
|
|
|
|
|
- mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
|
|
|
|
|
+ logger.info("Purged " + purged + " users from the database.");
|
|
return purged;
|
|
return purged;
|
|
}
|
|
}
|
|
|
|
|
|
public void purgeOldUsers() {
|
|
public void purgeOldUsers() {
|
|
massUpdateLock.lock();
|
|
massUpdateLock.lock();
|
|
- mcMMO.p.getLogger().info("Purging inactive users older than " + (mcMMO.p.getPurgeTime() / 2630000000L) + " months...");
|
|
|
|
|
|
+ logger.info("Purging inactive users older than " + (mcMMO.p.getPurgeTime() / 2630000000L) + " months...");
|
|
|
|
|
|
Connection connection = null;
|
|
Connection connection = null;
|
|
Statement statement = null;
|
|
Statement statement = null;
|
|
@@ -196,7 +216,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
massUpdateLock.unlock();
|
|
massUpdateLock.unlock();
|
|
}
|
|
}
|
|
|
|
|
|
- mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
|
|
|
|
|
+ logger.info("Purged " + purged + " users from the database.");
|
|
}
|
|
}
|
|
|
|
|
|
public boolean removeUser(String playerName, UUID uuid) {
|
|
public boolean removeUser(String playerName, UUID uuid) {
|
|
@@ -212,7 +232,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
|
|
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
|
|
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
|
|
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
|
|
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
|
|
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
|
|
- "WHERE u.user = ?");
|
|
|
|
|
|
+ "WHERE u.`user` = ?");
|
|
|
|
|
|
statement.setString(1, playerName);
|
|
statement.setString(1, playerName);
|
|
|
|
|
|
@@ -253,7 +273,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
if (id == -1) {
|
|
if (id == -1) {
|
|
id = newUser(connection, profile.getPlayerName(), profile.getUniqueId());
|
|
id = newUser(connection, profile.getPlayerName(), profile.getUniqueId());
|
|
if (id == -1) {
|
|
if (id == -1) {
|
|
- mcMMO.p.getLogger().severe("Failed to create new account for " + profile.getPlayerName());
|
|
|
|
|
|
+ logger.severe("Failed to create new account for " + profile.getPlayerName());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -263,7 +283,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
success &= (statement.executeUpdate() != 0);
|
|
success &= (statement.executeUpdate() != 0);
|
|
statement.close();
|
|
statement.close();
|
|
if (!success) {
|
|
if (!success) {
|
|
- mcMMO.p.getLogger().severe("Failed to update last login for " + profile.getPlayerName());
|
|
|
|
|
|
+ logger.severe("Failed to update last login for " + profile.getPlayerName());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -271,7 +291,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
|
|
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
|
|
+ ", unarmed = ?, herbalism = ?, excavation = ?"
|
|
+ ", unarmed = ?, herbalism = ?, excavation = ?"
|
|
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
|
|
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
|
|
- + ", fishing = ?, alchemy = ?, total = ? WHERE user_id = ?");
|
|
|
|
|
|
+ + ", fishing = ?, alchemy = ?, crossbows = ?, tridents = ?, total = ? WHERE user_id = ?");
|
|
statement.setInt(1, profile.getSkillLevel(PrimarySkillType.TAMING));
|
|
statement.setInt(1, profile.getSkillLevel(PrimarySkillType.TAMING));
|
|
statement.setInt(2, profile.getSkillLevel(PrimarySkillType.MINING));
|
|
statement.setInt(2, profile.getSkillLevel(PrimarySkillType.MINING));
|
|
statement.setInt(3, profile.getSkillLevel(PrimarySkillType.REPAIR));
|
|
statement.setInt(3, profile.getSkillLevel(PrimarySkillType.REPAIR));
|
|
@@ -285,15 +305,17 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
statement.setInt(11, profile.getSkillLevel(PrimarySkillType.ACROBATICS));
|
|
statement.setInt(11, profile.getSkillLevel(PrimarySkillType.ACROBATICS));
|
|
statement.setInt(12, profile.getSkillLevel(PrimarySkillType.FISHING));
|
|
statement.setInt(12, profile.getSkillLevel(PrimarySkillType.FISHING));
|
|
statement.setInt(13, profile.getSkillLevel(PrimarySkillType.ALCHEMY));
|
|
statement.setInt(13, profile.getSkillLevel(PrimarySkillType.ALCHEMY));
|
|
|
|
+ statement.setInt(14, profile.getSkillLevel(PrimarySkillType.CROSSBOWS));
|
|
|
|
+ statement.setInt(15, profile.getSkillLevel(PrimarySkillType.TRIDENTS));
|
|
int total = 0;
|
|
int total = 0;
|
|
for (PrimarySkillType primarySkillType : SkillTools.NON_CHILD_SKILLS)
|
|
for (PrimarySkillType primarySkillType : SkillTools.NON_CHILD_SKILLS)
|
|
total += profile.getSkillLevel(primarySkillType);
|
|
total += profile.getSkillLevel(primarySkillType);
|
|
- statement.setInt(14, total);
|
|
|
|
- statement.setInt(15, id);
|
|
|
|
|
|
+ statement.setInt(16, total);
|
|
|
|
+ statement.setInt(17, id);
|
|
success &= (statement.executeUpdate() != 0);
|
|
success &= (statement.executeUpdate() != 0);
|
|
statement.close();
|
|
statement.close();
|
|
if (!success) {
|
|
if (!success) {
|
|
- mcMMO.p.getLogger().severe("Failed to update skills for " + profile.getPlayerName());
|
|
|
|
|
|
+ logger.severe("Failed to update skills for " + profile.getPlayerName());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -301,7 +323,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
|
|
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
|
|
+ ", unarmed = ?, herbalism = ?, excavation = ?"
|
|
+ ", unarmed = ?, herbalism = ?, excavation = ?"
|
|
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
|
|
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
|
|
- + ", fishing = ?, alchemy = ? WHERE user_id = ?");
|
|
|
|
|
|
+ + ", fishing = ?, alchemy = ?, crossbows = ?, tridents = ? WHERE user_id = ?");
|
|
statement.setInt(1, profile.getSkillXpLevel(PrimarySkillType.TAMING));
|
|
statement.setInt(1, profile.getSkillXpLevel(PrimarySkillType.TAMING));
|
|
statement.setInt(2, profile.getSkillXpLevel(PrimarySkillType.MINING));
|
|
statement.setInt(2, profile.getSkillXpLevel(PrimarySkillType.MINING));
|
|
statement.setInt(3, profile.getSkillXpLevel(PrimarySkillType.REPAIR));
|
|
statement.setInt(3, profile.getSkillXpLevel(PrimarySkillType.REPAIR));
|
|
@@ -315,18 +337,20 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
statement.setInt(11, profile.getSkillXpLevel(PrimarySkillType.ACROBATICS));
|
|
statement.setInt(11, profile.getSkillXpLevel(PrimarySkillType.ACROBATICS));
|
|
statement.setInt(12, profile.getSkillXpLevel(PrimarySkillType.FISHING));
|
|
statement.setInt(12, profile.getSkillXpLevel(PrimarySkillType.FISHING));
|
|
statement.setInt(13, profile.getSkillXpLevel(PrimarySkillType.ALCHEMY));
|
|
statement.setInt(13, profile.getSkillXpLevel(PrimarySkillType.ALCHEMY));
|
|
- statement.setInt(14, id);
|
|
|
|
|
|
+ statement.setInt(14, profile.getSkillXpLevel(PrimarySkillType.CROSSBOWS));
|
|
|
|
+ statement.setInt(15, profile.getSkillXpLevel(PrimarySkillType.TRIDENTS));
|
|
|
|
+ statement.setInt(16, id);
|
|
success &= (statement.executeUpdate() != 0);
|
|
success &= (statement.executeUpdate() != 0);
|
|
statement.close();
|
|
statement.close();
|
|
if (!success) {
|
|
if (!success) {
|
|
- mcMMO.p.getLogger().severe("Failed to update experience for " + profile.getPlayerName());
|
|
|
|
|
|
+ logger.severe("Failed to update experience for " + profile.getPlayerName());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
statement = connection.prepareStatement("UPDATE " + tablePrefix + "cooldowns SET "
|
|
statement = connection.prepareStatement("UPDATE " + tablePrefix + "cooldowns SET "
|
|
+ " mining = ?, woodcutting = ?, unarmed = ?"
|
|
+ " mining = ?, woodcutting = ?, unarmed = ?"
|
|
+ ", herbalism = ?, excavation = ?, swords = ?"
|
|
+ ", herbalism = ?, excavation = ?, swords = ?"
|
|
- + ", axes = ?, blast_mining = ?, chimaera_wing = ? WHERE user_id = ?");
|
|
|
|
|
|
+ + ", axes = ?, blast_mining = ?, chimaera_wing = ?, crossbows = ?, tridents = ? WHERE user_id = ?");
|
|
statement.setLong(1, profile.getAbilityDATS(SuperAbilityType.SUPER_BREAKER));
|
|
statement.setLong(1, profile.getAbilityDATS(SuperAbilityType.SUPER_BREAKER));
|
|
statement.setLong(2, profile.getAbilityDATS(SuperAbilityType.TREE_FELLER));
|
|
statement.setLong(2, profile.getAbilityDATS(SuperAbilityType.TREE_FELLER));
|
|
statement.setLong(3, profile.getAbilityDATS(SuperAbilityType.BERSERK));
|
|
statement.setLong(3, profile.getAbilityDATS(SuperAbilityType.BERSERK));
|
|
@@ -336,11 +360,13 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
statement.setLong(7, profile.getAbilityDATS(SuperAbilityType.SKULL_SPLITTER));
|
|
statement.setLong(7, profile.getAbilityDATS(SuperAbilityType.SKULL_SPLITTER));
|
|
statement.setLong(8, profile.getAbilityDATS(SuperAbilityType.BLAST_MINING));
|
|
statement.setLong(8, profile.getAbilityDATS(SuperAbilityType.BLAST_MINING));
|
|
statement.setLong(9, profile.getUniqueData(UniqueDataType.CHIMAERA_WING_DATS));
|
|
statement.setLong(9, profile.getUniqueData(UniqueDataType.CHIMAERA_WING_DATS));
|
|
- statement.setInt(10, id);
|
|
|
|
|
|
+ statement.setLong(10, profile.getAbilityDATS(SuperAbilityType.SUPER_SHOTGUN));
|
|
|
|
+ statement.setLong(11, profile.getAbilityDATS(SuperAbilityType.TRIDENTS_SUPER_ABILITY));
|
|
|
|
+ statement.setInt(12, id);
|
|
success = (statement.executeUpdate() != 0);
|
|
success = (statement.executeUpdate() != 0);
|
|
statement.close();
|
|
statement.close();
|
|
if (!success) {
|
|
if (!success) {
|
|
- mcMMO.p.getLogger().severe("Failed to update cooldowns for " + profile.getPlayerName());
|
|
|
|
|
|
+ logger.severe("Failed to update cooldowns for " + profile.getPlayerName());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -351,7 +377,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
success = (statement.executeUpdate() != 0);
|
|
success = (statement.executeUpdate() != 0);
|
|
statement.close();
|
|
statement.close();
|
|
if (!success) {
|
|
if (!success) {
|
|
- mcMMO.p.getLogger().severe("Failed to update hud settings for " + profile.getPlayerName());
|
|
|
|
|
|
+ logger.severe("Failed to update hud settings for " + profile.getPlayerName());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -371,11 +397,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
|
|
|
|
//Fix for a plugin that people are using that is throwing SQL errors
|
|
//Fix for a plugin that people are using that is throwing SQL errors
|
|
if(skill != null && SkillTools.isChildSkill(skill)) {
|
|
if(skill != null && SkillTools.isChildSkill(skill)) {
|
|
- mcMMO.p.getLogger().severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
|
|
|
|
|
|
+ logger.severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
|
|
throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!");
|
|
throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!");
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
String query = skill == null ? ALL_QUERY_VERSION : skill.name().toLowerCase(Locale.ENGLISH);
|
|
String query = skill == null ? ALL_QUERY_VERSION : skill.name().toLowerCase(Locale.ENGLISH);
|
|
ResultSet resultSet = null;
|
|
ResultSet resultSet = null;
|
|
PreparedStatement statement = null;
|
|
PreparedStatement statement = null;
|
|
@@ -383,7 +408,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
|
|
|
|
try {
|
|
try {
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
- statement = connection.prepareStatement("SELECT " + query + ", user FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 AND NOT user = '\\_INVALID\\_OLD\\_USERNAME\\_' ORDER BY " + query + " DESC, user LIMIT ?, ?");
|
|
|
|
|
|
+ statement = connection.prepareStatement("SELECT " + query + ", `user` FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 AND NOT `user` = '\\_INVALID\\_OLD\\_USERNAME\\_' ORDER BY " + query + " DESC, `user` LIMIT ?, ?");
|
|
statement.setInt(1, (pageNumber * statsPerPage) - statsPerPage);
|
|
statement.setInt(1, (pageNumber * statsPerPage) - statsPerPage);
|
|
statement.setInt(2, statsPerPage);
|
|
statement.setInt(2, statsPerPage);
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
@@ -424,7 +449,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
// Get count of all users with higher skill level than player
|
|
// Get count of all users with higher skill level than player
|
|
String sql = "SELECT COUNT(*) AS 'rank' FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " +
|
|
String sql = "SELECT COUNT(*) AS 'rank' FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " +
|
|
"AND " + skillName + " > (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
|
|
"AND " + skillName + " > (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
|
|
- "WHERE user = ?)";
|
|
|
|
|
|
+ "WHERE `user` = ?)";
|
|
|
|
|
|
statement = connection.prepareStatement(sql);
|
|
statement = connection.prepareStatement(sql);
|
|
statement.setString(1, playerName);
|
|
statement.setString(1, playerName);
|
|
@@ -437,7 +462,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
// Ties are settled by alphabetical order
|
|
// Ties are settled by alphabetical order
|
|
sql = "SELECT user, " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " +
|
|
sql = "SELECT user, " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE " + skillName + " > 0 " +
|
|
"AND " + skillName + " = (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
|
|
"AND " + skillName + " = (SELECT " + skillName + " FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id " +
|
|
- "WHERE user = '" + playerName + "') ORDER BY user";
|
|
|
|
|
|
+ "WHERE `user` = '" + playerName + "') ORDER BY user";
|
|
|
|
|
|
resultSet.close();
|
|
resultSet.close();
|
|
statement.close();
|
|
statement.close();
|
|
@@ -460,7 +485,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
"WHERE " + ALL_QUERY_VERSION + " > 0 " +
|
|
"WHERE " + ALL_QUERY_VERSION + " > 0 " +
|
|
"AND " + ALL_QUERY_VERSION + " > " +
|
|
"AND " + ALL_QUERY_VERSION + " > " +
|
|
"(SELECT " + ALL_QUERY_VERSION + " " +
|
|
"(SELECT " + ALL_QUERY_VERSION + " " +
|
|
- "FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = ?)";
|
|
|
|
|
|
+ "FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE `user` = ?)";
|
|
|
|
|
|
statement = connection.prepareStatement(sql);
|
|
statement = connection.prepareStatement(sql);
|
|
statement.setString(1, playerName);
|
|
statement.setString(1, playerName);
|
|
@@ -478,7 +503,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
"WHERE " + ALL_QUERY_VERSION + " > 0 " +
|
|
"WHERE " + ALL_QUERY_VERSION + " > 0 " +
|
|
"AND " + ALL_QUERY_VERSION + " = " +
|
|
"AND " + ALL_QUERY_VERSION + " = " +
|
|
"(SELECT " + ALL_QUERY_VERSION + " " +
|
|
"(SELECT " + ALL_QUERY_VERSION + " " +
|
|
- "FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE user = ?) ORDER BY user";
|
|
|
|
|
|
+ "FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON user_id = id WHERE `user` = ?) ORDER BY user";
|
|
|
|
|
|
statement = connection.prepareStatement(sql);
|
|
statement = connection.prepareStatement(sql);
|
|
statement.setString(1, playerName);
|
|
statement.setString(1, playerName);
|
|
@@ -546,21 +571,26 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
try {
|
|
try {
|
|
statement = connection.prepareStatement(
|
|
statement = connection.prepareStatement(
|
|
"UPDATE `" + tablePrefix + "users` "
|
|
"UPDATE `" + tablePrefix + "users` "
|
|
- + "SET user = ? "
|
|
|
|
- + "WHERE user = ?");
|
|
|
|
|
|
+ + "SET `user` = ? "
|
|
|
|
+ + "WHERE `user` = ?");
|
|
statement.setString(1, "_INVALID_OLD_USERNAME_");
|
|
statement.setString(1, "_INVALID_OLD_USERNAME_");
|
|
statement.setString(2, playerName);
|
|
statement.setString(2, playerName);
|
|
statement.executeUpdate();
|
|
statement.executeUpdate();
|
|
statement.close();
|
|
statement.close();
|
|
- statement = connection.prepareStatement("INSERT INTO " + tablePrefix + "users (user, uuid, lastlogin) VALUES (?, ?, UNIX_TIMESTAMP())", Statement.RETURN_GENERATED_KEYS);
|
|
|
|
|
|
+
|
|
|
|
+ long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
+
|
|
|
|
+ String sql = "INSERT INTO " + tablePrefix + "users (`user`, uuid, lastlogin) VALUES (?, ?, ?)";
|
|
|
|
+ statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
|
statement.setString(1, playerName);
|
|
statement.setString(1, playerName);
|
|
statement.setString(2, uuid != null ? uuid.toString() : null);
|
|
statement.setString(2, uuid != null ? uuid.toString() : null);
|
|
|
|
+ statement.setLong(3, currentTimeMillis);
|
|
statement.executeUpdate();
|
|
statement.executeUpdate();
|
|
|
|
|
|
resultSet = statement.getGeneratedKeys();
|
|
resultSet = statement.getGeneratedKeys();
|
|
|
|
|
|
if (!resultSet.next()) {
|
|
if (!resultSet.next()) {
|
|
- mcMMO.p.getLogger().severe("Unable to create new user account in DB");
|
|
|
|
|
|
+ logger.severe("Unable to create new user account in DB");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -600,7 +630,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
return loadPlayerFromDB(uuid, null);
|
|
return loadPlayerFromDB(uuid, null);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private PlayerProfile loadPlayerFromDB(@Nullable UUID uuid, @Nullable String playerName) throws RuntimeException {
|
|
private PlayerProfile loadPlayerFromDB(@Nullable UUID uuid, @Nullable String playerName) throws RuntimeException {
|
|
if(uuid == null && playerName == null) {
|
|
if(uuid == null && playerName == null) {
|
|
throw new RuntimeException("Error looking up player, both UUID and playerName are null and one must not be.");
|
|
throw new RuntimeException("Error looking up player, both UUID and playerName are null and one must not be.");
|
|
@@ -622,17 +651,18 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
writeMissingRows(connection, id);
|
|
writeMissingRows(connection, id);
|
|
|
|
|
|
statement = connection.prepareStatement(
|
|
statement = connection.prepareStatement(
|
|
- "SELECT "
|
|
|
|
- + "s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, s.alchemy, "
|
|
|
|
- + "e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, e.alchemy, "
|
|
|
|
- + "c.taming, c.mining, c.repair, c.woodcutting, c.unarmed, c.herbalism, c.excavation, c.archery, c.swords, c.axes, c.acrobatics, c.blast_mining, c.chimaera_wing, "
|
|
|
|
- + "h.mobhealthbar, h.scoreboardtips, u.uuid, u.user "
|
|
|
|
|
|
+ "SELECT " +
|
|
|
|
+ "s.taming, s.mining, s.repair, s.woodcutting, s.unarmed, s.herbalism, s.excavation, s.archery, s.swords, s.axes, s.acrobatics, s.fishing, s.alchemy, s.crossbows, s.tridents, " +
|
|
|
|
+ "e.taming, e.mining, e.repair, e.woodcutting, e.unarmed, e.herbalism, e.excavation, e.archery, e.swords, e.axes, e.acrobatics, e.fishing, e.alchemy, e.crossbows, e.tridents, " +
|
|
|
|
+ "c.taming, c.mining, c.repair, c.woodcutting, c.unarmed, c.herbalism, c.excavation, c.archery, c.swords, c.axes, c.acrobatics, c.blast_mining, c.chimaera_wing, c.crossbows, c.tridents, " +
|
|
|
|
+ "h.mobhealthbar, h.scoreboardtips, u.uuid, u.`user` "
|
|
+ "FROM " + tablePrefix + "users u "
|
|
+ "FROM " + tablePrefix + "users u "
|
|
+ "JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) "
|
|
+ "JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) "
|
|
+ "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) "
|
|
+ "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) "
|
|
+ "JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) "
|
|
+ "JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) "
|
|
+ "JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) "
|
|
+ "JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) "
|
|
- + "WHERE u.id = ?");
|
|
|
|
|
|
+ + "WHERE u.id = ?"
|
|
|
|
+ );
|
|
statement.setInt(1, id);
|
|
statement.setInt(1, id);
|
|
|
|
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
@@ -640,7 +670,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
if (resultSet.next()) {
|
|
if (resultSet.next()) {
|
|
try {
|
|
try {
|
|
PlayerProfile profile = loadFromResult(playerName, resultSet);
|
|
PlayerProfile profile = loadFromResult(playerName, resultSet);
|
|
- String name = resultSet.getString(42); // TODO: Magic Number, make sure it stays updated
|
|
|
|
|
|
+ String name = resultSet.getString(MAGIC_NUMBER); // TODO: Magic Number, make sure it stays updated
|
|
resultSet.close();
|
|
resultSet.close();
|
|
statement.close();
|
|
statement.close();
|
|
|
|
|
|
@@ -650,15 +680,15 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
&& uuid != null) {
|
|
&& uuid != null) {
|
|
statement = connection.prepareStatement(
|
|
statement = connection.prepareStatement(
|
|
"UPDATE `" + tablePrefix + "users` "
|
|
"UPDATE `" + tablePrefix + "users` "
|
|
- + "SET user = ? "
|
|
|
|
- + "WHERE user = ?");
|
|
|
|
|
|
+ + "SET `user` = ? "
|
|
|
|
+ + "WHERE `user` = ?");
|
|
statement.setString(1, "_INVALID_OLD_USERNAME_");
|
|
statement.setString(1, "_INVALID_OLD_USERNAME_");
|
|
statement.setString(2, name);
|
|
statement.setString(2, name);
|
|
statement.executeUpdate();
|
|
statement.executeUpdate();
|
|
statement.close();
|
|
statement.close();
|
|
statement = connection.prepareStatement(
|
|
statement = connection.prepareStatement(
|
|
"UPDATE `" + tablePrefix + "users` "
|
|
"UPDATE `" + tablePrefix + "users` "
|
|
- + "SET user = ?, uuid = ? "
|
|
|
|
|
|
+ + "SET `user` = ?, uuid = ? "
|
|
+ "WHERE id = ?");
|
|
+ "WHERE id = ?");
|
|
statement.setString(1, playerName);
|
|
statement.setString(1, playerName);
|
|
statement.setString(2, uuid.toString());
|
|
statement.setString(2, uuid.toString());
|
|
@@ -706,7 +736,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
+ "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) "
|
|
+ "JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) "
|
|
+ "JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) "
|
|
+ "JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) "
|
|
+ "JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) "
|
|
+ "JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) "
|
|
- + "WHERE u.user = ?");
|
|
|
|
|
|
+ + "WHERE u.`user` = ?");
|
|
List<String> usernames = getStoredUsers();
|
|
List<String> usernames = getStoredUsers();
|
|
int convertedUsers = 0;
|
|
int convertedUsers = 0;
|
|
long startMillis = System.currentTimeMillis();
|
|
long startMillis = System.currentTimeMillis();
|
|
@@ -745,7 +775,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
statement = connection.prepareStatement(
|
|
statement = connection.prepareStatement(
|
|
"UPDATE `" + tablePrefix + "users` SET "
|
|
"UPDATE `" + tablePrefix + "users` SET "
|
|
- + " uuid = ? WHERE user = ?");
|
|
|
|
|
|
+ + " uuid = ? WHERE `user` = ?");
|
|
statement.setString(1, uuid.toString());
|
|
statement.setString(1, uuid.toString());
|
|
statement.setString(2, userName);
|
|
statement.setString(2, userName);
|
|
statement.execute();
|
|
statement.execute();
|
|
@@ -769,7 +799,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
|
|
|
|
try {
|
|
try {
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
- statement = connection.prepareStatement("UPDATE " + tablePrefix + "users SET uuid = ? WHERE user = ?");
|
|
|
|
|
|
+ statement = connection.prepareStatement("UPDATE " + tablePrefix + "users SET uuid = ? WHERE `user` = ?");
|
|
|
|
|
|
for (Map.Entry<String, UUID> entry : fetchedUUIDs.entrySet()) {
|
|
for (Map.Entry<String, UUID> entry : fetchedUUIDs.entrySet()) {
|
|
statement.setString(1, entry.getValue().toString());
|
|
statement.setString(1, entry.getValue().toString());
|
|
@@ -811,7 +841,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
try {
|
|
try {
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
statement = connection.createStatement();
|
|
statement = connection.createStatement();
|
|
- resultSet = statement.executeQuery("SELECT user FROM " + tablePrefix + "users");
|
|
|
|
|
|
+ resultSet = statement.executeQuery("SELECT `user` FROM " + tablePrefix + "users");
|
|
while (resultSet.next()) {
|
|
while (resultSet.next()) {
|
|
users.add(resultSet.getString("user"));
|
|
users.add(resultSet.getString("user"));
|
|
}
|
|
}
|
|
@@ -832,7 +862,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
* Checks that the database structure is present and correct
|
|
* Checks that the database structure is present and correct
|
|
*/
|
|
*/
|
|
private void checkStructure() {
|
|
private void checkStructure() {
|
|
-
|
|
|
|
PreparedStatement statement = null;
|
|
PreparedStatement statement = null;
|
|
Statement createStatement = null;
|
|
Statement createStatement = null;
|
|
ResultSet resultSet = null;
|
|
ResultSet resultSet = null;
|
|
@@ -840,27 +869,30 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
|
|
|
|
try {
|
|
try {
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
connection = getConnection(PoolIdentifier.MISC);
|
|
- statement = connection.prepareStatement("SELECT table_name FROM INFORMATION_SCHEMA.TABLES"
|
|
|
|
- + " WHERE table_schema = ?"
|
|
|
|
- + " AND table_name = ?");
|
|
|
|
- statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
|
|
|
- statement.setString(2, tablePrefix + "users");
|
|
|
|
|
|
+ String schemaQuery = this.h2 ? "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_name = ?"
|
|
|
|
+ : "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = ? AND table_name = ?";
|
|
|
|
+
|
|
|
|
+ statement = connection.prepareStatement(schemaQuery);
|
|
|
|
+
|
|
|
|
+ setStatementQuery(statement, "users");
|
|
|
|
+
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
|
|
+
|
|
if (!resultSet.next()) {
|
|
if (!resultSet.next()) {
|
|
createStatement = connection.createStatement();
|
|
createStatement = connection.createStatement();
|
|
- createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` ("
|
|
|
|
- + "`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
|
|
|
|
- + "`user` varchar(40) NOT NULL,"
|
|
|
|
- + "`uuid` varchar(36) NULL DEFAULT NULL,"
|
|
|
|
- + "`lastlogin` int(32) unsigned NOT NULL,"
|
|
|
|
- + "PRIMARY KEY (`id`),"
|
|
|
|
- + "INDEX(`user`(20) ASC),"
|
|
|
|
- + "UNIQUE KEY `uuid` (`uuid`)) DEFAULT CHARSET=" + CHARSET_SQL + " AUTO_INCREMENT=1;");
|
|
|
|
|
|
+ String sql = "CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` (" +
|
|
|
|
+ "`id` int AUTO_INCREMENT," +
|
|
|
|
+ "`user` varchar(40) NOT NULL," +
|
|
|
|
+ "`uuid` varchar(36)," +
|
|
|
|
+ "`lastlogin` bigint NOT NULL," +
|
|
|
|
+ "PRIMARY KEY (`id`)," +
|
|
|
|
+ "INDEX `user_index`(`user`)," +
|
|
|
|
+ "UNIQUE(`uuid`))";
|
|
|
|
+ createStatement.executeUpdate(sql);
|
|
tryClose(createStatement);
|
|
tryClose(createStatement);
|
|
}
|
|
}
|
|
tryClose(resultSet);
|
|
tryClose(resultSet);
|
|
- statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
|
|
|
- statement.setString(2, tablePrefix + "huds");
|
|
|
|
|
|
+ setStatementQuery(statement, "huds");
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
if (!resultSet.next()) {
|
|
if (!resultSet.next()) {
|
|
createStatement = connection.createStatement();
|
|
createStatement = connection.createStatement();
|
|
@@ -873,8 +905,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
tryClose(createStatement);
|
|
tryClose(createStatement);
|
|
}
|
|
}
|
|
tryClose(resultSet);
|
|
tryClose(resultSet);
|
|
- statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
|
|
|
- statement.setString(2, tablePrefix + "cooldowns");
|
|
|
|
|
|
+ setStatementQuery(statement, "cooldowns");
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
if (!resultSet.next()) {
|
|
if (!resultSet.next()) {
|
|
createStatement = connection.createStatement();
|
|
createStatement = connection.createStatement();
|
|
@@ -893,13 +924,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
+ "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`chimaera_wing` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`chimaera_wing` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
|
|
+ + "`crossbows` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
|
|
+ + "`tridents` int(32) unsigned NOT NULL DEFAULT '0',"
|
|
+ "PRIMARY KEY (`user_id`)) "
|
|
+ "PRIMARY KEY (`user_id`)) "
|
|
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
|
|
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
|
|
tryClose(createStatement);
|
|
tryClose(createStatement);
|
|
}
|
|
}
|
|
tryClose(resultSet);
|
|
tryClose(resultSet);
|
|
- statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
|
|
|
- statement.setString(2, tablePrefix + "skills");
|
|
|
|
|
|
+ setStatementQuery(statement, "skills");
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
if (!resultSet.next()) {
|
|
if (!resultSet.next()) {
|
|
String startingLevel = "'" + mcMMO.p.getAdvancedConfig().getStartingLevel() + "'";
|
|
String startingLevel = "'" + mcMMO.p.getAdvancedConfig().getStartingLevel() + "'";
|
|
@@ -920,14 +952,15 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
+ "`fishing` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
+ "`fishing` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
|
|
+ + "`crossbows` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
|
|
+ + "`tridents` int(10) unsigned NOT NULL DEFAULT "+startingLevel+","
|
|
+ "`total` int(10) unsigned NOT NULL DEFAULT "+totalLevel+","
|
|
+ "`total` int(10) unsigned NOT NULL DEFAULT "+totalLevel+","
|
|
+ "PRIMARY KEY (`user_id`)) "
|
|
+ "PRIMARY KEY (`user_id`)) "
|
|
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
|
|
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
|
|
tryClose(createStatement);
|
|
tryClose(createStatement);
|
|
}
|
|
}
|
|
tryClose(resultSet);
|
|
tryClose(resultSet);
|
|
- statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
|
|
|
- statement.setString(2, tablePrefix + "experience");
|
|
|
|
|
|
+ setStatementQuery(statement, "experience");
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
if (!resultSet.next()) {
|
|
if (!resultSet.next()) {
|
|
createStatement = connection.createStatement();
|
|
createStatement = connection.createStatement();
|
|
@@ -946,6 +979,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`fishing` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`fishing` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
|
|
+ + "`crossbows` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
|
|
+ + "`tridents` int(10) unsigned NOT NULL DEFAULT '0',"
|
|
+ "PRIMARY KEY (`user_id`)) "
|
|
+ "PRIMARY KEY (`user_id`)) "
|
|
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
|
|
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
|
|
tryClose(createStatement);
|
|
tryClose(createStatement);
|
|
@@ -968,7 +1003,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- mcMMO.p.getLogger().info("Killing orphans");
|
|
|
|
|
|
+ // TODO: refactor
|
|
|
|
+ LogUtils.debug(logger, "Killing orphans");
|
|
createStatement = connection.createStatement();
|
|
createStatement = connection.createStatement();
|
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "experience` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "experience`.`user_id` = `u`.`id`)");
|
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "experience` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "experience`.`user_id` = `u`.`id`)");
|
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "huds` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "huds`.`user_id` = `u`.`id`)");
|
|
createStatement.executeUpdate("DELETE FROM `" + tablePrefix + "huds` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "users` `u` WHERE `" + tablePrefix + "huds`.`user_id` = `u`.`id`)");
|
|
@@ -985,21 +1021,53 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
tryClose(connection);
|
|
tryClose(connection);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ String skills = "skills";
|
|
|
|
+ String crossbows = "crossbows";
|
|
|
|
+ String tridents = "tridents";
|
|
|
|
+ String experience = "experience";
|
|
|
|
+ String cooldowns = "cooldowns";
|
|
|
|
+
|
|
|
|
+ updateStructure(skills, crossbows, String.valueOf(32));
|
|
|
|
+ updateStructure(skills, tridents, String.valueOf(32));
|
|
|
|
+
|
|
|
|
+ updateStructure(experience, crossbows, String.valueOf(10));
|
|
|
|
+ updateStructure(experience, tridents, String.valueOf(10));
|
|
|
|
+
|
|
|
|
+ updateStructure(cooldowns, crossbows, String.valueOf(10));
|
|
|
|
+ updateStructure(cooldowns, tridents, String.valueOf(10));
|
|
}
|
|
}
|
|
|
|
|
|
- private Connection getConnection(PoolIdentifier identifier) throws SQLException {
|
|
|
|
- Connection connection = null;
|
|
|
|
- switch (identifier) {
|
|
|
|
- case LOAD:
|
|
|
|
- connection = loadPool.getConnection();
|
|
|
|
- break;
|
|
|
|
- case MISC:
|
|
|
|
- connection = miscPool.getConnection();
|
|
|
|
- break;
|
|
|
|
- case SAVE:
|
|
|
|
- connection = savePool.getConnection();
|
|
|
|
- break;
|
|
|
|
|
|
+ private void updateStructure(String tableName, String columnName, String columnSize) {
|
|
|
|
+ try (Connection connection = getConnection(PoolIdentifier.MISC);
|
|
|
|
+ Statement createStatement = connection.createStatement()) {
|
|
|
|
+
|
|
|
|
+ String startingLevel = "'" + mcMMO.p.getAdvancedConfig().getStartingLevel() + "'";
|
|
|
|
+ createStatement.executeUpdate("ALTER TABLE `" + tablePrefix + tableName + "` "
|
|
|
|
+ + "ADD COLUMN IF NOT EXISTS `" + columnName + "` int(" + columnSize + ") unsigned NOT NULL DEFAULT " + startingLevel);
|
|
|
|
+
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
+ e.printStackTrace(); // Consider more robust logging
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setStatementQuery(PreparedStatement statement, String tableName) throws SQLException {
|
|
|
|
+ if (!this.h2) {
|
|
|
|
+ // Set schema name for MySQL
|
|
|
|
+ statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
|
|
|
+ statement.setString(2, tablePrefix + tableName);
|
|
|
|
+ } else {
|
|
|
|
+ // For H2, the schema parameter is not needed
|
|
|
|
+ statement.setString(1, tablePrefix + tableName);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Connection getConnection(PoolIdentifier identifier) throws SQLException {
|
|
|
|
+ Connection connection = switch (identifier) {
|
|
|
|
+ case LOAD -> loadPool.getConnection();
|
|
|
|
+ case MISC -> miscPool.getConnection();
|
|
|
|
+ case SAVE -> savePool.getConnection();
|
|
|
|
+ };
|
|
if (connection == null) {
|
|
if (connection == null) {
|
|
throw new RuntimeException("getConnection() for " + identifier.name().toLowerCase(Locale.ENGLISH) + " pool timed out. Increase max connections settings.");
|
|
throw new RuntimeException("getConnection() for " + identifier.name().toLowerCase(Locale.ENGLISH) + " pool timed out. Increase max connections settings.");
|
|
}
|
|
}
|
|
@@ -1012,8 +1080,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
* @param upgrade Upgrade to attempt to apply
|
|
* @param upgrade Upgrade to attempt to apply
|
|
*/
|
|
*/
|
|
private void checkDatabaseStructure(Connection connection, UpgradeType upgrade) {
|
|
private void checkDatabaseStructure(Connection connection, UpgradeType upgrade) {
|
|
|
|
+ // TODO: Rewrite / Refactor
|
|
if (!mcMMO.getUpgradeManager().shouldUpgrade(upgrade)) {
|
|
if (!mcMMO.getUpgradeManager().shouldUpgrade(upgrade)) {
|
|
- LogUtils.debug(mcMMO.p.getLogger(), "Skipping " + upgrade.name() + " upgrade (unneeded)");
|
|
|
|
|
|
+ LogUtils.debug(logger, "Skipping " + upgrade.name() + " upgrade (unneeded)");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1132,9 +1201,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
|
|
|
|
final int OFFSET_SKILLS = 0; // TODO update these numbers when the query
|
|
final int OFFSET_SKILLS = 0; // TODO update these numbers when the query
|
|
// changes (a new skill is added)
|
|
// changes (a new skill is added)
|
|
- final int OFFSET_XP = 13;
|
|
|
|
- final int OFFSET_DATS = 26;
|
|
|
|
- final int OFFSET_OTHER = 39;
|
|
|
|
|
|
+ final int OFFSET_XP = 15;
|
|
|
|
+ final int OFFSET_DATS = 28;
|
|
|
|
+ final int OFFSET_OTHER = 41;
|
|
|
|
|
|
skills.put(PrimarySkillType.TAMING, result.getInt(OFFSET_SKILLS + 1));
|
|
skills.put(PrimarySkillType.TAMING, result.getInt(OFFSET_SKILLS + 1));
|
|
skills.put(PrimarySkillType.MINING, result.getInt(OFFSET_SKILLS + 2));
|
|
skills.put(PrimarySkillType.MINING, result.getInt(OFFSET_SKILLS + 2));
|
|
@@ -1149,6 +1218,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
skills.put(PrimarySkillType.ACROBATICS, result.getInt(OFFSET_SKILLS + 11));
|
|
skills.put(PrimarySkillType.ACROBATICS, result.getInt(OFFSET_SKILLS + 11));
|
|
skills.put(PrimarySkillType.FISHING, result.getInt(OFFSET_SKILLS + 12));
|
|
skills.put(PrimarySkillType.FISHING, result.getInt(OFFSET_SKILLS + 12));
|
|
skills.put(PrimarySkillType.ALCHEMY, result.getInt(OFFSET_SKILLS + 13));
|
|
skills.put(PrimarySkillType.ALCHEMY, result.getInt(OFFSET_SKILLS + 13));
|
|
|
|
+ skills.put(PrimarySkillType.CROSSBOWS, result.getInt(OFFSET_SKILLS + 14));
|
|
|
|
+ skills.put(PrimarySkillType.TRIDENTS, result.getInt(OFFSET_SKILLS + 15));
|
|
|
|
|
|
skillsXp.put(PrimarySkillType.TAMING, result.getFloat(OFFSET_XP + 1));
|
|
skillsXp.put(PrimarySkillType.TAMING, result.getFloat(OFFSET_XP + 1));
|
|
skillsXp.put(PrimarySkillType.MINING, result.getFloat(OFFSET_XP + 2));
|
|
skillsXp.put(PrimarySkillType.MINING, result.getFloat(OFFSET_XP + 2));
|
|
@@ -1163,6 +1234,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
skillsXp.put(PrimarySkillType.ACROBATICS, result.getFloat(OFFSET_XP + 11));
|
|
skillsXp.put(PrimarySkillType.ACROBATICS, result.getFloat(OFFSET_XP + 11));
|
|
skillsXp.put(PrimarySkillType.FISHING, result.getFloat(OFFSET_XP + 12));
|
|
skillsXp.put(PrimarySkillType.FISHING, result.getFloat(OFFSET_XP + 12));
|
|
skillsXp.put(PrimarySkillType.ALCHEMY, result.getFloat(OFFSET_XP + 13));
|
|
skillsXp.put(PrimarySkillType.ALCHEMY, result.getFloat(OFFSET_XP + 13));
|
|
|
|
+ skillsXp.put(PrimarySkillType.CROSSBOWS, result.getFloat(OFFSET_XP + 14));
|
|
|
|
+ skillsXp.put(PrimarySkillType.TRIDENTS, result.getFloat(OFFSET_XP + 15));
|
|
|
|
|
|
// Taming - Unused - result.getInt(OFFSET_DATS + 1)
|
|
// Taming - Unused - result.getInt(OFFSET_DATS + 1)
|
|
skillsDATS.put(SuperAbilityType.SUPER_BREAKER, result.getInt(OFFSET_DATS + 2));
|
|
skillsDATS.put(SuperAbilityType.SUPER_BREAKER, result.getInt(OFFSET_DATS + 2));
|
|
@@ -1177,6 +1250,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
// Acrobatics - Unused - result.getInt(OFFSET_DATS + 11)
|
|
// Acrobatics - Unused - result.getInt(OFFSET_DATS + 11)
|
|
skillsDATS.put(SuperAbilityType.BLAST_MINING, result.getInt(OFFSET_DATS + 12));
|
|
skillsDATS.put(SuperAbilityType.BLAST_MINING, result.getInt(OFFSET_DATS + 12));
|
|
uniqueData.put(UniqueDataType.CHIMAERA_WING_DATS, result.getInt(OFFSET_DATS + 13));
|
|
uniqueData.put(UniqueDataType.CHIMAERA_WING_DATS, result.getInt(OFFSET_DATS + 13));
|
|
|
|
+ skillsDATS.put(SuperAbilityType.SUPER_SHOTGUN, result.getInt(OFFSET_DATS + 14));
|
|
|
|
+ skillsDATS.put(SuperAbilityType.TRIDENTS_SUPER_ABILITY, result.getInt(OFFSET_DATS + 15));
|
|
|
|
|
|
try {
|
|
try {
|
|
scoreboardTipsShown = result.getInt(OFFSET_OTHER + 2);
|
|
scoreboardTipsShown = result.getInt(OFFSET_OTHER + 2);
|
|
@@ -1196,17 +1271,21 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
|
|
|
|
private void printErrors(SQLException ex) {
|
|
private void printErrors(SQLException ex) {
|
|
- if (debug) {
|
|
|
|
- ex.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
|
|
- StackTraceElement element = ex.getStackTrace()[0];
|
|
|
|
- mcMMO.p.getLogger().severe("Location: " + element.getClassName() + " " + element.getMethodName() + " " + element.getLineNumber());
|
|
|
|
- mcMMO.p.getLogger().severe("SQLException: " + ex.getMessage());
|
|
|
|
- mcMMO.p.getLogger().severe("SQLState: " + ex.getSQLState());
|
|
|
|
- mcMMO.p.getLogger().severe("VendorError: " + ex.getErrorCode());
|
|
|
|
|
|
+ // logger.severe("SQLException: " + ex.getMessage());
|
|
|
|
+ logger.severe("SQLState: " + ex.getSQLState());
|
|
|
|
+ logger.severe("VendorError: " + ex.getErrorCode());
|
|
|
|
+
|
|
|
|
+ // Handling SQLException chain
|
|
|
|
+ SQLException nextException = ex.getNextException();
|
|
|
|
+ while (nextException != null) {
|
|
|
|
+ logger.severe("Caused by: " + nextException.getMessage());
|
|
|
|
+ nextException = nextException.getNextException();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
public DatabaseType getDatabaseType() {
|
|
public DatabaseType getDatabaseType() {
|
|
return DatabaseType.SQL;
|
|
return DatabaseType.SQL;
|
|
}
|
|
}
|
|
@@ -1222,7 +1301,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
resultSet.close();
|
|
resultSet.close();
|
|
- mcMMO.p.getLogger().info("Updating mcMMO MySQL tables to drop name uniqueness...");
|
|
|
|
|
|
+ logger.info("Updating mcMMO MySQL tables to drop name uniqueness...");
|
|
statement.execute("ALTER TABLE `" + tablePrefix + "users` "
|
|
statement.execute("ALTER TABLE `" + tablePrefix + "users` "
|
|
+ "DROP INDEX `user`,"
|
|
+ "DROP INDEX `user`,"
|
|
+ "ADD INDEX `user` (`user`(20) ASC)");
|
|
+ "ADD INDEX `user` (`user`(20) ASC)");
|
|
@@ -1240,7 +1319,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_ALCHEMY);
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_ALCHEMY);
|
|
}
|
|
}
|
|
catch (SQLException ex) {
|
|
catch (SQLException ex) {
|
|
- mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Alchemy...");
|
|
|
|
|
|
+ logger.info("Updating mcMMO MySQL tables for Alchemy...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD `alchemy` int(10) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD `alchemy` int(10) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "experience` ADD `alchemy` int(10) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "experience` ADD `alchemy` int(10) NOT NULL DEFAULT '0'");
|
|
}
|
|
}
|
|
@@ -1252,7 +1331,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_BLAST_MINING_COOLDOWN);
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_BLAST_MINING_COOLDOWN);
|
|
}
|
|
}
|
|
catch (SQLException ex) {
|
|
catch (SQLException ex) {
|
|
- mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Blast Mining...");
|
|
|
|
|
|
+ logger.info("Updating mcMMO MySQL tables for Blast Mining...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1263,7 +1342,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UNIQUE_PLAYER_DATA);
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UNIQUE_PLAYER_DATA);
|
|
}
|
|
}
|
|
catch (SQLException ex) {
|
|
catch (SQLException ex) {
|
|
- mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Chimaera Wing...");
|
|
|
|
|
|
+ logger.info("Updating mcMMO MySQL tables for Chimaera Wing...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "cooldowns` ADD `chimaera_wing` int(32) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "cooldowns` ADD `chimaera_wing` int(32) NOT NULL DEFAULT '0'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1274,7 +1353,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_FISHING);
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_FISHING);
|
|
}
|
|
}
|
|
catch (SQLException ex) {
|
|
catch (SQLException ex) {
|
|
- mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Fishing...");
|
|
|
|
|
|
+ logger.info("Updating mcMMO MySQL tables for Fishing...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0'");
|
|
}
|
|
}
|
|
@@ -1286,7 +1365,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_MOB_HEALTHBARS);
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_MOB_HEALTHBARS);
|
|
}
|
|
}
|
|
catch (SQLException ex) {
|
|
catch (SQLException ex) {
|
|
- mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for mob healthbars...");
|
|
|
|
|
|
+ logger.info("Updating mcMMO MySQL tables for mob healthbars...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` ADD `mobhealthbar` varchar(50) NOT NULL DEFAULT '" + mcMMO.p.getGeneralConfig().getMobHealthbarDefault() + "'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` ADD `mobhealthbar` varchar(50) NOT NULL DEFAULT '" + mcMMO.p.getGeneralConfig().getMobHealthbarDefault() + "'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1297,7 +1376,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_SCOREBOARD_TIPS);
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_SCOREBOARD_TIPS);
|
|
}
|
|
}
|
|
catch (SQLException ex) {
|
|
catch (SQLException ex) {
|
|
- mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for scoreboard tips...");
|
|
|
|
|
|
+ logger.info("Updating mcMMO MySQL tables for scoreboard tips...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` ADD `scoreboardtips` int(10) NOT NULL DEFAULT '0' ;");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` ADD `scoreboardtips` int(10) NOT NULL DEFAULT '0' ;");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1310,7 +1389,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
resultSet.last();
|
|
resultSet.last();
|
|
|
|
|
|
if (resultSet.getRow() != SkillTools.NON_CHILD_SKILLS.size()) {
|
|
if (resultSet.getRow() != SkillTools.NON_CHILD_SKILLS.size()) {
|
|
- mcMMO.p.getLogger().info("Indexing tables, this may take a while on larger databases");
|
|
|
|
|
|
+ logger.info("Indexing tables, this may take a while on larger databases");
|
|
|
|
|
|
for (PrimarySkillType skill : SkillTools.NON_CHILD_SKILLS) {
|
|
for (PrimarySkillType skill : SkillTools.NON_CHILD_SKILLS) {
|
|
String skill_name = skill.name().toLowerCase(Locale.ENGLISH);
|
|
String skill_name = skill.name().toLowerCase(Locale.ENGLISH);
|
|
@@ -1351,7 +1430,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
|
|
|
|
if (!column_exists) {
|
|
if (!column_exists) {
|
|
- mcMMO.p.getLogger().info("Adding UUIDs to mcMMO MySQL user table...");
|
|
|
|
|
|
+ logger.info("Adding UUIDs to mcMMO MySQL user table...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD `uuid` varchar(36) NULL DEFAULT NULL");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD `uuid` varchar(36) NULL DEFAULT NULL");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD UNIQUE INDEX `uuid` (`uuid`) USING BTREE");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD UNIQUE INDEX `uuid` (`uuid`) USING BTREE");
|
|
|
|
|
|
@@ -1420,7 +1499,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
|
|
|
|
if (column_exists) {
|
|
if (column_exists) {
|
|
- mcMMO.p.getLogger().info("Removing party name from users table...");
|
|
|
|
|
|
+ logger.info("Removing party name from users table...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party`");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party`");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1454,7 +1533,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
|
|
|
|
if (!column_exists) {
|
|
if (!column_exists) {
|
|
- mcMMO.p.getLogger().info("Adding skill total column to skills table...");
|
|
|
|
|
|
+ logger.info("Adding skill total column to skills table...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD COLUMN `total` int NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD COLUMN `total` int NOT NULL DEFAULT '0'");
|
|
statement.executeUpdate("UPDATE `" + tablePrefix + "skills` SET `total` = (taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy)");
|
|
statement.executeUpdate("UPDATE `" + tablePrefix + "skills` SET `total` = (taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy)");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_total` (`total`) USING BTREE");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_total` (`total`) USING BTREE");
|
|
@@ -1490,7 +1569,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
}
|
|
}
|
|
|
|
|
|
if (column_exists) {
|
|
if (column_exists) {
|
|
- mcMMO.p.getLogger().info("Removing Spout HUD type from huds table...");
|
|
|
|
|
|
+ logger.info("Removing Spout HUD type from huds table...");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` DROP COLUMN `hudtype`");
|
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` DROP COLUMN `hudtype`");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1515,7 +1594,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
PreparedStatement statement = null;
|
|
PreparedStatement statement = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
- statement = connection.prepareStatement("SELECT id, user FROM " + tablePrefix + "users WHERE uuid = ? OR (uuid IS NULL AND user = ?)");
|
|
|
|
|
|
+ statement = connection.prepareStatement("SELECT id, `user` FROM " + tablePrefix + "users WHERE uuid = ? OR (uuid IS NULL AND `user` = ?)");
|
|
statement.setString(1, uuid.toString());
|
|
statement.setString(1, uuid.toString());
|
|
statement.setString(2, playerName);
|
|
statement.setString(2, playerName);
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
@@ -1544,7 +1623,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
PreparedStatement statement = null;
|
|
PreparedStatement statement = null;
|
|
|
|
|
|
try {
|
|
try {
|
|
- statement = connection.prepareStatement("SELECT id, user FROM " + tablePrefix + "users WHERE user = ?");
|
|
|
|
|
|
+ statement = connection.prepareStatement("SELECT id, `user` FROM " + tablePrefix + "users WHERE `user` = ?");
|
|
statement.setString(1, playerName);
|
|
statement.setString(1, playerName);
|
|
resultSet = statement.executeQuery();
|
|
resultSet = statement.executeQuery();
|
|
|
|
|
|
@@ -1577,7 +1656,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onDisable() {
|
|
public void onDisable() {
|
|
- LogUtils.debug(mcMMO.p.getLogger(), "Releasing connection pool resource...");
|
|
|
|
|
|
+ LogUtils.debug(logger, "Releasing connection pool resource...");
|
|
miscPool.close();
|
|
miscPool.close();
|
|
loadPool.close();
|
|
loadPool.close();
|
|
savePool.close();
|
|
savePool.close();
|
|
@@ -1619,19 +1698,19 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
*/
|
|
*/
|
|
|
|
|
|
//Alter users table
|
|
//Alter users table
|
|
- mcMMO.p.getLogger().info("SQL Converting tables from latin1 to utf8mb4");
|
|
|
|
|
|
+ logger.info("SQL Converting tables from latin1 to utf8mb4");
|
|
|
|
|
|
//Update "user" column
|
|
//Update "user" column
|
|
try {
|
|
try {
|
|
- mcMMO.p.getLogger().info("Updating user column to new encoding");
|
|
|
|
|
|
+ logger.info("Updating user column to new encoding");
|
|
statement.executeUpdate(getUpdateUserInUsersTableSQLQuery());
|
|
statement.executeUpdate(getUpdateUserInUsersTableSQLQuery());
|
|
|
|
|
|
//Update "uuid" column
|
|
//Update "uuid" column
|
|
- mcMMO.p.getLogger().info("Updating user column to new encoding");
|
|
|
|
|
|
+ logger.info("Updating user column to new encoding");
|
|
statement.executeUpdate(getUpdateUUIDInUsersTableSQLQuery());
|
|
statement.executeUpdate(getUpdateUUIDInUsersTableSQLQuery());
|
|
|
|
|
|
//Update "mobhealthbar" column
|
|
//Update "mobhealthbar" column
|
|
- mcMMO.p.getLogger().info("Updating mobhealthbar column to new encoding");
|
|
|
|
|
|
+ logger.info("Updating mobhealthbar column to new encoding");
|
|
statement.executeUpdate(getUpdateMobHealthBarInHudsTableSQLQuery());
|
|
statement.executeUpdate(getUpdateMobHealthBarInHudsTableSQLQuery());
|
|
|
|
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.SQL_CHARSET_UTF8MB4);
|
|
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.SQL_CHARSET_UTF8MB4);
|
|
@@ -1645,7 +1724,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
private String getUpdateUserInUsersTableSQLQuery() {
|
|
private String getUpdateUserInUsersTableSQLQuery() {
|
|
return "ALTER TABLE\n" +
|
|
return "ALTER TABLE\n" +
|
|
" " + tablePrefix + "users\n" +
|
|
" " + tablePrefix + "users\n" +
|
|
- " CHANGE user user\n" +
|
|
|
|
|
|
+ " CHANGE `user` user\n" +
|
|
" " + USER_VARCHAR + "\n" +
|
|
" " + USER_VARCHAR + "\n" +
|
|
" CHARACTER SET utf8mb4\n" +
|
|
" CHARACTER SET utf8mb4\n" +
|
|
" COLLATE utf8mb4_unicode_ci;";
|
|
" COLLATE utf8mb4_unicode_ci;";
|
|
@@ -1670,4 +1749,28 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|
" CHARACTER SET utf8mb4\n" +
|
|
" CHARACTER SET utf8mb4\n" +
|
|
" COLLATE utf8mb4_unicode_ci;";
|
|
" COLLATE utf8mb4_unicode_ci;";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void printAllTablesWithColumns(Connection connection) {
|
|
|
|
+ try {
|
|
|
|
+ DatabaseMetaData metaData = connection.getMetaData();
|
|
|
|
+ String[] types = {"TABLE"};
|
|
|
|
+ ResultSet tables = metaData.getTables(null, null, "%", types);
|
|
|
|
+
|
|
|
|
+ while (tables.next()) {
|
|
|
|
+ String tableName = tables.getString("TABLE_NAME");
|
|
|
|
+ System.out.println("Table: " + tableName);
|
|
|
|
+
|
|
|
|
+ ResultSet columns = metaData.getColumns(null, null, tableName, "%");
|
|
|
|
+ while (columns.next()) {
|
|
|
|
+ String columnName = columns.getString("COLUMN_NAME");
|
|
|
|
+ String columnType = columns.getString("TYPE_NAME");
|
|
|
|
+ System.out.println(" Column: " + columnName + " Type: " + columnType);
|
|
|
|
+ }
|
|
|
|
+ columns.close();
|
|
|
|
+ }
|
|
|
|
+ tables.close();
|
|
|
|
+ } catch (SQLException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|