mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-26 10:44:43 +02:00
New and Improved Scoreboard System
- Scoreboards now AUTO-UPDATE - Scoreboards now COME IN COLOR - If you want, they can come in EVERY COLOR (Config setting) - Scoreboards can be displayed alongside chat output! - Prevention of denial of service to SQL via spamming /mctop using a cooldown - Added /mccooldown command to show cooldowns for all available skills
This commit is contained in:
@ -7,6 +7,7 @@ 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;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
|
||||
public interface DatabaseManager {
|
||||
// One month in milliseconds
|
||||
@ -48,15 +49,18 @@ public interface DatabaseManager {
|
||||
* @param statsPerPage The number of stats per page
|
||||
* @return the requested leaderboard information
|
||||
*/
|
||||
public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage);
|
||||
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage);
|
||||
|
||||
/**
|
||||
* Retrieve rank info.
|
||||
* Retrieve rank info into a HashMap from SkillType to the rank.
|
||||
* <p>
|
||||
* The special value <code>null</code> is used to represent the Power
|
||||
* Level rank (the combination of all skill levels).
|
||||
*
|
||||
* @param playerName The name of the user to retrieve the rankings for
|
||||
* @return the requested rank information
|
||||
*/
|
||||
public Map<String, Integer> readRank(String playerName);
|
||||
public Map<SkillType, Integer> readRank(String playerName);
|
||||
|
||||
/**
|
||||
* Add a new user to the database.
|
||||
|
@ -285,24 +285,24 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage) {
|
||||
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage) {
|
||||
updateLeaderboards();
|
||||
List<PlayerStat> statsList = skillName.equalsIgnoreCase("all") ? powerLevels : playerStatHash.get(SkillType.getSkill(skillName));
|
||||
List<PlayerStat> statsList = skill == null ? powerLevels : playerStatHash.get(skill);
|
||||
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
|
||||
|
||||
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
|
||||
}
|
||||
|
||||
public Map<String, Integer> readRank(String playerName) {
|
||||
public Map<SkillType, Integer> readRank(String playerName) {
|
||||
updateLeaderboards();
|
||||
|
||||
Map<String, Integer> skills = new HashMap<String, Integer>();
|
||||
Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();
|
||||
|
||||
for (SkillType skill : SkillType.NON_CHILD_SKILLS) {
|
||||
skills.put(skill.name(), getPlayerRank(playerName, playerStatHash.get(skill)));
|
||||
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill)));
|
||||
}
|
||||
|
||||
skills.put("ALL", getPlayerRank(playerName, powerLevels));
|
||||
skills.put(null, getPlayerRank(playerName, powerLevels));
|
||||
|
||||
return skills;
|
||||
}
|
||||
@ -400,7 +400,16 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
tryClose(in);
|
||||
// I have no idea why it's necessary to inline tryClose() here, but it removes
|
||||
// a resource leak warning, and I'm trusting the compiler on this one.
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,11 +188,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
return success;
|
||||
}
|
||||
|
||||
public List<PlayerStat> readLeaderboard(String skillName, int pageNumber, int statsPerPage) {
|
||||
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage) {
|
||||
List<PlayerStat> stats = new ArrayList<PlayerStat>();
|
||||
|
||||
if (checkConnected()) {
|
||||
String query = skillName.equalsIgnoreCase("ALL") ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : skillName;
|
||||
String query = skill == null ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : skill.name().toLowerCase();
|
||||
ResultSet resultSet = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
@ -230,8 +230,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
return stats;
|
||||
}
|
||||
|
||||
public Map<String, Integer> readRank(String playerName) {
|
||||
Map<String, Integer> skills = new HashMap<String, Integer>();
|
||||
public Map<SkillType, Integer> readRank(String playerName) {
|
||||
Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();
|
||||
|
||||
if (checkConnected()) {
|
||||
ResultSet resultSet;
|
||||
@ -262,7 +262,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
while (resultSet.next()) {
|
||||
if (resultSet.getString("user").equalsIgnoreCase(playerName)) {
|
||||
skills.put(skillType.name(), rank + resultSet.getRow());
|
||||
skills.put(skillType, rank + resultSet.getRow());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -299,7 +299,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
while (resultSet.next()) {
|
||||
if (resultSet.getString("user").equalsIgnoreCase(playerName)) {
|
||||
skills.put("ALL", rank + resultSet.getRow());
|
||||
skills.put(null, rank + resultSet.getRow());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user