mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-03-14 13:59:43 +01:00
Merge 7d43e7eba5f0fc26608fff2a791fba62a2decc75 into 1f53c62ced7ac39c0ec929e30b807c85793dc759
This commit is contained in:
commit
0e62dce817
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -26,6 +27,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 +119,33 @@ 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];
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
long lastPlayed = 0;
|
||||||
boolean old = true;
|
boolean rewrite = false;
|
||||||
if (player != null) {
|
try {
|
||||||
old = (currentTime - player.getLastPlayed()) > PURGE_TIME;
|
lastPlayed = Long.parseLong(character[37]) * Misc.TIME_CONVERSION_FACTOR;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
if (lastPlayed == 0) {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
||||||
|
lastPlayed = player.getLastPlayed();
|
||||||
|
rewrite = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@ -485,20 +501,12 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
in = new BufferedReader(new FileReader(usersFilePath));
|
in = new BufferedReader(new FileReader(usersFilePath));
|
||||||
String line = "";
|
String line = "";
|
||||||
ArrayList<String> players = new ArrayList<String>();
|
|
||||||
|
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
String[] data = line.split(":");
|
String[] data = line.split(":");
|
||||||
String playerName = data[0];
|
String playerName = data[0];
|
||||||
int powerLevel = 0;
|
int powerLevel = 0;
|
||||||
|
|
||||||
// Prevent the same player from being added multiple times (I'd like to note that this shouldn't happen...)
|
|
||||||
if (players.contains(playerName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
players.add(playerName);
|
|
||||||
|
|
||||||
Map<SkillType, Integer> skills = getSkillMapFromLine(data);
|
Map<SkillType, Integer> skills = getSkillMapFromLine(data);
|
||||||
|
|
||||||
powerLevel += putStat(acrobatics, playerName, skills.get(SkillType.ACROBATICS));
|
powerLevel += putStat(acrobatics, playerName, skills.get(SkillType.ACROBATICS));
|
||||||
@ -569,15 +577,73 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
in = new BufferedReader(new FileReader(usersFilePath));
|
in = new BufferedReader(new FileReader(usersFilePath));
|
||||||
StringBuilder writer = new StringBuilder();
|
StringBuilder writer = new StringBuilder();
|
||||||
String line = "";
|
String line = "";
|
||||||
|
HashSet<String> players = new HashSet<String>();
|
||||||
|
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
|
// Length checks depend on last character being ':'
|
||||||
|
if (line.charAt(line.length() - 1) != ':') {
|
||||||
|
line = line + ":";
|
||||||
|
}
|
||||||
String[] character = line.split(":");
|
String[] character = line.split(":");
|
||||||
|
|
||||||
|
// Prevent the same player from being present multiple times
|
||||||
|
if (!players.add(character[0])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// If they're valid, rewrite them to the file.
|
// If they're valid, rewrite them to the file.
|
||||||
if (character.length >= 37) {
|
if (character.length > 38) {
|
||||||
writer.append(line).append("\r\n");
|
writer.append(line).append("\r\n");
|
||||||
|
} else if (character.length < 33) {
|
||||||
|
// Before Version 1.0 - Drop
|
||||||
|
mcMMO.p.getLogger().warning("Dropping malformed or before version 1.0 line from database - " + line);
|
||||||
} else {
|
} else {
|
||||||
// Placeholder, repair row if needed (I.E. when new skills are added and such)
|
String oldVersion = null;
|
||||||
|
StringBuilder newLine = new StringBuilder(line);
|
||||||
|
boolean announce = false;
|
||||||
|
if (character.length <= 33) {
|
||||||
|
// Introduction of HUDType
|
||||||
|
// Version 1.1.06
|
||||||
|
// commit 78f79213cdd7190cd11ae54526f3b4ea42078e8a
|
||||||
|
newLine.append("STANDARD").append(":");
|
||||||
|
oldVersion = "1.1.06";
|
||||||
|
}
|
||||||
|
if (character.length <= 35) {
|
||||||
|
// Introduction of Fishing
|
||||||
|
// Version 1.2.00
|
||||||
|
// commit a814b57311bc7734661109f0e77fc8bab3a0bd29
|
||||||
|
newLine.append(0).append(":");
|
||||||
|
newLine.append(0).append(":");
|
||||||
|
if (oldVersion == null) oldVersion = "1.2.00";
|
||||||
|
}
|
||||||
|
if (character.length <= 36) {
|
||||||
|
// Introduction of Blast Mining cooldowns
|
||||||
|
// Version 1.3.00-dev
|
||||||
|
// commit fadbaf429d6b4764b8f1ad0efaa524a090e82ef5
|
||||||
|
newLine.append((int) 0).append(":");
|
||||||
|
if (oldVersion == null) oldVersion = "1.3.00";
|
||||||
|
}
|
||||||
|
if (character.length <= 37) {
|
||||||
|
// Making old-purge work with flatfile
|
||||||
|
// Version 1.4.00-dev
|
||||||
|
// commmit 3f6c07ba6aaf44e388cc3b882cac3d8f51d0ac28
|
||||||
|
|
||||||
|
// XXX Cannot create an OfflinePlayer at startup, use 0 and fix in purge
|
||||||
|
newLine.append("0").append(":");
|
||||||
|
announce = true; // TODO move this down
|
||||||
|
if (oldVersion == null) oldVersion = "1.4.00";
|
||||||
|
}
|
||||||
|
if (character.length <= 38) {
|
||||||
|
// Addition of mob healthbars
|
||||||
|
// Version 1.4.06
|
||||||
|
// commit da29185b7dc7e0d992754bba555576d48fa08aa6
|
||||||
|
newLine.append(Config.getInstance().getMobHealthbarDefault().toString()).append(":");
|
||||||
|
if (oldVersion == null) oldVersion = "1.4.06";
|
||||||
|
}
|
||||||
|
if (announce) {
|
||||||
|
mcMMO.p.debug("Updating database line for player " + character[0] + " from before version " + oldVersion);
|
||||||
|
}
|
||||||
|
writer.append(newLine).append("\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user