From e53fe3677843379b1a20134d453c5f00d333d2e6 Mon Sep 17 00:00:00 2001 From: riking Date: Wed, 31 Jul 2013 15:02:01 -0700 Subject: [PATCH] Use provided last-saved information for purge. The new method, OfflinePlayer.getLastPlayed(), is used as a backup for when the data is unparsable. TODO check if StringUtils is available here --- .../database/FlatfileDatabaseManager.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index 9a03c3a7f..6d8728728 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -26,6 +26,7 @@ import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.spout.huds.HudType; import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.StringUtils; public final class FlatfileDatabaseManager implements DatabaseManager { private final HashMap> playerStatHash = new HashMap>(); @@ -117,19 +118,30 @@ public final class FlatfileDatabaseManager implements DatabaseManager { while ((line = in.readLine()) != null) { String[] character = line.split(":"); String name = character[0]; - OfflinePlayer player = Bukkit.getOfflinePlayer(name); - boolean old = true; - if (player != null) { - old = (currentTime - player.getLastPlayed()) > PURGE_TIME; + long lastPlayed = StringUtils.getLong(character[37]) * Misc.TIME_CONVERSION_FACTOR; + boolean rewrite = false; + + if (lastPlayed == 0) { + OfflinePlayer player = Bukkit.getOfflinePlayer(name); + lastPlayed = player.getLastPlayed(); + rewrite = true; } - if (!old) { - writer.append(line).append("\r\n"); - } - else { + if (currentTime - lastPlayed > PURGE_TIME) { removedPlayers++; Misc.profileCleanup(name); } + else { + if (rewrite) { + // Rewrite their data with a valid time + character[37] = Long.toString(lastPlayed); + String newLine = org.apache.commons.lang.StringUtils.join(character, ":"); + writer.append(newLine).append("\r\n"); + } + else { + writer.append(line).append("\r\n"); + } + } } // Write the new file