Converting from MySQL -> FlatFile now accounts for users that don't exist yet in mcmmo.users

Fixes #3130
This commit is contained in:
nossr50 2019-01-11 02:17:03 -08:00
parent 3dca32a226
commit 1e8d950767
2 changed files with 61 additions and 46 deletions

View File

@ -40,6 +40,7 @@ Version 2.1.0
= (Skills) Added missing mushroom blocks to experience.yml defaults = (Skills) Added missing mushroom blocks to experience.yml defaults
= (Skills) Tridents will no longer be considered unarmed = (Skills) Tridents will no longer be considered unarmed
= (MySQL) You can now inspect offline players = (MySQL) You can now inspect offline players
= (MySQL) When converting from MySQL to flatfile mcMMO will now properly include all users in the conversion process
! (Party) Party member list will only include members of the party that you can see (aren't vanished) ! (Party) Party member list will only include members of the party that you can see (aren't vanished)
! (Skills) mcMMO skills will now be on a scale from 1-100 instead of 0-1000 (for existing mcMMO installs this is opt-in and off by default) ! (Skills) mcMMO skills will now be on a scale from 1-100 instead of 0-1000 (for existing mcMMO installs this is opt-in and off by default)
! (Skills) Skill Super Powers (Tree Feller, etc...) will now require level 10+ to use ! (Skills) Skill Super Powers (Tree Feller, etc...) will now require level 10+ to use

View File

@ -268,6 +268,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
StringBuilder writer = new StringBuilder(); StringBuilder writer = new StringBuilder();
String line; String line;
boolean wroteUser = false;
// While not at the end of the file // While not at the end of the file
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
// Read the line in and copy it to the output if it's not the player we want to edit // Read the line in and copy it to the output if it's not the player we want to edit
@ -277,6 +278,50 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
} }
else { else {
// Otherwise write the new player information // Otherwise write the new player information
writeUserToLine(profile, playerName, uuid, writer);
wroteUser = true;
}
}
/*
* If we couldn't find the user in the DB we need to add him
*/
if(!wroteUser)
{
writeUserToLine(profile, playerName, uuid, writer);
}
// Write the new file
out = new FileWriter(usersFilePath);
out.write(writer.toString());
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
}
}
}
private void writeUserToLine(PlayerProfile profile, String playerName, UUID uuid, StringBuilder writer) {
writer.append(playerName).append(":"); writer.append(playerName).append(":");
writer.append(profile.getSkillLevel(PrimarySkill.MINING)).append(":"); writer.append(profile.getSkillLevel(PrimarySkill.MINING)).append(":");
writer.append(":"); writer.append(":");
@ -324,37 +369,6 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
writer.append(profile.getUniqueData(UniqueDataType.CHIMAERA_WING_DATS)).append(":"); writer.append(profile.getUniqueData(UniqueDataType.CHIMAERA_WING_DATS)).append(":");
writer.append("\r\n"); writer.append("\r\n");
} }
}
// Write the new file
out = new FileWriter(usersFilePath);
out.write(writer.toString());
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
}
}
}
public List<PlayerStat> readLeaderboard(PrimarySkill skill, int pageNumber, int statsPerPage) { public List<PlayerStat> readLeaderboard(PrimarySkill skill, int pageNumber, int statsPerPage) {
updateLeaderboards(); updateLeaderboards();