mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-02 08:39:49 +01:00
Fix bug with UserPurgeTask...
This commit is contained in:
parent
3dde331f9d
commit
d25a314d3a
@ -4,11 +4,16 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
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.datatypes.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.datatypes.SpoutHud;
|
||||||
|
import com.gmail.nossr50.spout.SpoutStuff;
|
||||||
import com.gmail.nossr50.util.Database;
|
import com.gmail.nossr50.util.Database;
|
||||||
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
public class UserPurgeTask implements Runnable {
|
public class UserPurgeTask implements Runnable {
|
||||||
private Plugin plugin;
|
private Plugin plugin;
|
||||||
@ -34,7 +39,7 @@ public class UserPurgeTask implements Runnable {
|
|||||||
private void purgePowerlessSQL() {
|
private void purgePowerlessSQL() {
|
||||||
System.out.println("Purging powerless users...");
|
System.out.println("Purging powerless users...");
|
||||||
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;
|
int purgedUsers = 0;
|
||||||
|
|
||||||
@ -42,16 +47,17 @@ public class UserPurgeTask implements Runnable {
|
|||||||
System.out.println("Checking user " + i + "/" + userslist.size());
|
System.out.println("Checking user " + i + "/" + userslist.size());
|
||||||
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 + "'");
|
||||||
|
String playerName = username.get(1).get(0);
|
||||||
|
|
||||||
if (username != null && Bukkit.getOfflinePlayer(username.get(1).get(0)).isOnline()) {
|
if (Bukkit.getOfflinePlayer(playerName).isOnline()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteFromSQL(userId);
|
deleteFromSQL(userId, playerName);
|
||||||
purgedUsers++;
|
purgedUsers++;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLogger().info("Purged " + purgedUsers + "users from the database.");
|
plugin.getLogger().info("Purged " + purgedUsers + " users from the database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void purgeOldSQL() {
|
private void purgeOldSQL() {
|
||||||
@ -65,19 +71,22 @@ public class UserPurgeTask implements Runnable {
|
|||||||
for (int i = 1; i <= userslist.size(); i++) {
|
for (int i = 1; i <= userslist.size(); i++) {
|
||||||
System.out.println("Checking user " + i + "/" + userslist.size());
|
System.out.println("Checking user " + i + "/" + userslist.size());
|
||||||
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 + "'");
|
||||||
|
String playerName = username.get(1).get(0);
|
||||||
|
|
||||||
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;
|
||||||
long loginDifference = currentTime - lastLoginTime;
|
long loginDifference = currentTime - lastLoginTime;
|
||||||
|
|
||||||
if (loginDifference > 2630000000L) {
|
if (loginDifference > 2630000000L) {
|
||||||
deleteFromSQL(userId);
|
deleteFromSQL(userId, playerName);
|
||||||
purgedUsers++;
|
purgedUsers++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLogger().info("Purged " + purgedUsers + "users from the database.");
|
plugin.getLogger().info("Purged " + purgedUsers + " users from the database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFromSQL(int userId) {
|
private void deleteFromSQL(int userId, String playerName) {
|
||||||
System.out.println("Deleting user " + userId);
|
System.out.println("Deleting user " + userId);
|
||||||
database.write("DELETE FROM "
|
database.write("DELETE FROM "
|
||||||
+ databaseName + "."
|
+ databaseName + "."
|
||||||
@ -104,6 +113,31 @@ public class UserPurgeTask implements Runnable {
|
|||||||
+ tablePrefix + "experience WHERE "
|
+ tablePrefix + "experience WHERE "
|
||||||
+ tablePrefix + "experience.user_id=" + userId);
|
+ tablePrefix + "experience.user_id=" + userId);
|
||||||
|
|
||||||
|
profileCleanup(playerName);
|
||||||
|
|
||||||
System.out.println("User " + userId + " was successfully removed!");
|
System.out.println("User " + userId + " was successfully removed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void profileCleanup(String playerName) {
|
||||||
|
McMMOPlayer mcmmoPlayer = Users.getPlayer(playerName);
|
||||||
|
|
||||||
|
if (mcmmoPlayer != null) {
|
||||||
|
Player player = mcmmoPlayer.getPlayer();
|
||||||
|
SpoutHud spoutHud = mcmmoPlayer.getProfile().getSpoutHud();
|
||||||
|
|
||||||
|
if (spoutHud != null) {
|
||||||
|
spoutHud.removeWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
|
Users.remove(playerName);
|
||||||
|
|
||||||
|
if (player.isOnline()) {
|
||||||
|
Users.addUser(player);
|
||||||
|
|
||||||
|
if (mcMMO.spoutEnabled) {
|
||||||
|
SpoutStuff.reloadSpoutPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class Database {
|
|||||||
private static mcMMO plugin = null;
|
private static mcMMO plugin = null;
|
||||||
|
|
||||||
// Scale waiting time by this much per failed attempt
|
// Scale waiting time by this much per failed attempt
|
||||||
private static final double SCALING_FACTOR = 10;
|
private static final double SCALING_FACTOR = 40;
|
||||||
|
|
||||||
// Minimum wait in nanoseconds (default 500ms)
|
// Minimum wait in nanoseconds (default 500ms)
|
||||||
private static final long MIN_WAIT = 500L*1000000L;
|
private static final long MIN_WAIT = 500L*1000000L;
|
||||||
|
Loading…
Reference in New Issue
Block a user