if( -> if (

This commit is contained in:
nossr50
2024-05-12 14:13:34 -07:00
parent 435a6fde34
commit 291effdbc8
163 changed files with 1116 additions and 1116 deletions

View File

@@ -33,7 +33,7 @@ public class FlatFileDataProcessor {
assert !lineData.isEmpty();
//Make sure the data line is "correct"
if(lineData.charAt(lineData.length() - 1) != ':') {
if (lineData.charAt(lineData.length() - 1) != ':') {
// Length checks depend on last rawSplitData being ':'
// We add it here if it is missing
lineData = lineData.concat(":");
@@ -48,9 +48,9 @@ public class FlatFileDataProcessor {
boolean anyBadData = false;
//This is the minimum size of the split array needed to be considered proper data
if(splitDataLine.length < getMinimumSplitDataLength()) {
if (splitDataLine.length < getMinimumSplitDataLength()) {
//Data is considered junk
if(!corruptDataFound) {
if (!corruptDataFound) {
logger.severe("Some corrupt data was found in mcmmo.users and has been repaired, it is possible that some player data has been lost in this process.");
corruptDataFound = true;
}
@@ -59,9 +59,9 @@ public class FlatFileDataProcessor {
builder.appendFlag(FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE);
//TODO: This block here is probably pointless
if(splitDataLine.length >= 10 //The value here is kind of arbitrary, it shouldn't be too low to avoid false positives, but also we aren't really going to correctly identify when player data has been corrupted or not with 100% accuracy ever
if (splitDataLine.length >= 10 //The value here is kind of arbitrary, it shouldn't be too low to avoid false positives, but also we aren't really going to correctly identify when player data has been corrupted or not with 100% accuracy ever
&& splitDataLine[0] != null && !splitDataLine[0].isEmpty()) {
if(splitDataLine[0].length() <= 16 && splitDataLine[0].length() >= 3) {
if (splitDataLine[0].length() <= 16 && splitDataLine[0].length() >= 3) {
logger.severe("Not enough data found to recover corrupted player data for user: "+splitDataLine[0]);
registerData(builder.appendFlag(FlatFileDataFlag.TOO_INCOMPLETE));
return;
@@ -81,14 +81,14 @@ public class FlatFileDataProcessor {
String name = splitDataLine[USERNAME_INDEX];
String strOfUUID = splitDataLine[UUID_INDEX];
if(name.isEmpty()) {
if (name.isEmpty()) {
reportBadDataLine("No name found for data", "[MISSING NAME]", lineData);
builder.appendFlag(FlatFileDataFlag.MISSING_NAME);
anyBadData = true;
badDataValues[USERNAME_INDEX] = true;
}
if(strOfUUID.isEmpty() || strOfUUID.equalsIgnoreCase("NULL")) {
if (strOfUUID.isEmpty() || strOfUUID.equalsIgnoreCase("NULL")) {
invalidUUID = true;
badDataValues[UUID_INDEX] = true;
reportBadDataLine("Empty/null UUID for user", "Empty/null", lineData);
@@ -110,20 +110,20 @@ public class FlatFileDataProcessor {
}
//Duplicate UUID is no good, reject them
if(!invalidUUID && uuid != null && uuids.contains(uuid)) {
if (!invalidUUID && uuid != null && uuids.contains(uuid)) {
registerData(builder.appendFlag(FlatFileDataFlag.DUPLICATE_UUID));
return;
}
uuids.add(uuid);
if(names.contains(name)) {
if (names.contains(name)) {
builder.appendFlag(FlatFileDataFlag.DUPLICATE_NAME);
anyBadData = true;
badDataValues[USERNAME_INDEX] = true;
}
if(!name.isEmpty())
if (!name.isEmpty())
names.add(name);
//Make sure the data is up to date schema wise, if it isn't we adjust it to the correct size and flag it for repair
@@ -136,9 +136,9 @@ public class FlatFileDataProcessor {
//Check each data for bad values
for(int i = 0; i < DATA_ENTRY_COUNT; i++) {
if(shouldNotBeEmpty(splitDataLine[i], i)) {
if (shouldNotBeEmpty(splitDataLine[i], i)) {
if(i == OVERHAUL_LAST_LOGIN) {
if (i == OVERHAUL_LAST_LOGIN) {
builder.appendFlag(FlatFileDataFlag.LAST_LOGIN_SCHEMA_UPGRADE);
}
@@ -149,13 +149,13 @@ public class FlatFileDataProcessor {
boolean isCorrectType = isOfExpectedType(splitDataLine[i], getExpectedValueType(i));
if(!isCorrectType) {
if (!isCorrectType) {
anyBadData = true;
badDataValues[i] = true;
}
}
if(anyBadData) {
if (anyBadData) {
builder.appendFlag(FlatFileDataFlag.BAD_VALUES);
builder.appendBadDataValues(badDataValues);
}
@@ -166,7 +166,7 @@ public class FlatFileDataProcessor {
public @NotNull String[] isDataSchemaUpToDate(@NotNull String[] splitDataLine, @NotNull FlatFileDataBuilder builder, boolean[] badDataValues) {
assert splitDataLine.length <= DATA_ENTRY_COUNT; //should NEVER be higher
if(splitDataLine.length < DATA_ENTRY_COUNT) {
if (splitDataLine.length < DATA_ENTRY_COUNT) {
int oldLength = splitDataLine.length;
splitDataLine = Arrays.copyOf(splitDataLine, DATA_ENTRY_COUNT);
int newLength = splitDataLine.length;
@@ -184,7 +184,7 @@ public class FlatFileDataProcessor {
public boolean shouldNotBeEmpty(@Nullable String data, int index) {
if(getExpectedValueType(index) == ExpectedType.IGNORED) {
if (getExpectedValueType(index) == ExpectedType.IGNORED) {
return false;
} else {
return data == null || data.isEmpty();
@@ -248,7 +248,7 @@ public class FlatFileDataProcessor {
FlatFileDataContainer flatFileDataContainer = builder.build();
flatFileDataContainers.add(flatFileDataContainer);
if(flatFileDataContainer.getDataFlags() != null)
if (flatFileDataContainer.getDataFlags() != null)
flatFileDataFlags.addAll(flatFileDataContainer.getDataFlags());
}
@@ -295,7 +295,7 @@ public class FlatFileDataProcessor {
for(FlatFileDataContainer dataContainer : flatFileDataContainers) {
String[] splitData = FlatFileDataUtil.getPreparedSaveDataLine(dataContainer);
if(splitData == null)
if (splitData == null)
continue;
//We add a trailing : as it is needed for some reason (is it?)

View File

@@ -101,15 +101,15 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
this.startingLevel = startingLevel;
this.testing = testing;
if(!usersFile.exists()) {
if (!usersFile.exists()) {
initEmptyDB();
}
if(!testing) {
if (!testing) {
List<FlatFileDataFlag> flatFileDataFlags = checkFileHealthAndStructure();
if(flatFileDataFlags != null) {
if(!flatFileDataFlags.isEmpty()) {
if (flatFileDataFlags != null) {
if (!flatFileDataFlags.isEmpty()) {
logger.info("Detected "+flatFileDataFlags.size() + " data entries which need correction.");
}
}
@@ -222,7 +222,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
if (lastPlayed == -1) {
OfflinePlayer player = mcMMO.p.getServer().getOfflinePlayer(uuid);
if(player.getLastPlayed() != 0) {
if (player.getLastPlayed() != 0) {
lastPlayed = player.getLastPlayed();
rewrite = true;
}
@@ -246,7 +246,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
out = new FileWriter(usersFilePath);
out.write(writer.toString());
if(testing) {
if (testing) {
System.out.println(writer);
}
}
@@ -354,15 +354,15 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
boolean wroteUser = false;
// While not at the end of the file
while ((line = in.readLine()) != null) {
if(line.startsWith("#")) {
if (line.startsWith("#")) {
writer.append(line).append("\r\n");
continue;
}
//Check for incomplete or corrupted data
if(!line.contains(":")) {
if (!line.contains(":")) {
if(!corruptDataFound) {
if (!corruptDataFound) {
logger.severe("mcMMO found some unexpected or corrupted data in mcmmo.users and is removing it, it is possible some data has been lost.");
corruptDataFound = true;
}
@@ -373,9 +373,9 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
String[] splitData = line.split(":");
//This would be rare, but check the splitData for having enough entries to contain a UUID
if(splitData.length < UUID_INDEX) { //UUID have been in mcMMO DB for a very long time so any user without
if (splitData.length < UUID_INDEX) { //UUID have been in mcMMO DB for a very long time so any user without
if(!corruptDataFound) {
if (!corruptDataFound) {
logger.severe("mcMMO found some unexpected or corrupted data in mcmmo.users and is removing it, it is possible some data has been lost.");
corruptDataFound = true;
}
@@ -397,7 +397,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
/*
* If we couldn't find the user in the DB we need to add him
*/
if(!wroteUser) {
if (!wroteUser) {
writeUserToLine(profile, writer);
}
@@ -498,7 +498,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
public @NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType primarySkillType, int pageNumber, int statsPerPage) throws InvalidSkillException {
//Fix for a plugin that people are using that is throwing SQL errors
if(primarySkillType != null && SkillTools.isChildSkill(primarySkillType)) {
if (primarySkillType != null && SkillTools.isChildSkill(primarySkillType)) {
logger.severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!");
}
@@ -572,11 +572,11 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
private @NotNull UserQuery getUserQuery(@Nullable UUID uuid, @Nullable String playerName) throws NullPointerException {
boolean hasName = playerName != null && !playerName.equalsIgnoreCase("null");
if(hasName && uuid != null) {
if (hasName && uuid != null) {
return new UserQueryFull(playerName, uuid);
} else if (uuid != null) {
return new UserQueryUUIDImpl(uuid);
} else if(hasName) {
} else if (hasName) {
return new UserQueryNameImpl(playerName);
} else {
throw new NullPointerException("Both name and UUID cannot be null, at least one must be non-null!");
@@ -610,7 +610,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
while ((line = in.readLine()) != null) {
if(line.startsWith("#")) {
if (line.startsWith("#")) {
continue;
}
@@ -620,12 +620,12 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
/* Don't read corrupt data */
if(rawSplitData.length < (USERNAME_INDEX + 1)) {
if (rawSplitData.length < (USERNAME_INDEX + 1)) {
continue;
}
// we found the player
if(playerName.equalsIgnoreCase(rawSplitData[USERNAME_INDEX])) {
if (playerName.equalsIgnoreCase(rawSplitData[USERNAME_INDEX])) {
return loadFromLine(rawSplitData);
}
}
@@ -660,24 +660,24 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
String line;
while ((line = in.readLine()) != null) {
if(line.startsWith("#")) {
if (line.startsWith("#")) {
continue;
}
// Find if the line contains the player we want.
String[] rawSplitData = line.split(":");
/* Don't read corrupt data */
if(rawSplitData.length < (UUID_INDEX + 1)) {
if (rawSplitData.length < (UUID_INDEX + 1)) {
continue;
}
try {
UUID fromDataUUID = UUID.fromString(rawSplitData[UUID_INDEX]);
if(fromDataUUID.equals(uuid)) {
if (fromDataUUID.equals(uuid)) {
return loadFromLine(rawSplitData);
}
} catch (Exception e) {
if(testing) {
if (testing) {
e.printStackTrace();
}
}
@@ -716,20 +716,20 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
String line;
while ((line = in.readLine()) != null) {
if(line.startsWith("#")) {
if (line.startsWith("#")) {
continue;
}
// Find if the line contains the player we want.
String[] rawSplitData = line.split(":");
/* Don't read corrupt data */
if(rawSplitData.length < (UUID_INDEX + 1)) {
if (rawSplitData.length < (UUID_INDEX + 1)) {
continue;
}
try {
UUID fromDataUUID = UUID.fromString(rawSplitData[UUID_INDEX]);
if(fromDataUUID.equals(uuid)) {
if (fromDataUUID.equals(uuid)) {
//Matched UUID, now check if name matches
String dbPlayerName = rawSplitData[USERNAME_INDEX];
@@ -746,7 +746,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
return loadFromLine(rawSplitData);
}
} catch (Exception e) {
if(testing) {
if (testing) {
e.printStackTrace();
}
}
@@ -774,7 +774,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}
private @NotNull PlayerProfile grabUnloadedProfile(@NotNull UUID uuid, @Nullable String playerName) {
if(playerName == null) {
if (playerName == null) {
playerName = ""; //No name for you boy!
}
@@ -793,7 +793,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
String line;
while ((line = in.readLine()) != null) {
if(line.startsWith("#")) {
if (line.startsWith("#")) {
continue;
}
@@ -1014,7 +1014,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
while ((line = in.readLine()) != null) {
if(line.startsWith("#"))
if (line.startsWith("#"))
continue;
String[] data = line.split(":");
@@ -1145,12 +1145,12 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
//Analyze the data
while ((currentLine = bufferedReader.readLine()) != null) {
//Commented lines
if(currentLine.startsWith("#") && dbCommentDate == null) { //The first commented line in the file is likely to be our note about when the file was created
if (currentLine.startsWith("#") && dbCommentDate == null) { //The first commented line in the file is likely to be our note about when the file was created
dbCommentDate = currentLine;
continue;
}
if(currentLine.isEmpty())
if (currentLine.isEmpty())
continue;
//TODO: We are never passing empty lines, should we remove the flag for them?
@@ -1158,12 +1158,12 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}
//Only update the file if needed
if(!dataProcessor.getFlatFileDataFlags().isEmpty()) {
if (!dataProcessor.getFlatFileDataFlags().isEmpty()) {
flagsFound = new ArrayList<>(dataProcessor.getFlatFileDataFlags());
logger.info("Updating FlatFile Database...");
fileWriter = new FileWriter(usersFilePath);
//Write data to file
if(dbCommentDate != null)
if (dbCommentDate != null)
fileWriter.write(dbCommentDate + "\r\n");
fileWriter.write(dataProcessor.processDataForSave().toString());
@@ -1176,7 +1176,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}
}
if(flagsFound == null || flagsFound.isEmpty()) {
if (flagsFound == null || flagsFound.isEmpty()) {
return null;
} else {
return flagsFound;
@@ -1184,7 +1184,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}
private void closeResources(BufferedReader bufferedReader, FileWriter fileWriter) {
if(bufferedReader != null) {
if (bufferedReader != null) {
try {
bufferedReader.close();
}

View File

@@ -59,7 +59,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
this.h2 = h2;
String connectionString = getConnectionString(h2);
if(!h2 && mcMMO.p.getGeneralConfig().getMySQLPublicKeyRetrieval()) {
if (!h2 && mcMMO.p.getGeneralConfig().getMySQLPublicKeyRetrieval()) {
connectionString+=
"&allowPublicKeyRetrieval=true";
}
@@ -140,7 +140,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
String connectionString = "jdbc:mysql://" + mcMMO.p.getGeneralConfig().getMySQLServerName()
+ ":" + mcMMO.p.getGeneralConfig().getMySQLServerPort() + "/" + mcMMO.p.getGeneralConfig().getMySQLDatabaseName();
if(!mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 17, 0) //Temporary hack for SQL and 1.17 support
if (!mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 17, 0) //Temporary hack for SQL and 1.17 support
&& mcMMO.p.getGeneralConfig().getMySQLSSL())
connectionString +=
"?verifyServerCertificate=false"+
@@ -247,7 +247,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
}
if (success) {
if(uuid != null)
if (uuid != null)
cleanupUser(uuid);
Misc.profileCleanup(playerName);
@@ -400,7 +400,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
List<PlayerStat> stats = new ArrayList<>();
//Fix for a plugin that people are using that is throwing SQL errors
if(skill != null && SkillTools.isChildSkill(skill)) {
if (skill != null && SkillTools.isChildSkill(skill)) {
logger.severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
throw new InvalidSkillException("A plugin hooking into mcMMO that you are using is attempting to read leaderboard skills for child skills, child skills do not have leaderboards! This is NOT an mcMMO error!");
}
@@ -631,7 +631,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
}
private PlayerProfile loadPlayerFromDB(@Nullable UUID uuid, @Nullable String playerName) throws RuntimeException {
if(uuid == null && playerName == null) {
if (uuid == null && playerName == null) {
throw new RuntimeException("Error looking up player, both UUID and playerName are null and one must not be.");
}

View File

@@ -28,7 +28,7 @@ public class FlatFileDataBuilder {
}
public @NotNull FlatFileDataContainer build() {
if(dataFlags.contains(FlatFileDataFlag.BAD_VALUES)) {
if (dataFlags.contains(FlatFileDataFlag.BAD_VALUES)) {
return new BadCategorizedFlatFileData(uniqueProcessingId, dataFlags, splitStringData, badDataValues);
}

View File

@@ -10,14 +10,14 @@ import static com.gmail.nossr50.database.FlatFileDatabaseManager.*;
public class FlatFileDataUtil {
public static @Nullable String[] getPreparedSaveDataLine(@NotNull FlatFileDataContainer dataContainer) {
if(dataContainer.getDataFlags() == null) {
if (dataContainer.getDataFlags() == null) {
return dataContainer.getSplitData();
}
//Data of this type is not salvageable
//TODO: Test that we ignore the things we are supposed to ignore
//TODO: Should we even keep track of the bad data or just not even build data containers for it? Making containers for it is only really useful for debugging.. well I suppose operations are typically async so it shouldn't matter
if(dataContainer.getDataFlags().contains(FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE)
if (dataContainer.getDataFlags().contains(FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE)
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.DUPLICATE_UUID) //For now we will not try to fix any issues with UUIDs
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.BAD_UUID_DATA) //For now we will not try to fix any issues with UUIDs
|| dataContainer.getDataFlags().contains(FlatFileDataFlag.TOO_INCOMPLETE)) {
@@ -29,7 +29,7 @@ public class FlatFileDataUtil {
/*
* First fix the bad data values if they exist
*/
if(dataContainer instanceof BadCategorizedFlatFileData badData) {
if (dataContainer instanceof BadCategorizedFlatFileData badData) {
splitData = repairBadData(dataContainer.getSplitData(), badData.getBadDataIndexes());
} else {
splitData = dataContainer.getSplitData();
@@ -42,7 +42,7 @@ public class FlatFileDataUtil {
public static @NotNull String[] repairBadData(@NotNull String[] splitData, boolean[] badDataValues) {
for(int i = 0; i < FlatFileDatabaseManager.DATA_ENTRY_COUNT; i++) {
if(badDataValues[i]) {
if (badDataValues[i]) {
//This data value was marked as bad so we zero initialize it
splitData[i] = getZeroInitialisedData(i, 0);
}