Made MySQL reload all profiles on reconnect, modified

RemoveProfileFromMemoryTask
This commit is contained in:
nossr50 2012-03-23 12:30:27 -07:00
parent 631b2342b9
commit d1f13ddec0
2 changed files with 17 additions and 2 deletions

View File

@ -10,9 +10,11 @@ import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.DatabaseUpdate; import com.gmail.nossr50.datatypes.DatabaseUpdate;
import com.gmail.nossr50.datatypes.PlayerProfile;
public class Database { public class Database {
@ -253,6 +255,16 @@ public class Database {
public void run() { public void run() {
if (!isConnected()) { if (!isConnected()) {
connect(); 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); }, 20*60);

View File

@ -13,7 +13,10 @@ public class RemoveProfileFromMemoryTask implements Runnable {
@Override @Override
public void run() { public void run() {
Users.getProfile(player.getName()).save(); //We save here so players don't quit/reconnect to cause lag //Check if the profile still exists (stuff like MySQL reconnection removes profiles)
Users.removeUserByName(player.getName()); 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());
}
} }
} }