mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-02 09:56:45 +01:00
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
This commit is contained in:
parent
7479a02220
commit
e53fe36778
@ -26,6 +26,7 @@ import com.gmail.nossr50.datatypes.skills.AbilityType;
|
|||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
import com.gmail.nossr50.datatypes.spout.huds.HudType;
|
import com.gmail.nossr50.datatypes.spout.huds.HudType;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
import com.gmail.nossr50.util.StringUtils;
|
||||||
|
|
||||||
public final class FlatfileDatabaseManager implements DatabaseManager {
|
public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||||
private final HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
|
private final HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
|
||||||
@ -117,19 +118,30 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
String[] character = line.split(":");
|
String[] character = line.split(":");
|
||||||
String name = character[0];
|
String name = character[0];
|
||||||
|
long lastPlayed = StringUtils.getLong(character[37]) * Misc.TIME_CONVERSION_FACTOR;
|
||||||
|
boolean rewrite = false;
|
||||||
|
|
||||||
|
if (lastPlayed == 0) {
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
||||||
boolean old = true;
|
lastPlayed = player.getLastPlayed();
|
||||||
if (player != null) {
|
rewrite = true;
|
||||||
old = (currentTime - player.getLastPlayed()) > PURGE_TIME;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!old) {
|
if (currentTime - lastPlayed > PURGE_TIME) {
|
||||||
writer.append(line).append("\r\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
removedPlayers++;
|
removedPlayers++;
|
||||||
Misc.profileCleanup(name);
|
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
|
// Write the new file
|
||||||
|
Loading…
Reference in New Issue
Block a user