1
0
mirror of https://github.com/mcMMO-Dev/mcMMO.git synced 2026-02-20 10:43:12 +01:00

Prepare for UUID update

This commit is contained in:
TfT_02
2014-04-10 17:57:40 +02:00
parent 48c7aa3e84
commit 7643edfdcd
6 changed files with 105 additions and 20 deletions

View File

@@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
@@ -271,6 +272,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":");
writer.append(profile.getSkillLevel(SkillType.ALCHEMY)).append(":");
writer.append(profile.getSkillXpLevel(SkillType.ALCHEMY)).append(":");
UUID uuid = profile.getUniqueId();
writer.append(uuid == null ? "" : uuid.toString()).append(":");
writer.append("\r\n");
}
}
@@ -313,7 +316,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
return skills;
}
public void newUser(String playerName) {
public void newUser(String playerName, String uuid) {
BufferedWriter out = null;
synchronized (fileWritingLock) {
try {
@@ -362,7 +365,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
out.append(Config.getInstance().getMobHealthbarDefault().toString()).append(":"); // Mob Healthbar HUD
out.append("0:"); // Alchemy
out.append("0:"); // AlchemyXp
out.append(uuid).append(":"); // UUID
// Add more in the same format as the line above
out.newLine();
@@ -376,7 +380,12 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
}
}
@Deprecated
public PlayerProfile loadPlayerProfile(String playerName, boolean create) {
return loadPlayerProfile(playerName, "", create);
}
public PlayerProfile loadPlayerProfile(String playerName, String uuid, boolean create) {
BufferedReader in = null;
String usersFilePath = mcMMO.getUsersFilePath();
@@ -399,7 +408,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
// Didn't find the player, create a new one
if (create) {
newUser(playerName);
newUser(playerName, uuid);
return new PlayerProfile(playerName, true);
}
}
@@ -645,7 +654,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
}
// If they're valid, rewrite them to the file.
if (character.length == 41) {
if (character.length == 42) {
writer.append(line).append("\r\n");
continue;
}
@@ -699,6 +708,14 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
oldVersion = "1.4.08";
}
}
if (character.length <= 41) {
// Addition of UUIDs
// Version 1.5.01
newLine.append(":");
if (oldVersion == null) {
oldVersion = "1.5.01";
}
}
// Remove any blanks that shouldn't be there, and validate the other fields
String[] newCharacter = newLine.toString().split(":");
@@ -869,7 +886,15 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
}
return new PlayerProfile(character[0], skills, skillsXp, skillsDATS, mobHealthbarType);
UUID uuid;
try {
uuid = UUID.fromString(character[41]);
}
catch (Exception e) {
uuid = null;
}
return new PlayerProfile(character[0], uuid, skills, skillsXp, skillsDATS, mobHealthbarType);
}
private Map<SkillType, Integer> getSkillMapFromLine(String[] character) {