Helpful logging!

This commit is contained in:
gmcferrin 2013-01-10 20:33:48 -05:00
parent 6d9ef91315
commit b554fb342a
2 changed files with 18 additions and 5 deletions

View File

@ -201,10 +201,10 @@ public class mcMMO extends JavaPlugin {
//Old & Powerless User remover //Old & Powerless User remover
int purgeInterval = Config.getInstance().getPurgeInterval(); int purgeInterval = Config.getInstance().getPurgeInterval();
if (purgeInterval == 0) { if (purgeInterval == 0) {
scheduler.runTask(this, new UserPurgeTask()); scheduler.runTask(this, new UserPurgeTask(this));
} }
else if (purgeInterval > 0) { 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(); registerCommands();

View File

@ -4,17 +4,22 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.util.Database; import com.gmail.nossr50.util.Database;
public class UserPurgeTask implements Runnable { public class UserPurgeTask implements Runnable {
private Plugin plugin;
private Database database = mcMMO.getPlayerDatabase(); private Database database = mcMMO.getPlayerDatabase();
private String tablePrefix = Config.getInstance().getMySQLTablePrefix(); private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
private String databaseName = Config.getInstance().getMySQLDatabaseName(); private String databaseName = Config.getInstance().getMySQLDatabaseName();
public UserPurgeTask(Plugin plugin) {
this.plugin = plugin;
}
@Override @Override
public void run() { public void run() {
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {
@ -28,9 +33,10 @@ public class UserPurgeTask implements Runnable {
private void purgePowerlessSQL() { private void purgePowerlessSQL() {
String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing";
HashMap<Integer, ArrayList<String>> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC "); HashMap<Integer, ArrayList<String>> 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++) { for (int i = 1; i <= userslist.size(); i++) {
int userId = Integer.valueOf(userslist.get(i).get(1)); int userId = Integer.valueOf(userslist.get(i).get(1));
HashMap<Integer, ArrayList<String>> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + userId + "'"); HashMap<Integer, ArrayList<String>> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + userId + "'");
@ -40,14 +46,18 @@ public class UserPurgeTask implements Runnable {
} }
deleteFromSQL(userId); deleteFromSQL(userId);
purgedUsers++;
} }
plugin.getLogger().info("Purged " + purgedUsers + "users from the database.");
} }
private void purgeOldSQL() { private void purgeOldSQL() {
String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing";
HashMap<Integer, ArrayList<String>> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC "); HashMap<Integer, ArrayList<String>> 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++) { for (int i = 1; i <= userslist.size(); i++) {
int userId = Integer.valueOf(userslist.get(i).get(1)); int userId = Integer.valueOf(userslist.get(i).get(1));
long lastLoginTime = database.getInt("SELECT lastlogin FROM " + tablePrefix + "users WHERE id = '" + userId + "'") * 1000L; 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) { if (loginDifference > 2630000000L) {
deleteFromSQL(userId); deleteFromSQL(userId);
purgedUsers++;
} }
} }
plugin.getLogger().info("Purged " + purgedUsers + "users from the database.");
} }
private void deleteFromSQL(int userId) { private void deleteFromSQL(int userId) {