mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-19 08:55:26 +01:00
Added task to prune old and powerless users from the SQL database.
*** WARNING: THIS WILL RUN AUTOMATICALLY ON YOUR DB. IF YOU ARE WORRIED ABOUT DATA LOSS, BACK UP YOUR SQL DATA BEFORE INSTALLING THIS BUILD ***
This commit is contained in:
parent
5b5413c1a2
commit
ce42da5806
@ -8,6 +8,9 @@ Key:
|
||||
- Removal
|
||||
|
||||
Version 1.3.13-dev
|
||||
+ Added task to prune old and powerless users from the SQL database.
|
||||
*** WARNING: THIS WILL RUN AUTOMATICALLY ON YOUR DB. IF YOU ARE WORRIED ***
|
||||
*** ABOUT DATA LOSS, BACK UP YOUR SQL DATA BEFORE INSTALLING THIS BUILD ***
|
||||
+ Added Craftbukkit 1.4.6 compatibility
|
||||
+ Added a configurable durability cap for ArmorImpact to advanced.yml
|
||||
+ Added the version number to /mcmmo
|
||||
|
@ -146,11 +146,12 @@ public class MctopCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
for (int i = (page * 10) - 9; i <= (page * 10); i++) {
|
||||
if (i > userslist.size() || database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null) {
|
||||
HashMap<Integer, ArrayList<String>> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
|
||||
|
||||
if (i > userslist.size() || username == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
HashMap<Integer, ArrayList<String>> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
|
||||
sender.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ import com.gmail.nossr50.runnables.MobStoreCleaner;
|
||||
import com.gmail.nossr50.runnables.SaveTimer;
|
||||
import com.gmail.nossr50.runnables.SkillMonitor;
|
||||
import com.gmail.nossr50.runnables.SpoutStart;
|
||||
import com.gmail.nossr50.runnables.UserPurgeTask;
|
||||
import com.gmail.nossr50.skills.repair.RepairManager;
|
||||
import com.gmail.nossr50.skills.repair.RepairManagerFactory;
|
||||
import com.gmail.nossr50.skills.repair.Repairable;
|
||||
@ -196,6 +197,8 @@ public class mcMMO extends JavaPlugin {
|
||||
scheduler.scheduleSyncRepeatingTask(this, new BleedTimer(), 0, 40);
|
||||
//Chunklet unloader (Runs every 20 seconds by default)
|
||||
scheduler.scheduleSyncRepeatingTask(this, new ChunkletUnloader(), 0, ChunkletUnloader.RUN_INTERVAL * 20);
|
||||
//Old & Powerless User remover (Runs every 6 hours)
|
||||
scheduler.scheduleSyncRepeatingTask(this, new UserPurgeTask(), 0, 21600 * 20);
|
||||
|
||||
registerCommands();
|
||||
|
||||
|
88
src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java
Normal file
88
src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.gmail.nossr50.runnables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.util.Database;
|
||||
|
||||
public class UserPurgeTask implements Runnable {
|
||||
|
||||
private Database database = mcMMO.getPlayerDatabase();
|
||||
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
private String databaseName = Config.getInstance().getMySQLDatabaseName();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
purgePowerlessSQL();
|
||||
purgeOldSQL();
|
||||
}
|
||||
else {
|
||||
//TODO: Make this work for Flatfile data.
|
||||
}
|
||||
}
|
||||
|
||||
private void purgePowerlessSQL() {
|
||||
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 ");
|
||||
|
||||
for (int i = 1; i <= userslist.size(); i++) {
|
||||
int userId = Integer.valueOf(userslist.get(i).get(1));
|
||||
HashMap<Integer, ArrayList<String>> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + userId + "'");
|
||||
|
||||
if (Bukkit.getPlayer(username.get(1).get(0)).isOnline()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
deleteFromSQL(userId);
|
||||
}
|
||||
}
|
||||
|
||||
private void purgeOldSQL() {
|
||||
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 ");
|
||||
|
||||
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;
|
||||
long loginDifference = System.currentTimeMillis() - lastLoginTime;
|
||||
|
||||
if (loginDifference > 2630000000L) {
|
||||
deleteFromSQL(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteFromSQL(int userId) {
|
||||
database.write("DELETE FROM "
|
||||
+ databaseName + "."
|
||||
+ tablePrefix + "users WHERE "
|
||||
+ tablePrefix + "users.id=" + userId);
|
||||
|
||||
database.write("DELETE FROM "
|
||||
+ databaseName + "."
|
||||
+ tablePrefix + "cooldowns WHERE "
|
||||
+ tablePrefix + "cooldowns.user_id=" + userId);
|
||||
|
||||
database.write("DELETE FROM "
|
||||
+ databaseName + "."
|
||||
+ tablePrefix + "huds WHERE "
|
||||
+ tablePrefix + "huds.user_id=" + userId);
|
||||
|
||||
database.write("DELETE FROM "
|
||||
+ databaseName + "."
|
||||
+ tablePrefix + "skills WHERE "
|
||||
+ tablePrefix + "skills.user_id=" + userId);
|
||||
|
||||
database.write("DELETE FROM "
|
||||
+ databaseName + "."
|
||||
+ tablePrefix + "experience WHERE "
|
||||
+ tablePrefix + "experience.user_id=" + userId);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user