Expanding DB cleanup settings, Player Leveling config pt 1

This commit is contained in:
nossr50
2019-03-13 13:09:27 -07:00
parent d139d520e7
commit 8660d86306
14 changed files with 153 additions and 31 deletions

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import java.util.List;
import java.util.Map;
@ -12,7 +13,7 @@ import java.util.UUID;
public interface DatabaseManager {
// One month in milliseconds
public final long PURGE_TIME = 2630000000L * MainConfig.getInstance().getOldUsersCutoff();
public final long PURGE_TIME = 2630000000L * mcMMO.getDatabaseCleaningSettings().getOldUserCutoffMonths();
// During convertUsers, how often to output a status
public final int progressInterval = 200;

View File

@ -58,7 +58,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
boolean powerless = true;
for (int skill : skills.values()) {
if (skill != 0) {
if (skill > mcMMO.getPlayerLevelingSettings().getStartingLevel()) {
powerless = false;
break;
}
@ -384,7 +384,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
// Open the file to write the player
out = new BufferedWriter(new FileWriter(mcMMO.getUsersFilePath(), true));
String startingLevel = AdvancedConfig.getInstance().getStartingLevel() + ":";
String startingLevel = mcMMO.getPlayerLevelingSettings().getStartingLevel() + ":";
// Add the player to the end
out.append(playerName).append(":");

View File

@ -119,12 +119,23 @@ public final class SQLDatabaseManager implements DatabaseManager {
connection = getConnection(PoolIdentifier.MISC);
statement = connection.createStatement();
String startingLevel = String.valueOf(mcMMO.getPlayerLevelingSettings().getStartingLevel());
//Purge users who have not leveled from the default level
purged = statement.executeUpdate("DELETE FROM " + tablePrefix + "skills WHERE "
+ "taming = " + startingLevel + " AND mining = " + startingLevel + " AND woodcutting = " + startingLevel + " AND repair = " + startingLevel + " "
+ "AND unarmed = " + startingLevel + " AND herbalism = " + startingLevel + " AND excavation = " + startingLevel + " AND "
+ "archery = " + startingLevel + " AND swords = " + startingLevel + " AND axes = " + startingLevel + " AND acrobatics = " + startingLevel + " "
+ "AND fishing = " + startingLevel + " AND alchemy = " + startingLevel + ";");
//Purge users who have 0 for all levels
purged += statement.executeUpdate("DELETE FROM " + tablePrefix + "skills WHERE "
+ "taming = 0 AND mining = 0 AND woodcutting = 0 AND repair = 0 "
+ "AND unarmed = 0 AND herbalism = 0 AND excavation = 0 AND "
+ "archery = 0 AND swords = 0 AND axes = 0 AND acrobatics = 0 "
+ "AND fishing = 0 AND alchemy = 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 + "huds` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "skills` `s` WHERE `" + tablePrefix + "huds`.`user_id` = `s`.`user_id`)");
statement.executeUpdate("DELETE FROM `" + tablePrefix + "cooldowns` WHERE NOT EXISTS (SELECT * FROM `" + tablePrefix + "skills` `s` WHERE `" + tablePrefix + "cooldowns`.`user_id` = `s`.`user_id`)");
@ -845,8 +856,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
statement.setString(2, tablePrefix + "skills");
resultSet = statement.executeQuery();
if (!resultSet.next()) {
String startingLevel = "'" + AdvancedConfig.getInstance().getStartingLevel() + "'";
String totalLevel = "'" + (AdvancedConfig.getInstance().getStartingLevel() * (PrimarySkillType.values().length - PrimarySkillType.CHILD_SKILLS.size())) + "'";
String startingLevel = "'" + mcMMO.getPlayerLevelingSettings().getStartingLevel() + "'";
String totalLevel = "'" + (mcMMO.getPlayerLevelingSettings().getStartingLevel() * (PrimarySkillType.values().length - PrimarySkillType.CHILD_SKILLS.size())) + "'";
createStatement = connection.createStatement();
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` ("
+ "`user_id` int(10) unsigned NOT NULL,"