mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-02 12:35:27 +02:00
Refactoring code part 1 to prep for adding a bunch of unit tests
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
@@ -15,15 +14,13 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface DatabaseManager {
|
||||
// One month in milliseconds
|
||||
long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
|
||||
// During convertUsers, how often to output a status
|
||||
int progressInterval = 200;
|
||||
|
||||
/**
|
||||
* Purge users with 0 power level from the database.
|
||||
*/
|
||||
void purgePowerlessUsers();
|
||||
int purgePowerlessUsers();
|
||||
|
||||
/**
|
||||
* Purge users who haven't logged on in over a certain time frame from the database.
|
||||
@@ -76,6 +73,8 @@ public interface DatabaseManager {
|
||||
*/
|
||||
Map<PrimarySkillType, Integer> readRank(String playerName);
|
||||
|
||||
default void init() {};
|
||||
|
||||
/**
|
||||
* Add a new user to the database.
|
||||
*
|
||||
|
@@ -1,13 +1,16 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class DatabaseManagerFactory {
|
||||
private static Class<? extends DatabaseManager> customManager = null;
|
||||
|
||||
public static DatabaseManager getDatabaseManager() {
|
||||
public static DatabaseManager getDatabaseManager(@NotNull String userFilePath, @NotNull Logger logger, long purgeTime, int startingLevel) {
|
||||
if (customManager != null) {
|
||||
try {
|
||||
return createDefaultCustomDatabaseManager();
|
||||
@@ -20,10 +23,10 @@ public class DatabaseManagerFactory {
|
||||
mcMMO.p.debug("Failed to create custom database manager");
|
||||
e.printStackTrace();
|
||||
}
|
||||
mcMMO.p.debug("Falling back on " + (Config.getInstance().getUseMySQL() ? "SQL" : "Flatfile") + " database");
|
||||
mcMMO.p.debug("Falling back on " + (mcMMO.p.getGeneralConfig().getUseMySQL() ? "SQL" : "Flatfile") + " database");
|
||||
}
|
||||
|
||||
return Config.getInstance().getUseMySQL() ? new SQLDatabaseManager() : new FlatFileDatabaseManager();
|
||||
return mcMMO.p.getGeneralConfig().getUseMySQL() ? new SQLDatabaseManager() : new FlatFileDatabaseManager(userFilePath, logger, purgeTime, startingLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,11 +59,11 @@ public class DatabaseManagerFactory {
|
||||
return customManager;
|
||||
}
|
||||
|
||||
public static DatabaseManager createDatabaseManager(DatabaseType type) {
|
||||
public static @Nullable DatabaseManager createDatabaseManager(@NotNull DatabaseType type, @NotNull String userFilePath, @NotNull Logger logger, long purgeTime, int startingLevel) {
|
||||
switch (type) {
|
||||
case FLATFILE:
|
||||
mcMMO.p.getLogger().info("Using FlatFile Database");
|
||||
return new FlatFileDatabaseManager();
|
||||
return new FlatFileDatabaseManager(userFilePath, logger, purgeTime, startingLevel);
|
||||
|
||||
case SQL:
|
||||
mcMMO.p.getLogger().info("Using SQL Database");
|
||||
@@ -80,7 +83,7 @@ public class DatabaseManagerFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public static DatabaseManager createDefaultCustomDatabaseManager() throws Throwable {
|
||||
private static DatabaseManager createDefaultCustomDatabaseManager() throws Throwable {
|
||||
return customManager.getConstructor().newInstance();
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,13 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.player.UniqueDataType;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -19,14 +17,20 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
private final HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<>();
|
||||
private final List<PlayerStat> powerLevels = new ArrayList<>();
|
||||
public static final String IGNORED = "IGNORED";
|
||||
private final @NotNull HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<>();
|
||||
private final @NotNull List<PlayerStat> powerLevels = new ArrayList<>();
|
||||
private long lastUpdate = 0;
|
||||
private final @NotNull String usersFilePath;
|
||||
private final @NotNull Logger logger;
|
||||
private final long purgeTime;
|
||||
private final int startingLevel;
|
||||
|
||||
private final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
|
||||
private final File usersFile;
|
||||
private final @NotNull File usersFile;
|
||||
private static final Object fileWritingLock = new Object();
|
||||
|
||||
public static int USERNAME_INDEX = 0;
|
||||
@@ -72,20 +76,26 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
|
||||
public static int DATA_ENTRY_COUNT = COOLDOWN_CHIMAERA_WING + 1; //Update this everytime new data is added
|
||||
|
||||
protected FlatFileDatabaseManager() {
|
||||
usersFile = new File(mcMMO.getUsersFilePath());
|
||||
protected FlatFileDatabaseManager(@NotNull String usersFilePath, @NotNull Logger logger, long purgeTime, int startingLevel) {
|
||||
usersFile = new File(usersFilePath);
|
||||
this.usersFilePath = usersFilePath;
|
||||
this.logger = logger;
|
||||
this.purgeTime = purgeTime;
|
||||
this.startingLevel = startingLevel;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
checkStructure();
|
||||
updateLeaderboards();
|
||||
}
|
||||
|
||||
public void purgePowerlessUsers() {
|
||||
public int purgePowerlessUsers() {
|
||||
int purgedUsers = 0;
|
||||
|
||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||
logger.info("Purging powerless users...");
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
// This code is O(n) instead of O(n²)
|
||||
synchronized (fileWritingLock) {
|
||||
@@ -96,7 +106,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String[] character = line.split(":");
|
||||
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(character);
|
||||
Map<Skill, Integer> skills = getSkillMapFromLine(character);
|
||||
|
||||
boolean powerless = true;
|
||||
for (int skill : skills.values()) {
|
||||
@@ -120,7 +130,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
logger.severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e);
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
@@ -142,18 +152,18 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + purgedUsers + " users from the database.");
|
||||
logger.info("Purged " + purgedUsers + " users from the database.");
|
||||
return purgedUsers;
|
||||
}
|
||||
|
||||
public void purgeOldUsers() {
|
||||
int removedPlayers = 0;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
mcMMO.p.getLogger().info("Purging old users...");
|
||||
logger.info("Purging old users...");
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
// This code is O(n) instead of O(n²)
|
||||
synchronized (fileWritingLock) {
|
||||
@@ -179,7 +189,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
rewrite = true;
|
||||
}
|
||||
|
||||
if (currentTime - lastPlayed > PURGE_TIME) {
|
||||
if (currentTime - lastPlayed > purgeTime) {
|
||||
removedPlayers++;
|
||||
}
|
||||
else {
|
||||
@@ -200,7 +210,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
logger.severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e);
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
@@ -222,7 +232,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database.");
|
||||
logger.info("Purged " + removedPlayers + " users from the database.");
|
||||
}
|
||||
|
||||
public boolean removeUser(String playerName, UUID uuid) {
|
||||
@@ -231,7 +241,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
@@ -242,7 +251,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
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.
|
||||
if (!worked && line.split(":")[USERNAME_INDEX].equalsIgnoreCase(playerName)) {
|
||||
mcMMO.p.getLogger().info("User found, removing...");
|
||||
logger.info("User found, removing...");
|
||||
worked = true;
|
||||
continue; // Skip the player
|
||||
}
|
||||
@@ -254,7 +263,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
logger.severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e);
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
@@ -286,13 +295,12 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
//Not used in FlatFile
|
||||
}
|
||||
|
||||
public boolean saveUser(PlayerProfile profile) {
|
||||
public boolean saveUser(@NotNull PlayerProfile profile) {
|
||||
String playerName = profile.getPlayerName();
|
||||
UUID uuid = profile.getUniqueId();
|
||||
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
boolean corruptDataFound = false;
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
@@ -309,7 +317,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
if(!line.contains(":")) {
|
||||
|
||||
if(!corruptDataFound) {
|
||||
mcMMO.p.getLogger().severe("mcMMO found some unexpected or corrupted data in mcmmo.users and is removing it, it is possible some data has been lost.");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -318,12 +326,11 @@ 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 username
|
||||
if(splitData.length < USERNAME_INDEX) { //UUID have been in mcMMO DB for a very long time so any user without
|
||||
//Something is wrong if we don't have enough split data to have an entry for a username
|
||||
//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(!corruptDataFound) {
|
||||
mcMMO.p.getLogger().severe("mcMMO found some unexpected or corrupted data in mcmmo.users and is removing it, it is possible some data has been lost.");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -378,7 +385,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeUserToLine(PlayerProfile profile, String playerName, @Nullable UUID uuid, StringBuilder writer) {
|
||||
private void writeUserToLine(PlayerProfile profile, @NotNull String playerName, @Nullable UUID uuid, StringBuilder writer) {
|
||||
writer.append(playerName).append(":");
|
||||
writer.append(profile.getSkillLevel(PrimarySkillType.MINING)).append(":");
|
||||
writer.append(":");
|
||||
@@ -417,8 +424,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
writer.append(profile.getSkillXpLevel(PrimarySkillType.FISHING)).append(":");
|
||||
writer.append((int) profile.getAbilityDATS(SuperAbilityType.BLAST_MINING)).append(":");
|
||||
writer.append(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR).append(":");
|
||||
MobHealthbarType mobHealthbarType = profile.getMobHealthbarType();
|
||||
writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":");
|
||||
writer.append(IGNORED).append(":"); //mob health bar
|
||||
writer.append(profile.getSkillLevel(PrimarySkillType.ALCHEMY)).append(":");
|
||||
writer.append(profile.getSkillXpLevel(PrimarySkillType.ALCHEMY)).append(":");
|
||||
writer.append(uuid != null ? uuid.toString() : "NULL").append(":");
|
||||
@@ -430,7 +436,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
public @NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException {
|
||||
//Fix for a plugin that people are using that is throwing SQL errors
|
||||
if(skill != null && skill.isChildSkill()) {
|
||||
mcMMO.p.getLogger().severe("A plugin hooking into mcMMO is being naughty with our database commands, update all plugins that hook into mcMMO and contact their devs!");
|
||||
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!");
|
||||
}
|
||||
|
||||
@@ -465,26 +471,26 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
// Open the file to write the player
|
||||
out = new BufferedWriter(new FileWriter(mcMMO.getUsersFilePath(), true));
|
||||
out = new BufferedWriter(new FileWriter(usersFilePath, true));
|
||||
|
||||
String startingLevel = AdvancedConfig.getInstance().getStartingLevel() + ":";
|
||||
String startingLevelStr = startingLevel + ":";
|
||||
|
||||
// Add the player to the end
|
||||
out.append(playerName).append(":");
|
||||
out.append(startingLevel); // Mining
|
||||
out.append(startingLevelStr); // Mining
|
||||
out.append(":");
|
||||
out.append(":");
|
||||
out.append("0:"); // Xp
|
||||
out.append(startingLevel); // Woodcutting
|
||||
out.append(startingLevelStr); // Woodcutting
|
||||
out.append("0:"); // WoodCuttingXp
|
||||
out.append(startingLevel); // Repair
|
||||
out.append(startingLevel); // Unarmed
|
||||
out.append(startingLevel); // Herbalism
|
||||
out.append(startingLevel); // Excavation
|
||||
out.append(startingLevel); // Archery
|
||||
out.append(startingLevel); // Swords
|
||||
out.append(startingLevel); // Axes
|
||||
out.append(startingLevel); // Acrobatics
|
||||
out.append(startingLevelStr); // Repair
|
||||
out.append(startingLevelStr); // Unarmed
|
||||
out.append(startingLevelStr); // Herbalism
|
||||
out.append(startingLevelStr); // Excavation
|
||||
out.append(startingLevelStr); // Archery
|
||||
out.append(startingLevelStr); // Swords
|
||||
out.append(startingLevelStr); // Axes
|
||||
out.append(startingLevelStr); // Acrobatics
|
||||
out.append("0:"); // RepairXp
|
||||
out.append("0:"); // UnarmedXp
|
||||
out.append("0:"); // HerbalismXp
|
||||
@@ -494,7 +500,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.append("0:"); // AxesXp
|
||||
out.append("0:"); // AcrobaticsXp
|
||||
out.append(":");
|
||||
out.append(startingLevel); // Taming
|
||||
out.append(startingLevelStr); // Taming
|
||||
out.append("0:"); // TamingXp
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
@@ -504,12 +510,12 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.append("0:"); // DATS
|
||||
out.append("0:"); // DATS
|
||||
out.append(":");
|
||||
out.append(startingLevel); // Fishing
|
||||
out.append(startingLevelStr); // Fishing
|
||||
out.append("0:"); // FishingXp
|
||||
out.append("0:"); // Blast Mining
|
||||
out.append(String.valueOf(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)).append(":"); // LastLogin
|
||||
out.append(Config.getInstance().getMobHealthbarDefault().toString()).append(":"); // Mob Healthbar HUD
|
||||
out.append(startingLevel); // Alchemy
|
||||
out.append(IGNORED).append(":"); // Mob Healthbar HUD
|
||||
out.append(startingLevelStr); // Alchemy
|
||||
out.append("0:"); // AlchemyXp
|
||||
out.append(uuid != null ? uuid.toString() : "NULL").append(":"); // UUID
|
||||
out.append("0:"); // Scoreboard tips shown
|
||||
@@ -543,7 +549,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
|
||||
private @NotNull PlayerProfile loadPlayerByUUID(@NotNull UUID uuid, @Nullable String playerName) {
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
@@ -580,7 +585,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
|
||||
/* Check for nickname changes and update since we are here anyways */
|
||||
if (!rawSplitData[USERNAME_INDEX].equalsIgnoreCase(playerName)) {
|
||||
//mcMMO.p.getLogger().info("Name updated for player: " + rawSplitData[USERNAME_INDEX] + " => " + playerName);
|
||||
//logger.info("Name updated for player: " + rawSplitData[USERNAME_INDEX] + " => " + playerName);
|
||||
rawSplitData[USERNAME_INDEX] = playerName;
|
||||
}
|
||||
|
||||
@@ -610,7 +615,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
|
||||
private @NotNull PlayerProfile loadPlayerByName(@NotNull String playerName) {
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
@@ -661,7 +665,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
|
||||
public void convertUsers(DatabaseManager destination) {
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
int convertedUsers = 0;
|
||||
long startMillis = System.currentTimeMillis();
|
||||
|
||||
@@ -706,7 +709,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
int i = 0;
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
@@ -718,8 +720,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
String[] character = line.split(":");
|
||||
if (!worked && character[USERNAME_INDEX].equalsIgnoreCase(userName)) {
|
||||
if (character.length < 42) {
|
||||
mcMMO.p.getLogger().severe("Could not update UUID for " + userName + "!");
|
||||
mcMMO.p.getLogger().severe("Database entry is invalid.");
|
||||
logger.severe("Could not update UUID for " + userName + "!");
|
||||
logger.severe("Database entry is invalid.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -735,10 +737,10 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
logger.severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e);
|
||||
}
|
||||
finally {
|
||||
mcMMO.p.getLogger().info(i + " entries written while saving UUID for " + userName);
|
||||
logger.info(i + " entries written while saving UUID for " + userName);
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
@@ -764,7 +766,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
public boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs) {
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
int i = 0;
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
@@ -777,8 +778,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
String[] character = line.split(":");
|
||||
if (!fetchedUUIDs.isEmpty() && fetchedUUIDs.containsKey(character[USERNAME_INDEX])) {
|
||||
if (character.length < 42) {
|
||||
mcMMO.p.getLogger().severe("Could not update UUID for " + character[USERNAME_INDEX] + "!");
|
||||
mcMMO.p.getLogger().severe("Database entry is invalid.");
|
||||
logger.severe("Could not update UUID for " + character[USERNAME_INDEX] + "!");
|
||||
logger.severe("Database entry is invalid.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -794,10 +795,10 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
logger.severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e);
|
||||
}
|
||||
finally {
|
||||
mcMMO.p.getLogger().info(i + " entries written while saving UUID batch");
|
||||
logger.info(i + " entries written while saving UUID batch");
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
@@ -823,7 +824,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
public List<String> getStoredUsers() {
|
||||
ArrayList<String> users = new ArrayList<>();
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
@@ -862,7 +862,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
return;
|
||||
}
|
||||
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
lastUpdate = System.currentTimeMillis(); // Log when the last update was run
|
||||
powerLevels.clear(); // Clear old values from the power levels
|
||||
|
||||
@@ -894,7 +893,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
playerName = data[USERNAME_INDEX];
|
||||
int powerLevel = 0;
|
||||
|
||||
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(data);
|
||||
Map<Skill, Integer> skills = getSkillMapFromLine(data);
|
||||
|
||||
powerLevel += putStat(acrobatics, playerName, skills.get(PrimarySkillType.ACROBATICS));
|
||||
powerLevel += putStat(alchemy, playerName, skills.get(PrimarySkillType.ALCHEMY));
|
||||
@@ -914,7 +913,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e.toString());
|
||||
logger.severe("Exception while reading " + usersFilePath + " during user " + playerName + " (Are you sure you formatted it correctly?) " + e);
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
@@ -969,7 +968,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
if (usersFile.exists()) {
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
@@ -996,14 +994,14 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
//Not enough data found to be considered a user reliably (NOTE: not foolproof)
|
||||
if(rawSplitData.length < (UUID_INDEX + 1)) {
|
||||
if(!corruptDataFound) {
|
||||
mcMMO.p.getLogger().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.");
|
||||
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;
|
||||
}
|
||||
|
||||
if(rawSplitData.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
|
||||
&& rawSplitData[0] != null && !rawSplitData[0].isEmpty()) {
|
||||
if(rawSplitData[0].length() <= 16 && rawSplitData[0].length() >= 3) {
|
||||
mcMMO.p.getLogger().severe("Not enough data found to recover corrupted player data for user: "+rawSplitData[0]);
|
||||
logger.severe("Not enough data found to recover corrupted player data for user: "+rawSplitData[0]);
|
||||
}
|
||||
}
|
||||
//This user may have had a name so declare it
|
||||
@@ -1016,7 +1014,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
//TODO: Check if the commented out code was even necessary
|
||||
rawSplitData[USERNAME_INDEX] = "_INVALID_OLD_USERNAME_'";
|
||||
if (rawSplitData.length < UUID_INDEX + 1 || rawSplitData[UUID_INDEX].equals("NULL")) {
|
||||
mcMMO.p.getLogger().severe("Fixing duplicate player names found in mcmmo.users");
|
||||
logger.severe("Fixing duplicate player names found in mcmmo.users");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1026,8 +1024,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
&& (!rawSplitData[UUID_INDEX].isEmpty()
|
||||
&& !rawSplitData[UUID_INDEX].equals("NULL") && !players.add(rawSplitData[UUID_INDEX]))) {
|
||||
|
||||
mcMMO.p.getLogger().severe("Removing duplicate player data from mcmmo.users");
|
||||
mcMMO.p.getLogger().info("Duplicate Data: "+line);
|
||||
logger.severe("Removing duplicate player data from mcmmo.users");
|
||||
logger.info("Duplicate Data: "+line);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1049,7 +1047,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
logger.severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e);
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
@@ -1072,7 +1070,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
if(corruptDataFound)
|
||||
mcMMO.p.getLogger().info("Corrupt data was found and removed, everything should be working fine. It is possible some player data was lost.");
|
||||
logger.info("Corrupt data was found and removed, everything should be working fine. It is possible some player data was lost.");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1080,8 +1078,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
usersFile.getParentFile().mkdir();
|
||||
|
||||
try {
|
||||
mcMMO.p.debug("Creating mcmmo.users file...");
|
||||
new File(mcMMO.getUsersFilePath()).createNewFile();
|
||||
logger.info("Creating mcmmo.users file...");
|
||||
new File(usersFilePath).createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -1119,11 +1117,10 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
private PlayerProfile loadFromLine(@NotNull String[] character) {
|
||||
Map<PrimarySkillType, Integer> skills = getSkillMapFromLine(character); // Skill levels
|
||||
Map<PrimarySkillType, Float> skillsXp = new EnumMap<>(PrimarySkillType.class); // Skill & XP
|
||||
Map<Skill, Integer> skills = getSkillMapFromLine(character); // Skill levels
|
||||
Map<Skill, Float> skillsXp = new HashMap<>(); // Skill & XP
|
||||
Map<SuperAbilityType, Integer> skillsDATS = new EnumMap<>(SuperAbilityType.class); // Ability & Cooldown
|
||||
Map<UniqueDataType, Integer> uniquePlayerDataMap = new EnumMap<>(UniqueDataType.class);
|
||||
MobHealthbarType mobHealthbarType;
|
||||
int scoreboardTipsShown;
|
||||
|
||||
String username = character[USERNAME_INDEX];
|
||||
@@ -1155,12 +1152,12 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
// Acrobatics - Unused
|
||||
tryLoadSkillCooldownFromRawData(skillsDATS, character, SuperAbilityType.BLAST_MINING, COOLDOWN_BLAST_MINING, username);
|
||||
|
||||
try {
|
||||
mobHealthbarType = MobHealthbarType.valueOf(character[HEALTHBAR]);
|
||||
}
|
||||
catch (Exception e) {
|
||||
mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
|
||||
}
|
||||
// try {
|
||||
// mobHealthbarType = MobHealthbarType.valueOf(character[HEALTHBAR]);
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
|
||||
// }
|
||||
|
||||
UUID uuid;
|
||||
try {
|
||||
@@ -1184,44 +1181,45 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
uniquePlayerDataMap.put(UniqueDataType.CHIMAERA_WING_DATS, 0);
|
||||
}
|
||||
|
||||
return new PlayerProfile(character[USERNAME_INDEX], uuid, skills, skillsXp, skillsDATS, mobHealthbarType, scoreboardTipsShown, uniquePlayerDataMap);
|
||||
return new PlayerProfile(character[USERNAME_INDEX], uuid, skills, skillsXp, skillsDATS, null, scoreboardTipsShown, uniquePlayerDataMap);
|
||||
}
|
||||
|
||||
private void tryLoadSkillCooldownFromRawData(@NotNull Map<SuperAbilityType, Integer> cooldownMap, @NotNull String[] character, @NotNull SuperAbilityType superAbilityType, int cooldownSuperBreaker, @NotNull String userName) {
|
||||
try {
|
||||
cooldownMap.put(superAbilityType, Integer.valueOf(character[cooldownSuperBreaker]));
|
||||
} catch (NumberFormatException e) {
|
||||
mcMMO.p.getLogger().severe("Data corruption when trying to load the value for skill "+superAbilityType.toString()+" for player named " + userName+ " setting value to zero");
|
||||
logger.severe("Data corruption when trying to load the value for skill "+superAbilityType+" for player named " + userName+ " setting value to zero");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void tryLoadSkillFloatValuesFromRawData(@NotNull Map<PrimarySkillType, Float> skillMap, @NotNull String[] character, @NotNull PrimarySkillType primarySkillType, int index, @NotNull String userName) {
|
||||
private void tryLoadSkillFloatValuesFromRawData(@NotNull Map<Skill, Float> skillMap, @NotNull String[] character, @NotNull Skill primarySkillType, int index, @NotNull String userName) {
|
||||
try {
|
||||
float valueFromString = Integer.parseInt(character[index]);
|
||||
skillMap.put(primarySkillType, valueFromString);
|
||||
} catch (NumberFormatException e) {
|
||||
skillMap.put(primarySkillType, 0F);
|
||||
mcMMO.p.getLogger().severe("Data corruption when trying to load the value for skill "+primarySkillType.toString()+" for player named " + userName+ " setting value to zero");
|
||||
logger.severe("Data corruption when trying to load the value for skill "+primarySkillType+" for player named " + userName+ " setting value to zero");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void tryLoadSkillIntValuesFromRawData(@NotNull Map<PrimarySkillType, Integer> skillMap, @NotNull String[] character, @NotNull PrimarySkillType primarySkillType, int index, @NotNull String userName) {
|
||||
private void tryLoadSkillIntValuesFromRawData(@NotNull Map<Skill, Integer> skillMap, @NotNull String[] character, @NotNull Skill skill, int index, @NotNull String userName) {
|
||||
try {
|
||||
int valueFromString = Integer.parseInt(character[index]);
|
||||
skillMap.put(primarySkillType, valueFromString);
|
||||
skillMap.put(skill, valueFromString);
|
||||
} catch (NumberFormatException e) {
|
||||
skillMap.put(primarySkillType, 0);
|
||||
mcMMO.p.getLogger().severe("Data corruption when trying to load the value for skill "+primarySkillType.toString()+" for player named " + userName+ " setting value to zero");
|
||||
skillMap.put(skill, 0);
|
||||
logger.severe("Data corruption when trying to load the value for skill "+skill+" for player named " + userName+ " setting value to zero");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private @NotNull Map<PrimarySkillType, Integer> getSkillMapFromLine(@NotNull String[] character) {
|
||||
Map<PrimarySkillType, Integer> skills = new EnumMap<>(PrimarySkillType.class); // Skill & Level
|
||||
private @NotNull Map<Skill, Integer> getSkillMapFromLine(@NotNull String[] character) {
|
||||
HashMap<Skill, Integer> skills = new HashMap<>(); // Skill & Level
|
||||
String username = character[USERNAME_INDEX];
|
||||
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.ACROBATICS, SKILLS_ACROBATICS, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.TAMING, SKILLS_TAMING, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.MINING, SKILLS_MINING, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.REPAIR, SKILLS_REPAIR, username);
|
||||
@@ -1232,7 +1230,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.ARCHERY, SKILLS_ARCHERY, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.SWORDS, SKILLS_SWORDS, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.AXES, SKILLS_AXES, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.ACROBATICS, SKILLS_ACROBATICS, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.FISHING, SKILLS_FISHING, username);
|
||||
tryLoadSkillIntValuesFromRawData(skills, character, PrimarySkillType.ALCHEMY, SKILLS_ALCHEMY, username);
|
||||
|
||||
@@ -1243,93 +1240,10 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
return DatabaseType.FLATFILE;
|
||||
}
|
||||
|
||||
public File getUsersFile() {
|
||||
return usersFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() { }
|
||||
|
||||
private int getSkillIndex(PrimarySkillType skill) {
|
||||
switch (skill) {
|
||||
case ACROBATICS:
|
||||
return SKILLS_ACROBATICS;
|
||||
case ALCHEMY:
|
||||
return SKILLS_ALCHEMY;
|
||||
case ARCHERY:
|
||||
return SKILLS_ARCHERY;
|
||||
case AXES:
|
||||
return SKILLS_AXES;
|
||||
case EXCAVATION:
|
||||
return SKILLS_EXCAVATION;
|
||||
case FISHING:
|
||||
return SKILLS_FISHING;
|
||||
case HERBALISM:
|
||||
return SKILLS_HERBALISM;
|
||||
case MINING:
|
||||
return SKILLS_MINING;
|
||||
case REPAIR:
|
||||
return SKILLS_REPAIR;
|
||||
case SWORDS:
|
||||
return SKILLS_SWORDS;
|
||||
case TAMING:
|
||||
return SKILLS_TAMING;
|
||||
case UNARMED:
|
||||
return SKILLS_UNARMED;
|
||||
case WOODCUTTING:
|
||||
return SKILLS_WOODCUTTING;
|
||||
default:
|
||||
throw new RuntimeException("Primary Skills only");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void resetMobHealthSettings() {
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
// Remove empty lines from the file
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String[] character = line.split(":");
|
||||
|
||||
character[HEALTHBAR] = Config.getInstance().getMobHealthbarDefault().toString();
|
||||
|
||||
line = org.apache.commons.lang.StringUtils.join(character, ":") + ":";
|
||||
|
||||
writer.append(line).append("\r\n");
|
||||
}
|
||||
|
||||
// Write the new file
|
||||
out = new FileWriter(usersFilePath);
|
||||
out.write(writer.toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
@@ -11,6 +9,7 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.player.UniqueDataType;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.interfaces.Skill;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
@@ -30,7 +29,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
public static final String MOBHEALTHBAR_VARCHAR = "VARCHAR(50)";
|
||||
public static final String UUID_VARCHAR = "VARCHAR(36)";
|
||||
public static final String USER_VARCHAR = "VARCHAR(40)";
|
||||
private final String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
private final String tablePrefix = mcMMO.p.getGeneralConfig().getMySQLTablePrefix();
|
||||
|
||||
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
|
||||
|
||||
@@ -45,10 +44,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
private final String CHARSET_SQL = "utf8mb4"; //This is compliant with UTF-8 while "utf8" is not, confusing but this is how it is.
|
||||
|
||||
protected SQLDatabaseManager() {
|
||||
String connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName()
|
||||
+ ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName();
|
||||
String connectionString = "jdbc:mysql://" + mcMMO.p.getGeneralConfig().getMySQLServerName()
|
||||
+ ":" + mcMMO.p.getGeneralConfig().getMySQLServerPort() + "/" + mcMMO.p.getGeneralConfig().getMySQLDatabaseName();
|
||||
|
||||
if(Config.getInstance().getMySQLSSL())
|
||||
if(mcMMO.p.getGeneralConfig().getMySQLSSL())
|
||||
connectionString +=
|
||||
"?verifyServerCertificate=false"+
|
||||
"&useSSL=true"+
|
||||
@@ -67,16 +66,15 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
//throw e; // aborts onEnable() Riking if you want to do this, fully implement it.
|
||||
}
|
||||
|
||||
debug = Config.getInstance().getMySQLDebug();
|
||||
|
||||
debug = mcMMO.p.getGeneralConfig().getMySQLDebug();
|
||||
|
||||
PoolProperties poolProperties = new PoolProperties();
|
||||
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
poolProperties.setUrl(connectionString);
|
||||
poolProperties.setUsername(Config.getInstance().getMySQLUserName());
|
||||
poolProperties.setPassword(Config.getInstance().getMySQLUserPassword());
|
||||
poolProperties.setMaxIdle(Config.getInstance().getMySQLMaxPoolSize(PoolIdentifier.MISC));
|
||||
poolProperties.setMaxActive(Config.getInstance().getMySQLMaxConnections(PoolIdentifier.MISC));
|
||||
poolProperties.setUsername(mcMMO.p.getGeneralConfig().getMySQLUserName());
|
||||
poolProperties.setPassword(mcMMO.p.getGeneralConfig().getMySQLUserPassword());
|
||||
poolProperties.setMaxIdle(mcMMO.p.getGeneralConfig().getMySQLMaxPoolSize(PoolIdentifier.MISC));
|
||||
poolProperties.setMaxActive(mcMMO.p.getGeneralConfig().getMySQLMaxConnections(PoolIdentifier.MISC));
|
||||
poolProperties.setInitialSize(0);
|
||||
poolProperties.setMaxWait(-1);
|
||||
poolProperties.setRemoveAbandoned(true);
|
||||
@@ -88,11 +86,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
poolProperties = new PoolProperties();
|
||||
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
poolProperties.setUrl(connectionString);
|
||||
poolProperties.setUsername(Config.getInstance().getMySQLUserName());
|
||||
poolProperties.setPassword(Config.getInstance().getMySQLUserPassword());
|
||||
poolProperties.setUsername(mcMMO.p.getGeneralConfig().getMySQLUserName());
|
||||
poolProperties.setPassword(mcMMO.p.getGeneralConfig().getMySQLUserPassword());
|
||||
poolProperties.setInitialSize(0);
|
||||
poolProperties.setMaxIdle(Config.getInstance().getMySQLMaxPoolSize(PoolIdentifier.SAVE));
|
||||
poolProperties.setMaxActive(Config.getInstance().getMySQLMaxConnections(PoolIdentifier.SAVE));
|
||||
poolProperties.setMaxIdle(mcMMO.p.getGeneralConfig().getMySQLMaxPoolSize(PoolIdentifier.SAVE));
|
||||
poolProperties.setMaxActive(mcMMO.p.getGeneralConfig().getMySQLMaxConnections(PoolIdentifier.SAVE));
|
||||
poolProperties.setMaxWait(-1);
|
||||
poolProperties.setRemoveAbandoned(true);
|
||||
poolProperties.setRemoveAbandonedTimeout(60);
|
||||
@@ -103,11 +101,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
poolProperties = new PoolProperties();
|
||||
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
poolProperties.setUrl(connectionString);
|
||||
poolProperties.setUsername(Config.getInstance().getMySQLUserName());
|
||||
poolProperties.setPassword(Config.getInstance().getMySQLUserPassword());
|
||||
poolProperties.setUsername(mcMMO.p.getGeneralConfig().getMySQLUserName());
|
||||
poolProperties.setPassword(mcMMO.p.getGeneralConfig().getMySQLUserPassword());
|
||||
poolProperties.setInitialSize(0);
|
||||
poolProperties.setMaxIdle(Config.getInstance().getMySQLMaxPoolSize(PoolIdentifier.LOAD));
|
||||
poolProperties.setMaxActive(Config.getInstance().getMySQLMaxConnections(PoolIdentifier.LOAD));
|
||||
poolProperties.setMaxIdle(mcMMO.p.getGeneralConfig().getMySQLMaxPoolSize(PoolIdentifier.LOAD));
|
||||
poolProperties.setMaxActive(mcMMO.p.getGeneralConfig().getMySQLMaxConnections(PoolIdentifier.LOAD));
|
||||
poolProperties.setMaxWait(-1);
|
||||
poolProperties.setRemoveAbandoned(true);
|
||||
poolProperties.setRemoveAbandonedTimeout(60);
|
||||
@@ -115,11 +113,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
poolProperties.setValidationQuery("SELECT 1");
|
||||
poolProperties.setValidationInterval(30000);
|
||||
loadPool = new DataSource(poolProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
checkStructure();
|
||||
}
|
||||
|
||||
public void purgePowerlessUsers() {
|
||||
public int purgePowerlessUsers() {
|
||||
massUpdateLock.lock();
|
||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||
|
||||
@@ -152,11 +153,12 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
||||
return purged;
|
||||
}
|
||||
|
||||
public void purgeOldUsers() {
|
||||
massUpdateLock.lock();
|
||||
mcMMO.p.getLogger().info("Purging inactive users older than " + (PURGE_TIME / 2630000000L) + " months...");
|
||||
mcMMO.p.getLogger().info("Purging inactive users older than " + (mcMMO.p.getPurgeTime() / 2630000000L) + " months...");
|
||||
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
@@ -171,7 +173,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
|
||||
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
|
||||
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
|
||||
"WHERE ((UNIX_TIMESTAMP() - lastlogin) > " + PURGE_TIME + ")");
|
||||
"WHERE ((UNIX_TIMESTAMP() - lastlogin) > " + mcMMO.p.getPurgeTime() + ")");
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
printErrors(ex);
|
||||
@@ -331,7 +333,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ?, scoreboardtips = ? WHERE user_id = ?");
|
||||
statement.setString(1, profile.getMobHealthbarType() == null ? Config.getInstance().getMobHealthbarDefault().name() : profile.getMobHealthbarType().name());
|
||||
statement.setString(1, profile.getMobHealthbarType() == null ? mcMMO.p.getGeneralConfig().getMobHealthbarDefault().name() : profile.getMobHealthbarType().name());
|
||||
statement.setInt(2, profile.getScoreboardTipsShown());
|
||||
statement.setInt(3, id);
|
||||
success = (statement.executeUpdate() != 0);
|
||||
@@ -818,7 +820,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
statement = connection.prepareStatement("SELECT table_name FROM INFORMATION_SCHEMA.TABLES"
|
||||
+ " WHERE table_schema = ?"
|
||||
+ " AND table_name = ?");
|
||||
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||
statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
||||
statement.setString(2, tablePrefix + "users");
|
||||
resultSet = statement.executeQuery();
|
||||
if (!resultSet.next()) {
|
||||
@@ -834,21 +836,21 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
tryClose(createStatement);
|
||||
}
|
||||
tryClose(resultSet);
|
||||
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||
statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
||||
statement.setString(2, tablePrefix + "huds");
|
||||
resultSet = statement.executeQuery();
|
||||
if (!resultSet.next()) {
|
||||
createStatement = connection.createStatement();
|
||||
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "huds` ("
|
||||
+ "`user_id` int(10) unsigned NOT NULL,"
|
||||
+ "`mobhealthbar` varchar(50) NOT NULL DEFAULT '" + Config.getInstance().getMobHealthbarDefault() + "',"
|
||||
+ "`mobhealthbar` varchar(50) NOT NULL DEFAULT '" + mcMMO.p.getGeneralConfig().getMobHealthbarDefault() + "',"
|
||||
+ "`scoreboardtips` int(10) NOT NULL DEFAULT '0',"
|
||||
+ "PRIMARY KEY (`user_id`)) "
|
||||
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
|
||||
tryClose(createStatement);
|
||||
}
|
||||
tryClose(resultSet);
|
||||
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||
statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
||||
statement.setString(2, tablePrefix + "cooldowns");
|
||||
resultSet = statement.executeQuery();
|
||||
if (!resultSet.next()) {
|
||||
@@ -873,12 +875,12 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
tryClose(createStatement);
|
||||
}
|
||||
tryClose(resultSet);
|
||||
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||
statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
||||
statement.setString(2, tablePrefix + "skills");
|
||||
resultSet = statement.executeQuery();
|
||||
if (!resultSet.next()) {
|
||||
String startingLevel = "'" + AdvancedConfig.getInstance().getStartingLevel() + "'";
|
||||
String totalLevel = "'" + (AdvancedConfig.getInstance().getStartingLevel() * (PrimarySkillType.values().length - PrimarySkillType.CHILD_SKILLS.size())) + "'";
|
||||
String startingLevel = "'" + mcMMO.p.getAdvancedConfig().getStartingLevel() + "'";
|
||||
String totalLevel = "'" + (mcMMO.p.getAdvancedConfig().getStartingLevel() * (PrimarySkillType.values().length - PrimarySkillType.CHILD_SKILLS.size())) + "'";
|
||||
createStatement = connection.createStatement();
|
||||
createStatement.executeUpdate("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "skills` ("
|
||||
+ "`user_id` int(10) unsigned NOT NULL,"
|
||||
@@ -901,7 +903,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
tryClose(createStatement);
|
||||
}
|
||||
tryClose(resultSet);
|
||||
statement.setString(1, Config.getInstance().getMySQLDatabaseName());
|
||||
statement.setString(1, mcMMO.p.getGeneralConfig().getMySQLDatabaseName());
|
||||
statement.setString(2, tablePrefix + "experience");
|
||||
resultSet = statement.executeQuery();
|
||||
if (!resultSet.next()) {
|
||||
@@ -932,9 +934,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
checkDatabaseStructure(connection, updateType);
|
||||
}
|
||||
|
||||
if (Config.getInstance().getTruncateSkills()) {
|
||||
if (mcMMO.p.getGeneralConfig().getTruncateSkills()) {
|
||||
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) {
|
||||
int cap = Config.getInstance().getLevelCap(skill);
|
||||
int cap = mcMMO.p.getGeneralConfig().getLevelCap(skill);
|
||||
if (cap != Integer.MAX_VALUE) {
|
||||
statement = connection.prepareStatement("UPDATE `" + tablePrefix + "skills` SET `" + skill.name().toLowerCase(Locale.ENGLISH) + "` = " + cap + " WHERE `" + skill.name().toLowerCase(Locale.ENGLISH) + "` > " + cap);
|
||||
statement.executeUpdate();
|
||||
@@ -1083,7 +1085,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
statement = connection.prepareStatement("INSERT IGNORE INTO " + tablePrefix + "huds (user_id, mobhealthbar, scoreboardtips) VALUES (?, ?, ?)");
|
||||
statement.setInt(1, id);
|
||||
statement.setString(2, Config.getInstance().getMobHealthbarDefault().name());
|
||||
statement.setString(2, mcMMO.p.getGeneralConfig().getMobHealthbarDefault().name());
|
||||
statement.setInt(3, 0);
|
||||
statement.execute();
|
||||
statement.close();
|
||||
@@ -1097,8 +1099,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
private PlayerProfile loadFromResult(String playerName, ResultSet result) throws SQLException {
|
||||
Map<PrimarySkillType, Integer> skills = new EnumMap<>(PrimarySkillType.class); // Skill & Level
|
||||
Map<PrimarySkillType, Float> skillsXp = new EnumMap<>(PrimarySkillType.class); // Skill & XP
|
||||
Map<Skill, Integer> skills = new HashMap<>(); // Skill & Level
|
||||
Map<Skill, Float> skillsXp = new HashMap<>(); // Skill & XP
|
||||
Map<SuperAbilityType, Integer> skillsDATS = new EnumMap<>(SuperAbilityType.class); // Ability & Cooldown
|
||||
Map<UniqueDataType, Integer> uniqueData = new EnumMap<>(UniqueDataType.class); //Chimaera wing cooldown and other misc info
|
||||
MobHealthbarType mobHealthbarType;
|
||||
@@ -1158,7 +1160,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
mobHealthbarType = MobHealthbarType.valueOf(result.getString(OFFSET_OTHER + 1));
|
||||
}
|
||||
catch (Exception e) {
|
||||
mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
|
||||
mobHealthbarType = mcMMO.p.getGeneralConfig().getMobHealthbarDefault();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -1270,7 +1272,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for mob healthbars...");
|
||||
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` ADD `mobhealthbar` varchar(50) NOT NULL DEFAULT '" + Config.getInstance().getMobHealthbarDefault() + "'");
|
||||
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` ADD `mobhealthbar` varchar(50) NOT NULL DEFAULT '" + mcMMO.p.getGeneralConfig().getMobHealthbarDefault() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1579,7 +1581,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
try {
|
||||
connection = getConnection(PoolIdentifier.MISC);
|
||||
statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ?");
|
||||
statement.setString(1, Config.getInstance().getMobHealthbarDefault().toString());
|
||||
statement.setString(1, mcMMO.p.getGeneralConfig().getMobHealthbarDefault().toString());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
|
Reference in New Issue
Block a user