diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 2311f17a5..98214013f 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -201,10 +201,10 @@ public class mcMMO extends JavaPlugin { //Old & Powerless User remover int purgeInterval = Config.getInstance().getPurgeInterval(); if (purgeInterval == 0) { - scheduler.runTask(this, new UserPurgeTask()); + scheduler.runTask(this, new UserPurgeTask(this)); } else if (purgeInterval > 0) { - scheduler.scheduleSyncRepeatingTask(this, new UserPurgeTask(), 0, purgeInterval * 60L * 60L * 20L); + scheduler.scheduleSyncRepeatingTask(this, new UserPurgeTask(this), 0, purgeInterval * 60L * 60L * 20L); } registerCommands(); diff --git a/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java b/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java index cd17bcb76..f4e4cd5d3 100644 --- a/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java @@ -4,17 +4,22 @@ import java.util.ArrayList; import java.util.HashMap; import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.util.Database; public class UserPurgeTask implements Runnable { - + private Plugin plugin; private Database database = mcMMO.getPlayerDatabase(); private String tablePrefix = Config.getInstance().getMySQLTablePrefix(); private String databaseName = Config.getInstance().getMySQLDatabaseName(); + public UserPurgeTask(Plugin plugin) { + this.plugin = plugin; + } + @Override public void run() { if (Config.getInstance().getUseMySQL()) { @@ -28,9 +33,10 @@ public class UserPurgeTask implements Runnable { private void purgePowerlessSQL() { String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; - HashMap> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC "); + int purgedUsers = 0; + for (int i = 1; i <= userslist.size(); i++) { int userId = Integer.valueOf(userslist.get(i).get(1)); HashMap> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + userId + "'"); @@ -40,14 +46,18 @@ public class UserPurgeTask implements Runnable { } deleteFromSQL(userId); + purgedUsers++; } + + plugin.getLogger().info("Purged " + purgedUsers + "users from the database."); } private void purgeOldSQL() { String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; - HashMap> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC "); + int purgedUsers = 0; + for (int i = 1; i <= userslist.size(); i++) { int userId = Integer.valueOf(userslist.get(i).get(1)); long lastLoginTime = database.getInt("SELECT lastlogin FROM " + tablePrefix + "users WHERE id = '" + userId + "'") * 1000L; @@ -55,8 +65,11 @@ public class UserPurgeTask implements Runnable { if (loginDifference > 2630000000L) { deleteFromSQL(userId); + purgedUsers++; } } + + plugin.getLogger().info("Purged " + purgedUsers + "users from the database."); } private void deleteFromSQL(int userId) {