mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +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 org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
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.Users;
|
||||
|
||||
public class UserPurgeTask implements Runnable {
|
||||
private Plugin plugin;
|
||||
@ -34,7 +39,7 @@ public class UserPurgeTask implements Runnable {
|
||||
private void purgePowerlessSQL() {
|
||||
System.out.println("Purging powerless users...");
|
||||
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;
|
||||
|
||||
@ -42,12 +47,13 @@ public class UserPurgeTask implements Runnable {
|
||||
System.out.println("Checking user " + i + "/" + userslist.size());
|
||||
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);
|
||||
|
||||
if (username != null && Bukkit.getOfflinePlayer(username.get(1).get(0)).isOnline()) {
|
||||
if (Bukkit.getOfflinePlayer(playerName).isOnline()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
deleteFromSQL(userId);
|
||||
deleteFromSQL(userId, playerName);
|
||||
purgedUsers++;
|
||||
}
|
||||
|
||||
@ -65,11 +71,14 @@ public class UserPurgeTask implements Runnable {
|
||||
for (int i = 1; i <= userslist.size(); i++) {
|
||||
System.out.println("Checking user " + i + "/" + userslist.size());
|
||||
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 loginDifference = currentTime - lastLoginTime;
|
||||
|
||||
if (loginDifference > 2630000000L) {
|
||||
deleteFromSQL(userId);
|
||||
deleteFromSQL(userId, playerName);
|
||||
purgedUsers++;
|
||||
}
|
||||
}
|
||||
@ -77,7 +86,7 @@ public class UserPurgeTask implements Runnable {
|
||||
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);
|
||||
database.write("DELETE FROM "
|
||||
+ databaseName + "."
|
||||
@ -104,6 +113,31 @@ public class UserPurgeTask implements Runnable {
|
||||
+ tablePrefix + "experience WHERE "
|
||||
+ tablePrefix + "experience.user_id=" + userId);
|
||||
|
||||
profileCleanup(playerName);
|
||||
|
||||
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;
|
||||
|
||||
// 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)
|
||||
private static final long MIN_WAIT = 500L*1000000L;
|
||||
|
Loading…
Reference in New Issue
Block a user