Fix for reveling hidden debug info for plugins

This commit is contained in:
GeorgH93 2016-11-24 21:31:59 +01:00
parent 241527aac6
commit 82856a81e3
4 changed files with 93 additions and 91 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.16.4</version>
<version>1.16.4.1</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>
@ -60,8 +60,8 @@
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.10</version>
</dependency>
</dependencies>

View File

@ -48,8 +48,8 @@ protected HikariConfig getPoolConfig()
@Override
protected void updateQuerysForDialect()
{
Query_DeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` + INTERVAL {VarMaxAge} day < NOW()";
Query_UpdateBP = Query_UpdateBP.replaceAll("\\{NOW\\}", "NOW()");
queryDeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` + INTERVAL {VarMaxAge} day < NOW()";
queryUpdateBP = queryUpdateBP.replaceAll("\\{NOW\\}", "NOW()");
}
@Override
@ -60,52 +60,52 @@ protected void checkDB()
ResultSet res;
if(useUUIDs)
{
stmt.execute("CREATE TABLE IF NOT EXISTS `" + Table_Players + "` (`" + Field_PlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + Field_Name + "` CHAR(16) NOT NULL,`" + Field_UUID + "` CHAR(36) UNIQUE, PRIMARY KEY (`" + Field_PlayerID + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + Table_Players + "' AND COLUMN_NAME = '" + Field_UUID + "';");
stmt.execute("CREATE TABLE IF NOT EXISTS `" + tablePlayers + "` (`" + fieldPlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + fieldName + "` CHAR(16) NOT NULL,`" + fieldUUID + "` CHAR(36) UNIQUE, PRIMARY KEY (`" + fieldPlayerID + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldUUID + "';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + Table_Players + "` ADD COLUMN `" + Field_UUID + "` CHAR(36) UNIQUE;");
stmt.execute("ALTER TABLE `" + tablePlayers + "` ADD COLUMN `" + fieldUUID + "` CHAR(36) UNIQUE;");
}
res.close();
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + Table_Players + "' AND COLUMN_NAME = '" + Field_Name + "' AND COLUMN_KEY='UNI';");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldName + "' AND COLUMN_KEY='UNI';");
if(res.next())
{
stmt.execute("ALTER TABLE `" + Table_Players + "` DROP INDEX `" + Field_Name + "_UNIQUE`;");
stmt.execute("ALTER TABLE `" + tablePlayers + "` DROP INDEX `" + fieldName + "_UNIQUE`;");
}
res.close();
if(useUUIDSeparators)
{
res = stmt.executeQuery("SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + Table_Players + "' AND COLUMN_NAME = '" + Field_UUID + "';");
res = stmt.executeQuery("SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldUUID + "';");
if(res.next() && res.getInt(1) < 36)
{
stmt.execute("ALTER TABLE `" + Table_Players + "` MODIFY `" + Field_UUID + "` CHAR(36) UNIQUE;");
stmt.execute("ALTER TABLE `" + tablePlayers + "` MODIFY `" + fieldUUID + "` CHAR(36) UNIQUE;");
}
res.close();
}
}
else
{
stmt.execute("CREATE TABLE IF NOT EXISTS `" + Table_Players + "` (`" + Field_PlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + Field_Name + "` CHAR(16) NOT NULL, PRIMARY KEY (`" + Field_PlayerID + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + Table_Players + "' AND COLUMN_NAME = '" + Field_Name + "' AND COLUMN_KEY='UNI';");
stmt.execute("CREATE TABLE IF NOT EXISTS `" + tablePlayers + "` (`" + fieldPlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + fieldName + "` CHAR(16) NOT NULL, PRIMARY KEY (`" + fieldPlayerID + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldName + "' AND COLUMN_KEY='UNI';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + Table_Players + "` ADD UNIQUE INDEX `" + Field_Name + "_UNIQUE` (`" + Field_Name + "` ASC);");
stmt.execute("ALTER TABLE `" + tablePlayers + "` ADD UNIQUE INDEX `" + fieldName + "_UNIQUE` (`" + fieldName + "` ASC);");
}
res.close();
}
stmt.execute("CREATE TABLE IF NOT EXISTS `" + Table_Backpacks + "` (`" + Field_BPOwner + "` INT UNSIGNED NOT NULL, `" + Field_BPITS + "` BLOB, `"
+ Field_BPVersion + "` INT DEFAULT 0, " + ((maxAge > 0) ? "`" + Field_BPLastUpdate + "` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " : "") + "PRIMARY KEY (`" + Field_BPOwner + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + Table_Backpacks + "' AND COLUMN_NAME = '" + Field_BPVersion + "';");
stmt.execute("CREATE TABLE IF NOT EXISTS `" + tableBackpacks + "` (`" + fieldBPOwner + "` INT UNSIGNED NOT NULL, `" + fieldBPITS + "` BLOB, `"
+ fieldBPVersion + "` INT DEFAULT 0, " + ((maxAge > 0) ? "`" + fieldBPLastUpdate + "` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " : "") + "PRIMARY KEY (`" + fieldBPOwner + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tableBackpacks + "' AND COLUMN_NAME = '" + fieldBPVersion + "';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + Table_Backpacks + "` ADD COLUMN `" + Field_BPVersion + "` INT DEFAULT 0;");
stmt.execute("ALTER TABLE `" + tableBackpacks + "` ADD COLUMN `" + fieldBPVersion + "` INT DEFAULT 0;");
}
if(maxAge > 0)
{
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + Table_Backpacks + "' AND COLUMN_NAME = '" + Field_BPLastUpdate + "';");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tableBackpacks + "' AND COLUMN_NAME = '" + fieldBPLastUpdate + "';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + Table_Backpacks + "` ADD COLUMN `" + Field_BPLastUpdate + "` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;");
stmt.execute("ALTER TABLE `" + tableBackpacks + "` ADD COLUMN `" + fieldBPLastUpdate + "` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;");
}
res.close();
}

View File

@ -36,21 +36,23 @@ public abstract class SQL extends Database
{
private HikariDataSource dataSource;
protected String Table_Players, Table_Backpacks; // Table Names
protected String Field_Name, Field_PlayerID, Field_UUID, Field_BPOwner, Field_BPITS, Field_BPVersion, Field_BPLastUpdate; // Table Fields
protected String Query_UpdatePlayerAdd, Query_GetPlayerID, Query_InsertBP, Query_UpdateBP, Query_GetBP, Query_DeleteOldBackpacks, Query_GetUnsetOrInvalidUUIDs, Query_FixUUIDs; // DB Querys
protected boolean UpdatePlayer;
protected String tablePlayers, tableBackpacks; // Table Names
protected String fieldName, fieldPlayerID, fieldUUID, fieldBPOwner, fieldBPITS, fieldBPVersion, fieldBPLastUpdate; // Table Fields
protected String queryUpdatePlayerAdd, queryGetPlayerID, queryInsertBP, queryUpdateBP, queryGetBP, queryDeleteOldBackpacks, queryGetUnsetOrInvalidUUIDs, queryFixUUIDs; // DB Querys
protected boolean updatePlayer;
public SQL(MinePacks mp)
{
super(mp);
dataSource = new HikariDataSource(getPoolConfig());
HikariConfig poolConfig = getPoolConfig();
poolConfig.setPoolName("Minepacks-Connection-Pool");
dataSource = new HikariDataSource(poolConfig);
loadSettings();
buildQuerys();
checkDB();
if(useUUIDs && UpdatePlayer)
if(useUUIDs && updatePlayer)
{
checkUUIDs(); // Check if there are user accounts without UUID
}
@ -60,7 +62,7 @@ public SQL(MinePacks mp)
{
try
{
getConnection().createStatement().execute(Query_DeleteOldBackpacks);
getConnection().createStatement().execute(queryDeleteOldBackpacks);
}
catch(SQLException e)
{
@ -74,16 +76,16 @@ public SQL(MinePacks mp)
protected void loadSettings()
{
// Load table and field names
Table_Players = plugin.config.getUserTable();
Table_Backpacks = plugin.config.getBackpackTable();
Field_PlayerID = plugin.config.getDBFields("User.Player_ID");
Field_Name = plugin.config.getDBFields("User.Name");
Field_UUID = plugin.config.getDBFields("User.UUID");
Field_BPOwner = plugin.config.getDBFields("Backpack.Owner_ID");
Field_BPITS = plugin.config.getDBFields("Backpack.ItemStacks");
Field_BPVersion = plugin.config.getDBFields("Backpack.Version");
Field_BPLastUpdate = plugin.config.getDBFields("Backpack.LastUpdate");
UpdatePlayer = plugin.config.getUpdatePlayer();
tablePlayers = plugin.config.getUserTable();
tableBackpacks = plugin.config.getBackpackTable();
fieldPlayerID = plugin.config.getDBFields("User.Player_ID");
fieldName = plugin.config.getDBFields("User.Name");
fieldUUID = plugin.config.getDBFields("User.UUID");
fieldBPOwner = plugin.config.getDBFields("Backpack.Owner_ID");
fieldBPITS = plugin.config.getDBFields("Backpack.ItemStacks");
fieldBPVersion = plugin.config.getDBFields("Backpack.Version");
fieldBPLastUpdate = plugin.config.getDBFields("Backpack.LastUpdate");
updatePlayer = plugin.config.getUpdatePlayer();
}
@Override
@ -110,7 +112,7 @@ public UpdateData(String name, String uuid, int id)
{
Map<String, UpdateData> toConvert = new HashMap<>();
List<UpdateData> toUpdate = new LinkedList<>();
try(Statement stmt = connection.createStatement(); ResultSet res = stmt.executeQuery(Query_GetUnsetOrInvalidUUIDs))
try(Statement stmt = connection.createStatement(); ResultSet res = stmt.executeQuery(queryGetUnsetOrInvalidUUIDs))
{
while(res.next())
{
@ -118,15 +120,15 @@ public UpdateData(String name, String uuid, int id)
{
plugin.log.info(plugin.lang.get("Console.UpdateUUIDs"));
}
String uuid = res.getString(Field_UUID);
String uuid = res.getString(fieldUUID);
if(uuid == null)
{
toConvert.put(res.getString(Field_Name).toLowerCase(), new UpdateData(res.getString(Field_Name), null, res.getInt(Field_PlayerID)));
toConvert.put(res.getString(fieldName).toLowerCase(), new UpdateData(res.getString(fieldName), null, res.getInt(fieldPlayerID)));
}
else
{
uuid = (useUUIDSeparators) ? uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5") : uuid.replaceAll("-", "");
toUpdate.add(new UpdateData(res.getString(Field_Name), uuid, res.getInt(Field_PlayerID)));
toUpdate.add(new UpdateData(res.getString(fieldName), uuid, res.getInt(fieldPlayerID)));
}
}
}
@ -142,7 +144,7 @@ public UpdateData(String name, String uuid, int id)
toUpdate.add(updateData);
}
}
try(PreparedStatement ps = connection.prepareStatement(Query_FixUUIDs))
try(PreparedStatement ps = connection.prepareStatement(queryFixUUIDs))
{
for(UpdateData updateData : toUpdate)
{
@ -171,48 +173,48 @@ protected Connection getConnection() throws SQLException
protected final void buildQuerys()
{
// Build the SQL querys with placeholders for the table and field names
Query_GetBP = "SELECT `{FieldBPOwner}`,`{FieldBPITS}`,`{FieldBPVersion}` FROM `{TableBackpacks}` INNER JOIN `{TablePlayers}` ON `{TableBackpacks}`.`{FieldBPOwner}`=`{TablePlayers}`.`{FieldPlayerID}` WHERE ";
queryGetBP = "SELECT `{FieldBPOwner}`,`{FieldBPITS}`,`{FieldBPVersion}` FROM `{TableBackpacks}` INNER JOIN `{TablePlayers}` ON `{TableBackpacks}`.`{FieldBPOwner}`=`{TablePlayers}`.`{FieldPlayerID}` WHERE ";
if(useUUIDs)
{
Query_UpdatePlayerAdd = "INSERT INTO `{TablePlayers}` (`{FieldName}`,`{FieldUUID}`) VALUES (?,?) ON DUPLICATE KEY UPDATE `{FieldName}`=?;";
Query_GetPlayerID = "SELECT `{FieldPlayerID}` FROM `{TablePlayers}` WHERE `{FieldUUID}`=?;";
Query_GetBP += "`{FieldUUID}`=?;";
queryUpdatePlayerAdd = "INSERT INTO `{TablePlayers}` (`{FieldName}`,`{FieldUUID}`) VALUES (?,?) ON DUPLICATE KEY UPDATE `{FieldName}`=?;";
queryGetPlayerID = "SELECT `{FieldPlayerID}` FROM `{TablePlayers}` WHERE `{FieldUUID}`=?;";
queryGetBP += "`{FieldUUID}`=?;";
}
else
{
Query_UpdatePlayerAdd = "INSERT IGNORE INTO `{TablePlayers}` (`{FieldName}`) VALUES (?);";
Query_GetPlayerID = "SELECT `{FieldPlayerID}` FROM `{TablePlayers}` WHERE `{FieldName}`=?;";
Query_GetBP += "`{FieldName}`=?;";
queryUpdatePlayerAdd = "INSERT IGNORE INTO `{TablePlayers}` (`{FieldName}`) VALUES (?);";
queryGetPlayerID = "SELECT `{FieldPlayerID}` FROM `{TablePlayers}` WHERE `{FieldName}`=?;";
queryGetBP += "`{FieldName}`=?;";
}
Query_InsertBP = "INSERT INTO `{TableBackpacks}` (`{FieldBPOwner}`,`{FieldBPITS}`,`{FieldBPVersion}`) VALUES (?,?,?);";
Query_UpdateBP = "UPDATE `{TableBackpacks}` SET `{FieldBPITS}`=?,`{FieldBPVersion}`=?";
queryInsertBP = "INSERT INTO `{TableBackpacks}` (`{FieldBPOwner}`,`{FieldBPITS}`,`{FieldBPVersion}`) VALUES (?,?,?);";
queryUpdateBP = "UPDATE `{TableBackpacks}` SET `{FieldBPITS}`=?,`{FieldBPVersion}`=?";
if(maxAge > 0)
{
Query_UpdateBP += ",`{FieldBPLastUpdate}`={NOW}";
queryUpdateBP += ",`{FieldBPLastUpdate}`={NOW}";
}
Query_UpdateBP += " WHERE `{FieldBPOwner}`=?;";
Query_DeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` < DATE('now', '-{VarMaxAge} days')";
queryUpdateBP += " WHERE `{FieldBPOwner}`=?;";
queryDeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` < DATE('now', '-{VarMaxAge} days')";
if(useUUIDSeparators)
{
Query_GetUnsetOrInvalidUUIDs = "SELECT `{FieldPlayerID}`,`{FieldName}`,`{FieldUUID}` FROM `{TablePlayers}` WHERE `{FieldUUID}` IS NULL OR `{FieldUUID}` NOT LIKE '%-%-%-%-%';";
queryGetUnsetOrInvalidUUIDs = "SELECT `{FieldPlayerID}`,`{FieldName}`,`{FieldUUID}` FROM `{TablePlayers}` WHERE `{FieldUUID}` IS NULL OR `{FieldUUID}` NOT LIKE '%-%-%-%-%';";
}
else
{
Query_GetUnsetOrInvalidUUIDs = "SELECT `{FieldPlayerID}`,`{FieldName}`,`{FieldUUID}` FROM `{TablePlayers}` WHERE `{FieldUUID}` IS NULL OR `{FieldUUID}` LIKE '%-%';";
queryGetUnsetOrInvalidUUIDs = "SELECT `{FieldPlayerID}`,`{FieldName}`,`{FieldUUID}` FROM `{TablePlayers}` WHERE `{FieldUUID}` IS NULL OR `{FieldUUID}` LIKE '%-%';";
}
Query_FixUUIDs = "UPDATE `{TablePlayers}` SET `{FieldUUID}`=? WHERE `{FieldPlayerID}`=?;";
queryFixUUIDs = "UPDATE `{TablePlayers}` SET `{FieldUUID}`=? WHERE `{FieldPlayerID}`=?;";
updateQuerysForDialect();
// Replace the table and filed names with the names from the config
Query_UpdatePlayerAdd = Query_UpdatePlayerAdd.replaceAll("\\{TablePlayers\\}", Table_Players).replaceAll("\\{FieldName\\}", Field_Name).replaceAll("\\{FieldUUID\\}", Field_UUID).replaceAll("\\{FieldPlayerID\\}", Field_PlayerID);
Query_GetPlayerID = Query_GetPlayerID.replaceAll("\\{TablePlayers\\}", Table_Players).replaceAll("\\{FieldName\\}", Field_Name).replaceAll("\\{FieldUUID\\}", Field_UUID).replaceAll("\\{FieldPlayerID\\}", Field_PlayerID);
Query_GetBP = Query_GetBP.replaceAll("\\{FieldBPOwner\\}", Field_BPOwner).replaceAll("\\{FieldBPITS\\}", Field_BPITS).replaceAll("\\{FieldBPVersion\\}", Field_BPVersion).replaceAll("\\{TableBackpacks\\}", Table_Backpacks).replaceAll("\\{TablePlayers\\}", Table_Players).replaceAll("\\{FieldPlayerID\\}", Field_PlayerID).replaceAll("\\{FieldName\\}", Field_Name).replaceAll("\\{FieldUUID\\}", Field_UUID);
Query_InsertBP = Query_InsertBP.replaceAll("\\{TableBackpacks\\}", Table_Backpacks).replaceAll("\\{FieldBPOwner\\}", Field_BPOwner).replaceAll("\\{FieldBPITS\\}", Field_BPITS).replaceAll("\\{FieldBPVersion\\}", Field_BPVersion).replaceAll("\\{FieldBPLastUpdate\\}", Field_BPLastUpdate);
Query_UpdateBP = Query_UpdateBP.replaceAll("\\{TableBackpacks\\}", Table_Backpacks).replaceAll("\\{FieldBPOwner\\}", Field_BPOwner).replaceAll("\\{FieldBPITS\\}", Field_BPITS).replaceAll("\\{FieldBPVersion\\}", Field_BPVersion).replaceAll("\\{FieldBPLastUpdate\\}", Field_BPLastUpdate);
Query_DeleteOldBackpacks = Query_DeleteOldBackpacks.replaceAll("\\{TableBackpacks\\}", Table_Backpacks).replaceAll("\\{FieldBPLastUpdate\\}", Field_BPLastUpdate).replaceAll("\\{VarMaxAge\\}", maxAge + "");
Query_GetUnsetOrInvalidUUIDs = Query_GetUnsetOrInvalidUUIDs.replaceAll("\\{TablePlayers\\}", Table_Players).replaceAll("\\{FieldName\\}", Field_Name).replaceAll("\\{FieldUUID\\}", Field_UUID).replaceAll("\\{FieldPlayerID\\}", Field_PlayerID);
Query_FixUUIDs = Query_FixUUIDs.replaceAll("\\{TablePlayers\\}", Table_Players).replaceAll("\\{FieldUUID\\}", Field_UUID).replaceAll("\\{FieldPlayerID\\}", Field_PlayerID);
queryUpdatePlayerAdd = queryUpdatePlayerAdd.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
queryGetPlayerID = queryGetPlayerID.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
queryGetBP = queryGetBP.replaceAll("\\{FieldBPOwner\\}", fieldBPOwner).replaceAll("\\{FieldBPITS\\}", fieldBPITS).replaceAll("\\{FieldBPVersion\\}", fieldBPVersion).replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID);
queryInsertBP = queryInsertBP.replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{FieldBPOwner\\}", fieldBPOwner).replaceAll("\\{FieldBPITS\\}", fieldBPITS).replaceAll("\\{FieldBPVersion\\}", fieldBPVersion).replaceAll("\\{FieldBPLastUpdate\\}", fieldBPLastUpdate);
queryUpdateBP = queryUpdateBP.replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{FieldBPOwner\\}", fieldBPOwner).replaceAll("\\{FieldBPITS\\}", fieldBPITS).replaceAll("\\{FieldBPVersion\\}", fieldBPVersion).replaceAll("\\{FieldBPLastUpdate\\}", fieldBPLastUpdate);
queryDeleteOldBackpacks = queryDeleteOldBackpacks.replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{FieldBPLastUpdate\\}", fieldBPLastUpdate).replaceAll("\\{VarMaxAge\\}", maxAge + "");
queryGetUnsetOrInvalidUUIDs = queryGetUnsetOrInvalidUUIDs.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
queryFixUUIDs = queryFixUUIDs.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
}
protected abstract void updateQuerysForDialect();
@ -252,11 +254,11 @@ public void updatePlayer(final Player player)
{
if(useUUIDs)
{
runStatementAsync(Query_UpdatePlayerAdd, player.getName(), getPlayerFormattedUUID(player), player.getName());
runStatementAsync(queryUpdatePlayerAdd, player.getName(), getPlayerFormattedUUID(player), player.getName());
}
else
{
runStatementAsync(Query_UpdatePlayerAdd, player.getName());
runStatementAsync(queryUpdatePlayerAdd, player.getName());
}
}
@ -277,7 +279,7 @@ public void run()
if(id <= 0)
{
final int newID;
try(PreparedStatement ps = connection.prepareStatement(Query_GetPlayerID))
try(PreparedStatement ps = connection.prepareStatement(queryGetPlayerID))
{
ps.setString(1, nameOrUUID);
try(ResultSet rs = ps.executeQuery())
@ -305,7 +307,7 @@ public void run()
plugin.log.warning("Failed saving backpack for: " + name + " (Unable to get players ID from database)");
return;
}
try(PreparedStatement ps = connection.prepareStatement(Query_InsertBP))
try(PreparedStatement ps = connection.prepareStatement(queryInsertBP))
{
ps.setInt(1, newID);
ps.setBytes(2, data);
@ -315,7 +317,7 @@ public void run()
}
else
{
try(PreparedStatement ps = connection.prepareStatement(Query_UpdateBP))
try(PreparedStatement ps = connection.prepareStatement(queryUpdateBP))
{
ps.setBytes(1, data);
ps.setInt(2, usedSerializer);
@ -340,7 +342,7 @@ protected void loadBackpack(final OfflinePlayer player, final Callback<Backpack>
@Override
public void run()
{
try(Connection conn = getConnection(); PreparedStatement ps = conn.prepareStatement(Query_GetBP))
try(Connection conn = getConnection(); PreparedStatement ps = conn.prepareStatement(queryGetBP))
{
ps.setString(1, getPlayerNameOrUUID(player));
final int bpID, version;
@ -389,7 +391,7 @@ public void run()
@Override
public Backpack loadBackpack(OfflinePlayer player) // The sync function shouldn't be called at all
{
try(Connection connection = getConnection(); PreparedStatement ps = connection.prepareStatement(Query_GetBP))
try(Connection connection = getConnection(); PreparedStatement ps = connection.prepareStatement(queryGetBP))
{
ps.setString(1, getPlayerNameOrUUID(player));
try(ResultSet rs = ps.executeQuery())

View File

@ -41,20 +41,20 @@ public SQLite(MinePacks mp)
protected void loadSettings()
{
// Set table and field names to fixed values to prevent users from destroying old databases.
Field_PlayerID = "player_id";
Field_Name = "name";
Field_UUID = "uuid";
Field_BPOwner = "owner";
fieldPlayerID = "player_id";
fieldName = "name";
fieldUUID = "uuid";
fieldBPOwner = "owner";
//noinspection SpellCheckingInspection
Field_BPITS = "itemstacks";
Field_BPVersion = "version";
fieldBPITS = "itemstacks";
fieldBPVersion = "version";
//noinspection SpellCheckingInspection
Field_BPLastUpdate = "lastupdate";
Table_Players = "backpack_players";
Table_Backpacks = "backpacks";
fieldBPLastUpdate = "lastupdate";
tablePlayers = "backpack_players";
tableBackpacks = "backpacks";
// Set fixed settings
useUUIDSeparators = false;
UpdatePlayer = true;
updatePlayer = true;
}
@Override
@ -80,17 +80,17 @@ protected void updateQuerysForDialect()
{
if(maxAge > 0)
{
Query_InsertBP = Query_InsertBP.replaceAll("\\) VALUES \\(\\?,\\?,\\?", "{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')");
queryInsertBP = queryInsertBP.replaceAll("\\) VALUES \\(\\?,\\?,\\?", "{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')");
}
Query_DeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` < DATE('now', '-{VarMaxAge} days')";
Query_UpdateBP = Query_UpdateBP.replaceAll("\\{NOW\\}", "DATE('now')");
queryDeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` < DATE('now', '-{VarMaxAge} days')";
queryUpdateBP = queryUpdateBP.replaceAll("\\{NOW\\}", "DATE('now')");
if(useUUIDs)
{
Query_UpdatePlayerAdd = "INSERT OR IGNORE INTO `{TablePlayers}` (`{FieldName}`,`{FieldUUID}`) VALUES (?,?);";
queryUpdatePlayerAdd = "INSERT OR IGNORE INTO `{TablePlayers}` (`{FieldName}`,`{FieldUUID}`) VALUES (?,?);";
}
else
{
Query_UpdatePlayerAdd = Query_UpdatePlayerAdd.replaceAll("INSERT IGNORE INTO", "INSERT OR IGNORE INTO");
queryUpdatePlayerAdd = queryUpdatePlayerAdd.replaceAll("INSERT IGNORE INTO", "INSERT OR IGNORE INTO");
}
}
@ -142,14 +142,14 @@ public void updatePlayer(final Player player)
@Override
public void run()
{
runStatement(Query_UpdatePlayerAdd, player.getName(), getPlayerFormattedUUID(player));
runStatement("UPDATE `" + Table_Players + "` SET `" + Field_Name + "`=? WHERE `" + Field_UUID + "`=?;", player.getName(), getPlayerFormattedUUID(player));
runStatement(queryUpdatePlayerAdd, player.getName(), getPlayerFormattedUUID(player));
runStatement("UPDATE `" + tablePlayers + "` SET `" + fieldName + "`=? WHERE `" + fieldUUID + "`=?;", player.getName(), getPlayerFormattedUUID(player));
}
});
}
else
{
runStatementAsync(Query_UpdatePlayerAdd, player.getName());
runStatementAsync(queryUpdatePlayerAdd, player.getName());
}
}
}