mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-15 03:54:43 +02:00
Merge branch 'master' of github.com:mcMMO-Dev/mcMMO into tridentsxbows
This commit is contained in:
@ -12,19 +12,19 @@ import java.util.UUID;
|
||||
|
||||
public interface DatabaseManager {
|
||||
// One month in milliseconds
|
||||
public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
|
||||
long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
|
||||
// During convertUsers, how often to output a status
|
||||
public final int progressInterval = 200;
|
||||
int progressInterval = 200;
|
||||
|
||||
/**
|
||||
* Purge users with 0 power level from the database.
|
||||
*/
|
||||
public void purgePowerlessUsers();
|
||||
void purgePowerlessUsers();
|
||||
|
||||
/**
|
||||
* Purge users who haven't logged on in over a certain time frame from the database.
|
||||
*/
|
||||
public void purgeOldUsers();
|
||||
void purgeOldUsers();
|
||||
|
||||
/**
|
||||
* Remove a user from the database.
|
||||
@ -33,14 +33,14 @@ public interface DatabaseManager {
|
||||
* @param uuid player UUID, can be null
|
||||
* @return true if the user was successfully removed, false otherwise
|
||||
*/
|
||||
public boolean removeUser(String playerName, UUID uuid);
|
||||
boolean removeUser(String playerName, UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes any cache used for faster lookups
|
||||
* Currently only used for SQL
|
||||
* @param uuid target UUID to cleanup
|
||||
*/
|
||||
public void cleanupUser(UUID uuid);
|
||||
void cleanupUser(UUID uuid);
|
||||
|
||||
/**
|
||||
* Save a user to the database.
|
||||
@ -48,7 +48,7 @@ public interface DatabaseManager {
|
||||
* @param profile The profile of the player to save
|
||||
* @return true if successful, false on failure
|
||||
*/
|
||||
public boolean saveUser(PlayerProfile profile);
|
||||
boolean saveUser(PlayerProfile profile);
|
||||
|
||||
/**
|
||||
* Retrieve leaderboard info.
|
||||
@ -58,7 +58,7 @@ public interface DatabaseManager {
|
||||
* @param statsPerPage The number of stats per page
|
||||
* @return the requested leaderboard information
|
||||
*/
|
||||
public List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage);
|
||||
List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage);
|
||||
|
||||
/**
|
||||
* Retrieve rank info into a HashMap from PrimarySkillType to the rank.
|
||||
@ -69,7 +69,7 @@ public interface DatabaseManager {
|
||||
* @param playerName The name of the user to retrieve the rankings for
|
||||
* @return the requested rank information
|
||||
*/
|
||||
public Map<PrimarySkillType, Integer> readRank(String playerName);
|
||||
Map<PrimarySkillType, Integer> readRank(String playerName);
|
||||
|
||||
/**
|
||||
* Add a new user to the database.
|
||||
@ -77,7 +77,7 @@ public interface DatabaseManager {
|
||||
* @param playerName The name of the player to be added to the database
|
||||
* @param uuid The uuid of the player to be added to the database
|
||||
*/
|
||||
public void newUser(String playerName, UUID uuid);
|
||||
void newUser(String playerName, UUID uuid);
|
||||
|
||||
/**
|
||||
* Load a player from the database.
|
||||
@ -91,7 +91,7 @@ public interface DatabaseManager {
|
||||
* and createNew is false
|
||||
*/
|
||||
@Deprecated
|
||||
public PlayerProfile loadPlayerProfile(String playerName, boolean createNew);
|
||||
PlayerProfile loadPlayerProfile(String playerName, boolean createNew);
|
||||
|
||||
/**
|
||||
* Load a player from the database.
|
||||
@ -99,7 +99,7 @@ public interface DatabaseManager {
|
||||
* @param uuid The uuid of the player to load from the database
|
||||
* @return The player's data, or an unloaded PlayerProfile if not found
|
||||
*/
|
||||
public PlayerProfile loadPlayerProfile(UUID uuid);
|
||||
PlayerProfile loadPlayerProfile(UUID uuid);
|
||||
|
||||
/**
|
||||
* Load a player from the database. Attempt to use uuid, fall back on playername
|
||||
@ -111,14 +111,14 @@ public interface DatabaseManager {
|
||||
* @return The player's data, or an unloaded PlayerProfile if not found
|
||||
* and createNew is false
|
||||
*/
|
||||
public PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean createNew);
|
||||
PlayerProfile loadPlayerProfile(String playerName, UUID uuid, boolean createNew);
|
||||
|
||||
/**
|
||||
* Get all users currently stored in the database.
|
||||
*
|
||||
* @return list of playernames
|
||||
*/
|
||||
public List<String> getStoredUsers();
|
||||
List<String> getStoredUsers();
|
||||
|
||||
/**
|
||||
* Convert all users from this database to the provided database using
|
||||
@ -126,21 +126,21 @@ public interface DatabaseManager {
|
||||
*
|
||||
* @param destination The DatabaseManager to save to
|
||||
*/
|
||||
public void convertUsers(DatabaseManager destination);
|
||||
void convertUsers(DatabaseManager destination);
|
||||
|
||||
public boolean saveUserUUID(String userName, UUID uuid);
|
||||
boolean saveUserUUID(String userName, UUID uuid);
|
||||
|
||||
public boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
|
||||
boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
|
||||
|
||||
/**
|
||||
* Retrieve the type of database in use. Custom databases should return CUSTOM.
|
||||
*
|
||||
* @return The type of database
|
||||
*/
|
||||
public DatabaseType getDatabaseType();
|
||||
DatabaseType getDatabaseType();
|
||||
|
||||
/**
|
||||
* Called when the plugin disables
|
||||
*/
|
||||
public void onDisable();
|
||||
void onDisable();
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
private final HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<PrimarySkillType, List<PlayerStat>>();
|
||||
private final List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
|
||||
private final HashMap<PrimarySkillType, List<PlayerStat>> playerStatHash = new HashMap<>();
|
||||
private final List<PlayerStat> powerLevels = new ArrayList<>();
|
||||
private long lastUpdate = 0;
|
||||
|
||||
private final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
|
||||
@ -36,7 +36,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
updateLeaderboards();
|
||||
|
||||
if (mcMMO.getUpgradeManager().shouldUpgrade(UpgradeType.ADD_UUIDS)) {
|
||||
new UUIDUpdateAsyncTask(mcMMO.p, getStoredUsers()).runTaskAsynchronously(mcMMO.p);
|
||||
new UUIDUpdateAsyncTask(mcMMO.p, getStoredUsers()).start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,7 +425,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
public Map<PrimarySkillType, Integer> readRank(String playerName) {
|
||||
updateLeaderboards();
|
||||
|
||||
Map<PrimarySkillType, Integer> skills = new HashMap<PrimarySkillType, Integer>();
|
||||
Map<PrimarySkillType, Integer> skills = new HashMap<>();
|
||||
|
||||
for (PrimarySkillType skill : PrimarySkillType.NON_CHILD_SKILLS) {
|
||||
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill)));
|
||||
@ -734,7 +734,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
character[UUID_INDEX] = fetchedUUIDs.remove(character[USERNAME]).toString();
|
||||
line = new StringBuilder(org.apache.commons.lang.StringUtils.join(character, ":")).append(":").toString();
|
||||
line = org.apache.commons.lang.StringUtils.join(character, ":") + ":";
|
||||
}
|
||||
|
||||
i++;
|
||||
@ -772,7 +772,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public List<String> getStoredUsers() {
|
||||
ArrayList<String> users = new ArrayList<String>();
|
||||
ArrayList<String> users = new ArrayList<>();
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
|
||||
@ -818,19 +818,19 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
powerLevels.clear(); // Clear old values from the power levels
|
||||
|
||||
// Initialize lists
|
||||
List<PlayerStat> mining = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> woodcutting = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> herbalism = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> excavation = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> acrobatics = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> repair = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> swords = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> axes = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> archery = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> unarmed = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> taming = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> fishing = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> alchemy = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> mining = new ArrayList<>();
|
||||
List<PlayerStat> woodcutting = new ArrayList<>();
|
||||
List<PlayerStat> herbalism = new ArrayList<>();
|
||||
List<PlayerStat> excavation = new ArrayList<>();
|
||||
List<PlayerStat> acrobatics = new ArrayList<>();
|
||||
List<PlayerStat> repair = new ArrayList<>();
|
||||
List<PlayerStat> swords = new ArrayList<>();
|
||||
List<PlayerStat> axes = new ArrayList<>();
|
||||
List<PlayerStat> archery = new ArrayList<>();
|
||||
List<PlayerStat> unarmed = new ArrayList<>();
|
||||
List<PlayerStat> taming = new ArrayList<>();
|
||||
List<PlayerStat> fishing = new ArrayList<>();
|
||||
List<PlayerStat> alchemy = new ArrayList<>();
|
||||
|
||||
BufferedReader in = null;
|
||||
String playerName = null;
|
||||
@ -881,20 +881,20 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
|
||||
SkillComparator c = new SkillComparator();
|
||||
|
||||
Collections.sort(mining, c);
|
||||
Collections.sort(woodcutting, c);
|
||||
Collections.sort(repair, c);
|
||||
Collections.sort(unarmed, c);
|
||||
Collections.sort(herbalism, c);
|
||||
Collections.sort(excavation, c);
|
||||
Collections.sort(archery, c);
|
||||
Collections.sort(swords, c);
|
||||
Collections.sort(axes, c);
|
||||
Collections.sort(acrobatics, c);
|
||||
Collections.sort(taming, c);
|
||||
Collections.sort(fishing, c);
|
||||
Collections.sort(alchemy, c);
|
||||
Collections.sort(powerLevels, c);
|
||||
mining.sort(c);
|
||||
woodcutting.sort(c);
|
||||
repair.sort(c);
|
||||
unarmed.sort(c);
|
||||
herbalism.sort(c);
|
||||
excavation.sort(c);
|
||||
archery.sort(c);
|
||||
swords.sort(c);
|
||||
axes.sort(c);
|
||||
acrobatics.sort(c);
|
||||
taming.sort(c);
|
||||
fishing.sort(c);
|
||||
alchemy.sort(c);
|
||||
powerLevels.sort(c);
|
||||
|
||||
playerStatHash.put(PrimarySkillType.MINING, mining);
|
||||
playerStatHash.put(PrimarySkillType.WOODCUTTING, woodcutting);
|
||||
@ -925,8 +925,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
in = new BufferedReader(new FileReader(usersFilePath));
|
||||
StringBuilder writer = new StringBuilder();
|
||||
String line;
|
||||
HashSet<String> usernames = new HashSet<String>();
|
||||
HashSet<String> players = new HashSet<String>();
|
||||
HashSet<String> usernames = new HashSet<>();
|
||||
HashSet<String> players = new HashSet<>();
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
// Remove empty lines from the file
|
||||
@ -1196,7 +1196,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
line = new StringBuilder(org.apache.commons.lang.StringUtils.join(character, ":")).append(":").toString();
|
||||
line = org.apache.commons.lang.StringUtils.join(character, ":") + ":";
|
||||
}
|
||||
|
||||
writer.append(line).append("\r\n");
|
||||
@ -1273,7 +1273,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
return statValue;
|
||||
}
|
||||
|
||||
private class SkillComparator implements Comparator<PlayerStat> {
|
||||
private static class SkillComparator implements Comparator<PlayerStat> {
|
||||
@Override
|
||||
public int compare(PlayerStat o1, PlayerStat o2) {
|
||||
return (o2.statVal - o1.statVal);
|
||||
@ -1376,7 +1376,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
private Map<PrimarySkillType, Integer> getSkillMapFromLine(String[] character) {
|
||||
Map<PrimarySkillType, Integer> skills = new EnumMap<PrimarySkillType, Integer>(PrimarySkillType.class); // Skill & Level
|
||||
Map<PrimarySkillType, Integer> skills = new EnumMap<>(PrimarySkillType.class); // Skill & Level
|
||||
|
||||
skills.put(PrimarySkillType.TAMING, Integer.valueOf(character[SKILLS_TAMING]));
|
||||
skills.put(PrimarySkillType.MINING, Integer.valueOf(character[SKILLS_MINING]));
|
||||
|
@ -24,9 +24,9 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public final class SQLDatabaseManager implements DatabaseManager {
|
||||
private static final String ALL_QUERY_VERSION = "total";
|
||||
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
private final String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
private final Map<UUID, Integer> cachedUserIDs = new HashMap<UUID, Integer>();
|
||||
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
|
||||
|
||||
private DataSource miscPool;
|
||||
private DataSource loadPool;
|
||||
@ -34,7 +34,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
private boolean debug = false;
|
||||
|
||||
private ReentrantLock massUpdateLock = new ReentrantLock();
|
||||
private final ReentrantLock massUpdateLock = new ReentrantLock();
|
||||
|
||||
protected SQLDatabaseManager() {
|
||||
String connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName()
|
||||
@ -215,8 +215,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public void cleanupUser(UUID uuid) {
|
||||
if(cachedUserIDs.containsKey(uuid))
|
||||
cachedUserIDs.remove(uuid);
|
||||
cachedUserIDs.remove(uuid);
|
||||
}
|
||||
|
||||
public boolean saveUser(PlayerProfile profile) {
|
||||
@ -346,7 +345,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage) {
|
||||
List<PlayerStat> stats = new ArrayList<PlayerStat>();
|
||||
List<PlayerStat> stats = new ArrayList<>();
|
||||
|
||||
String query = skill == null ? ALL_QUERY_VERSION : skill.name().toLowerCase(Locale.ENGLISH);
|
||||
ResultSet resultSet = null;
|
||||
@ -361,13 +360,13 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
ArrayList<String> column = new ArrayList<String>();
|
||||
ArrayList<String> column = new ArrayList<>();
|
||||
|
||||
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
|
||||
column.add(resultSet.getString(i));
|
||||
}
|
||||
|
||||
stats.add(new PlayerStat(column.get(1), Integer.valueOf(column.get(0))));
|
||||
stats.add(new PlayerStat(column.get(1), Integer.parseInt(column.get(0))));
|
||||
}
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
@ -383,7 +382,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public Map<PrimarySkillType, Integer> readRank(String playerName) {
|
||||
Map<PrimarySkillType, Integer> skills = new HashMap<PrimarySkillType, Integer>();
|
||||
Map<PrimarySkillType, Integer> skills = new HashMap<>();
|
||||
|
||||
ResultSet resultSet = null;
|
||||
PreparedStatement statement = null;
|
||||
@ -753,7 +752,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public List<String> getStoredUsers() {
|
||||
ArrayList<String> users = new ArrayList<String>();
|
||||
ArrayList<String> users = new ArrayList<>();
|
||||
|
||||
Statement statement = null;
|
||||
Connection connection = null;
|
||||
@ -1319,7 +1318,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
private class GetUUIDUpdatesRequired extends BukkitRunnable {
|
||||
public void run() {
|
||||
massUpdateLock.lock();
|
||||
List<String> names = new ArrayList<String>();
|
||||
List<String> names = new ArrayList<>();
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
@ -1341,7 +1340,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
if (!names.isEmpty()) {
|
||||
new UUIDUpdateAsyncTask(mcMMO.p, names).run();
|
||||
UUIDUpdateAsyncTask updateTask = new UUIDUpdateAsyncTask(mcMMO.p, names);
|
||||
updateTask.start();
|
||||
updateTask.waitUntilFinished();
|
||||
}
|
||||
} finally {
|
||||
massUpdateLock.unlock();
|
||||
@ -1489,9 +1490,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
int id = resultSet.getInt("id");
|
||||
|
||||
return id;
|
||||
return resultSet.getInt("id");
|
||||
}
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
|
Reference in New Issue
Block a user