mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
UUID flatfile stuff
This commit is contained in:
parent
e7d5aa17bf
commit
e619e01c23
@ -403,7 +403,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
// Find if the line contains the player we want.
|
// Find if the line contains the player we want.
|
||||||
String[] character = line.split(":");
|
String[] character = line.split(":");
|
||||||
|
|
||||||
if (!character[0].equalsIgnoreCase(playerName)) {
|
if (!character[41].equalsIgnoreCase(uuid) || !character[0].equalsIgnoreCase(playerName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,9 +412,14 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
|
|
||||||
// Didn't find the player, create a new one
|
// Didn't find the player, create a new one
|
||||||
if (create) {
|
if (create) {
|
||||||
|
if (uuid.isEmpty()) {
|
||||||
newUser(playerName, uuid);
|
newUser(playerName, uuid);
|
||||||
return new PlayerProfile(playerName, true);
|
return new PlayerProfile(playerName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newUser(playerName, uuid);
|
||||||
|
return new PlayerProfile(playerName, UUID.fromString(uuid), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -434,9 +439,13 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return unloaded profile
|
// Return unloaded profile
|
||||||
|
if (uuid.isEmpty()) {
|
||||||
return new PlayerProfile(playerName);
|
return new PlayerProfile(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new PlayerProfile(UUID.fromString(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
public void convertUsers(DatabaseManager destination) {
|
public void convertUsers(DatabaseManager destination) {
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
String usersFilePath = mcMMO.getUsersFilePath();
|
String usersFilePath = mcMMO.getUsersFilePath();
|
||||||
@ -485,10 +494,15 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
String line;
|
String line;
|
||||||
|
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
// Write out the same file but when we get to the player we want to remove, we skip his line.
|
String[] character = line.split(":");
|
||||||
if (!worked && line.split(":")[0].equalsIgnoreCase(userName)) {
|
if (!worked && character[0].equalsIgnoreCase(userName)) {
|
||||||
mcMMO.p.getLogger().info("User found, updating UUID...");
|
if (character.length < 42) {
|
||||||
line.split(":")[41] = uuid.toString();
|
mcMMO.p.getLogger().severe("Could not update UUID for " + userName + "!");
|
||||||
|
mcMMO.p.getLogger().severe("Database entry is invalid.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
line = line.replace(character[41], uuid.toString());
|
||||||
worked = true;
|
worked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,7 +521,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Saving " + userName + " | uuid = " + uuid.toString());
|
|
||||||
return worked;
|
return worked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,6 +664,7 @@ 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> usernames = new HashSet<String>();
|
||||||
HashSet<String> players = new HashSet<String>();
|
HashSet<String> players = new HashSet<String>();
|
||||||
|
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
@ -665,8 +679,13 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
String[] character = line.split(":");
|
String[] character = line.split(":");
|
||||||
|
|
||||||
|
// Prevent the same username from being present multiple times
|
||||||
|
if (!usernames.add(character[0])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent the same player from being present multiple times
|
// Prevent the same player from being present multiple times
|
||||||
if (!players.add(character[0])) {
|
if (character.length == 42 && (!character[41].isEmpty() && !players.add(character[41]))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,6 +774,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
if (character.length <= 41) {
|
if (character.length <= 41) {
|
||||||
// Addition of UUIDs
|
// Addition of UUIDs
|
||||||
// Version 1.5.01
|
// Version 1.5.01
|
||||||
|
// Add a space because otherwise it gets removed
|
||||||
newLine.append(" :");
|
newLine.append(" :");
|
||||||
if (oldVersion == null) {
|
if (oldVersion == null) {
|
||||||
oldVersion = "1.5.01";
|
oldVersion = "1.5.01";
|
||||||
@ -766,10 +786,10 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
boolean corrupted = false;
|
boolean corrupted = false;
|
||||||
|
|
||||||
for (int i = 0; i < newCharacter.length; i++) {
|
for (int i = 0; i < newCharacter.length; i++) {
|
||||||
if (newCharacter[i].isEmpty() && !(i == 2 || i == 3 || i == 23 || i == 33)) {
|
if (newCharacter[i].isEmpty() && !(i == 2 || i == 3 || i == 23 || i == 33 || i == 41)) {
|
||||||
corrupted = true;
|
corrupted = true;
|
||||||
|
|
||||||
if (newCharacter.length != 41) {
|
if (newCharacter.length != 42) {
|
||||||
newCharacter = (String[]) ArrayUtils.remove(newCharacter, i);
|
newCharacter = (String[]) ArrayUtils.remove(newCharacter, i);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -790,7 +810,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
newCharacter[i] = Config.getInstance().getMobHealthbarDefault().toString();
|
newCharacter[i] = Config.getInstance().getMobHealthbarDefault().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StringUtils.isInt(newCharacter[i]) && !(i == 0 || i == 2 || i == 3 || i == 23 || i == 33 || i == 38)) {
|
if (!StringUtils.isInt(newCharacter[i]) && !(i == 0 || i == 2 || i == 3 || i == 23 || i == 33 || i == 38 || i == 41)) {
|
||||||
corrupted = true;
|
corrupted = true;
|
||||||
newCharacter[i] = "0";
|
newCharacter[i] = "0";
|
||||||
}
|
}
|
||||||
@ -801,7 +821,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion != null) {
|
if (oldVersion != null) {
|
||||||
mcMMO.p.debug("Updating database line for player " + character[0] + " from before version " + oldVersion);
|
mcMMO.p.debug("Updating database line from before version " + oldVersion + " for player " + character[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (corrupted || oldVersion != null) {
|
if (corrupted || oldVersion != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user