mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 18:24:43 +02:00
Add lastlogin tests
This commit is contained in:
@ -3,6 +3,7 @@ package com.gmail.nossr50.database;
|
||||
public enum ExpectedType {
|
||||
STRING,
|
||||
INTEGER,
|
||||
LONG,
|
||||
BOOLEAN,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
|
@ -3,6 +3,7 @@ package com.gmail.nossr50.database;
|
||||
public enum FlatFileDataFlag {
|
||||
INCOMPLETE,
|
||||
BAD_VALUES,
|
||||
LAST_LOGIN_SCHEMA_UPGRADE,
|
||||
MISSING_NAME,
|
||||
DUPLICATE_NAME,
|
||||
DUPLICATE_UUID,
|
||||
|
@ -2,8 +2,9 @@ package com.gmail.nossr50.database;
|
||||
|
||||
import com.gmail.nossr50.database.flatfile.FlatFileDataBuilder;
|
||||
import com.gmail.nossr50.database.flatfile.FlatFileDataContainer;
|
||||
import com.gmail.nossr50.database.flatfile.FlatFileSaveDataProcessor;
|
||||
import com.gmail.nossr50.database.flatfile.FlatFileDataUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
@ -134,16 +135,19 @@ public class FlatFileDataProcessor {
|
||||
//Check each data for bad values
|
||||
for(int i = 0; i < DATA_ENTRY_COUNT; i++) {
|
||||
if(shouldNotBeEmpty(splitDataLine[i], i)) {
|
||||
|
||||
if(i == OVERHAUL_LAST_LOGIN) {
|
||||
builder.appendFlag(FlatFileDataFlag.LAST_LOGIN_SCHEMA_UPGRADE);
|
||||
}
|
||||
|
||||
badDataValues[i] = true;
|
||||
anyBadData = true;
|
||||
reportBadDataLine("Data is empty when it should not be at index", "[index=" + i + "]", lineData);
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean isCorrectType = isOfExpectedType(splitDataLine[i], getExpectedValueType(i));
|
||||
|
||||
if(!isCorrectType) {
|
||||
reportBadDataLine("Data is not of correct type", splitDataLine[i], lineData);
|
||||
anyBadData = true;
|
||||
badDataValues[i] = true;
|
||||
}
|
||||
@ -177,7 +181,7 @@ public class FlatFileDataProcessor {
|
||||
}
|
||||
|
||||
|
||||
public boolean shouldNotBeEmpty(String data, int index) {
|
||||
public boolean shouldNotBeEmpty(@Nullable String data, int index) {
|
||||
if(getExpectedValueType(index) == ExpectedType.IGNORED) {
|
||||
return false;
|
||||
} else {
|
||||
@ -255,6 +259,7 @@ public class FlatFileDataProcessor {
|
||||
case 23: //Assumption: Used to be used for something, no longer used
|
||||
case 33: //Assumption: Used to be used for something, no longer used
|
||||
case HEALTHBAR:
|
||||
case LEGACY_LAST_LOGIN:
|
||||
return ExpectedType.IGNORED;
|
||||
case SKILLS_MINING:
|
||||
case SKILLS_REPAIR:
|
||||
@ -269,7 +274,6 @@ public class FlatFileDataProcessor {
|
||||
case SKILLS_TAMING:
|
||||
case SKILLS_FISHING:
|
||||
case SKILLS_ALCHEMY:
|
||||
case LAST_LOGIN:
|
||||
case COOLDOWN_BERSERK:
|
||||
case COOLDOWN_GIGA_DRILL_BREAKER:
|
||||
case COOLDOWN_TREE_FELLER:
|
||||
@ -297,6 +301,8 @@ public class FlatFileDataProcessor {
|
||||
return ExpectedType.FLOAT;
|
||||
case UUID_INDEX:
|
||||
return ExpectedType.UUID;
|
||||
case OVERHAUL_LAST_LOGIN:
|
||||
return ExpectedType.LONG;
|
||||
}
|
||||
|
||||
throw new IndexOutOfBoundsException();
|
||||
@ -320,7 +326,7 @@ public class FlatFileDataProcessor {
|
||||
//Fix our data if needed and prepare it to be saved
|
||||
|
||||
for(FlatFileDataContainer dataContainer : flatFileDataContainers) {
|
||||
String[] splitData = FlatFileSaveDataProcessor.getPreparedSaveDataLine(dataContainer);
|
||||
String[] splitData = FlatFileDataUtil.getPreparedSaveDataLine(dataContainer);
|
||||
|
||||
if(splitData == null)
|
||||
continue;
|
||||
|
@ -70,15 +70,16 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
public static final int SKILLS_FISHING = 34;
|
||||
public static final int EXP_FISHING = 35;
|
||||
public static final int COOLDOWN_BLAST_MINING = 36;
|
||||
public static final int LAST_LOGIN = 37;
|
||||
public static final int LEGACY_LAST_LOGIN = 37;
|
||||
public static final int HEALTHBAR = 38;
|
||||
public static final int SKILLS_ALCHEMY = 39;
|
||||
public static final int EXP_ALCHEMY = 40;
|
||||
public static final int UUID_INDEX = 41;
|
||||
public static final int SCOREBOARD_TIPS = 42;
|
||||
public static final int COOLDOWN_CHIMAERA_WING = 43;
|
||||
public static final int OVERHAUL_LAST_LOGIN = 44;
|
||||
|
||||
public static final int DATA_ENTRY_COUNT = COOLDOWN_CHIMAERA_WING + 1; //Update this everytime new data is added
|
||||
public static final int DATA_ENTRY_COUNT = OVERHAUL_LAST_LOGIN + 1; //Update this everytime new data is added
|
||||
|
||||
protected FlatFileDatabaseManager(@NotNull File usersFile, @NotNull Logger logger, long purgeTime, int startingLevel, boolean testing) {
|
||||
this.usersFile = usersFile;
|
||||
@ -666,6 +667,10 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
String line;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
if(line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find if the line contains the player we want.
|
||||
String[] rawSplitData = line.split(":");
|
||||
|
||||
@ -718,6 +723,10 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
String line;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
if(line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] character = line.split(":");
|
||||
|
||||
try {
|
||||
@ -1071,7 +1080,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
fileWriter = new FileWriter(usersFilePath);
|
||||
//Write data to file
|
||||
if(dbCommentDate != null)
|
||||
fileWriter.write(dbCommentDate);
|
||||
fileWriter.write(dbCommentDate + "\r\n");
|
||||
|
||||
fileWriter.write(dataProcessor.processDataForSave().toString());
|
||||
}
|
||||
@ -1200,9 +1209,9 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
try {
|
||||
lastLogin = Long.parseLong(character[LAST_LOGIN]);
|
||||
lastLogin = Long.parseLong(character[OVERHAUL_LAST_LOGIN]);
|
||||
} catch (Exception e) {
|
||||
lastLogin = System.currentTimeMillis();
|
||||
lastLogin = -1;
|
||||
}
|
||||
|
||||
return new PlayerProfile(character[USERNAME_INDEX], uuid, skills, skillsXp, skillsDATS, scoreboardTipsShown, uniquePlayerDataMap, lastLogin);
|
||||
|
@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.gmail.nossr50.database.FlatFileDatabaseManager.*;
|
||||
|
||||
public class FlatFileSaveDataProcessor {
|
||||
public class FlatFileDataUtil {
|
||||
|
||||
public static @Nullable String[] getPreparedSaveDataLine(@NotNull FlatFileDataContainer dataContainer) {
|
||||
if(dataContainer.getDataFlags() == null) {
|
||||
@ -64,6 +64,7 @@ public class FlatFileSaveDataProcessor {
|
||||
case 3: //Assumption: Used to be for something, no longer used
|
||||
case 23: //Assumption: Used to be used for something, no longer used
|
||||
case 33: //Assumption: Used to be used for something, no longer used
|
||||
case LEGACY_LAST_LOGIN:
|
||||
case HEALTHBAR:
|
||||
return "IGNORED";
|
||||
case SKILLS_MINING:
|
||||
@ -80,8 +81,8 @@ public class FlatFileSaveDataProcessor {
|
||||
case SKILLS_FISHING:
|
||||
case SKILLS_ALCHEMY:
|
||||
return String.valueOf(startingLevel);
|
||||
case LAST_LOGIN:
|
||||
return String.valueOf(System.currentTimeMillis() / 1000); //This is just to shorten the value
|
||||
case OVERHAUL_LAST_LOGIN:
|
||||
return String.valueOf(-1L);
|
||||
case COOLDOWN_BERSERK:
|
||||
case COOLDOWN_GIGA_DRILL_BREAKER:
|
||||
case COOLDOWN_TREE_FELLER:
|
@ -162,7 +162,7 @@ public class PlayerProfile {
|
||||
@Deprecated
|
||||
public @NotNull Long getLastLogin() {
|
||||
if(lastLogin == null)
|
||||
return System.currentTimeMillis();
|
||||
return -1L;
|
||||
else
|
||||
return lastLogin;
|
||||
}
|
||||
|
Reference in New Issue
Block a user