Some refactoring of FlatFileDatabaseManager

This commit is contained in:
nossr50 2021-03-11 12:02:21 -08:00
parent 72116d809b
commit 7755875dbf
3 changed files with 8 additions and 9 deletions

View File

@ -1,7 +1,7 @@
package com.gmail.nossr50.commands; package com.gmail.nossr50.commands;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.FlatfileDatabaseManager; import com.gmail.nossr50.database.FlatFileDatabaseManager;
import com.gmail.nossr50.database.SQLDatabaseManager; import com.gmail.nossr50.database.SQLDatabaseManager;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
@ -27,8 +27,8 @@ public class MHDCommand implements TabExecutor {
sender.sendMessage("Mob health reset"); sender.sendMessage("Mob health reset");
return true; return true;
} }
if (mcMMO.getDatabaseManager() instanceof FlatfileDatabaseManager) { if (mcMMO.getDatabaseManager() instanceof FlatFileDatabaseManager) {
FlatfileDatabaseManager m = (FlatfileDatabaseManager) mcMMO.getDatabaseManager(); FlatFileDatabaseManager m = (FlatFileDatabaseManager) mcMMO.getDatabaseManager();
m.resetMobHealthSettings(); m.resetMobHealthSettings();
for (McMMOPlayer player : UserManager.getPlayers()) { for (McMMOPlayer player : UserManager.getPlayers()) {
player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault()); player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault());

View File

@ -23,7 +23,7 @@ public class DatabaseManagerFactory {
mcMMO.p.debug("Falling back on " + (Config.getInstance().getUseMySQL() ? "SQL" : "Flatfile") + " database"); mcMMO.p.debug("Falling back on " + (Config.getInstance().getUseMySQL() ? "SQL" : "Flatfile") + " database");
} }
return Config.getInstance().getUseMySQL() ? new SQLDatabaseManager() : new FlatfileDatabaseManager(); return Config.getInstance().getUseMySQL() ? new SQLDatabaseManager() : new FlatFileDatabaseManager();
} }
/** /**
@ -60,7 +60,7 @@ public class DatabaseManagerFactory {
switch (type) { switch (type) {
case FLATFILE: case FLATFILE:
mcMMO.p.getLogger().info("Using FlatFile Database"); mcMMO.p.getLogger().info("Using FlatFile Database");
return new FlatfileDatabaseManager(); return new FlatFileDatabaseManager();
case SQL: case SQL:
mcMMO.p.getLogger().info("Using SQL Database"); mcMMO.p.getLogger().info("Using SQL Database");

View File

@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
public final class FlatfileDatabaseManager implements DatabaseManager { public final class FlatFileDatabaseManager implements DatabaseManager {
private final HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<>(); private final HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<>();
private final List<PlayerStat> powerLevels = new ArrayList<>(); private final List<PlayerStat> powerLevels = new ArrayList<>();
private long lastUpdate = 0; private long lastUpdate = 0;
@ -74,7 +74,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
public static int DATA_ENTRY_COUNT = COOLDOWN_CHIMAERA_WING + 1; //Update this everytime new data is added public static int DATA_ENTRY_COUNT = COOLDOWN_CHIMAERA_WING + 1; //Update this everytime new data is added
protected FlatfileDatabaseManager() { protected FlatFileDatabaseManager() {
usersFile = new File(mcMMO.getUsersFilePath()); usersFile = new File(mcMMO.getUsersFilePath());
checkStructure(); checkStructure();
updateLeaderboards(); updateLeaderboards();
@ -339,8 +339,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
/* /*
* If we couldn't find the user in the DB we need to add him * If we couldn't find the user in the DB we need to add him
*/ */
if(!wroteUser) if(!wroteUser) {
{
writeUserToLine(profile, playerName, uuid, writer); writeUserToLine(profile, playerName, uuid, writer);
} }