From d1f13ddec0bc699f8beffcae985d249121d7fa51 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 23 Mar 2012 12:30:27 -0700 Subject: [PATCH] Made MySQL reload all profiles on reconnect, modified RemoveProfileFromMemoryTask --- src/main/java/com/gmail/nossr50/Database.java | 12 ++++++++++++ .../runnables/RemoveProfileFromMemoryTask.java | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/Database.java b/src/main/java/com/gmail/nossr50/Database.java index 87811df52..6c74e0f7e 100644 --- a/src/main/java/com/gmail/nossr50/Database.java +++ b/src/main/java/com/gmail/nossr50/Database.java @@ -10,9 +10,11 @@ import java.util.ArrayList; import java.util.Properties; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.DatabaseUpdate; +import com.gmail.nossr50.datatypes.PlayerProfile; public class Database { @@ -253,6 +255,16 @@ public class Database { public void run() { if (!isConnected()) { connect(); + if(isConnected()) { + //Save/Remove all profiles + for(PlayerProfile x : Users.players.values()) { + x.save(); + } + Users.players.clear(); //Clear the profiles + for(Player x : Bukkit.getOnlinePlayers()) { + Users.addUser(x); //Add in new profiles, forcing them to 'load' again from MySQL + } + } } } }, 20*60); diff --git a/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java index 81d6ad3e0..3beb99f72 100644 --- a/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java @@ -13,7 +13,10 @@ public class RemoveProfileFromMemoryTask implements Runnable { @Override public void run() { - Users.getProfile(player.getName()).save(); //We save here so players don't quit/reconnect to cause lag - Users.removeUserByName(player.getName()); + //Check if the profile still exists (stuff like MySQL reconnection removes profiles) + if(Users.players.containsKey(player.getName().toLowerCase())) { + Users.getProfile(player.getName()).save(); //We save here so players don't quit/reconnect to cause lag + Users.removeUserByName(player.getName()); + } } }