Skip to content

Commit

Permalink
Throw errors for child skill leaderboard requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Nov 10, 2020
1 parent c9b950d commit 592851e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
@@ -1,5 +1,6 @@
Version 2.1.156
Fixed a bug where the admin and party chat toggles in chat.yml didn't function as intended
Added some errors that trigger if a plugin hooking into mcMMO is grabbing leaderboards for child skills through our SQL/FlatFile class (which don't exist)

Version 2.1.155
Master Angler now has 8 ranks
Expand Down
Expand Up @@ -6,4 +6,8 @@ public class InvalidSkillException extends RuntimeException {
public InvalidSkillException() {
super("That is not a valid skill.");
}

public InvalidSkillException(String msg) {
super(msg);
}
}
@@ -1,5 +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;
Expand Down Expand Up @@ -58,7 +59,7 @@ public interface DatabaseManager {
* @param statsPerPage The number of stats per page
* @return the requested leaderboard information
*/
List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage);
List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException;

/**
* Retrieve rank info into a HashMap from PrimarySkillType to the rank.
Expand Down
@@ -1,5 +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;
Expand Down Expand Up @@ -363,7 +364,13 @@ private void writeUserToLine(PlayerProfile profile, String playerName, UUID uuid
writer.append("\r\n");
}

public List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage) {
public List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException {
//Fix for a plugin that people are using that is throwing SQL errors
if(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!");
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!");
}

updateLeaderboards();
List<PlayerStat> statsList = skill == null ? powerLevels : playerStatHash.get(skill);
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
Expand Down
@@ -1,5 +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;
Expand Down Expand Up @@ -343,9 +344,16 @@ public boolean saveUser(PlayerProfile profile) {
return success;
}

public List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage) {
public List<PlayerStat> readLeaderboard(PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException {
List<PlayerStat> stats = new ArrayList<>();

//Fix for a plugin that people are using that is throwing SQL errors
if(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!");
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!");
}


String query = skill == null ? ALL_QUERY_VERSION : skill.name().toLowerCase(Locale.ENGLISH);
ResultSet resultSet = null;
PreparedStatement statement = null;
Expand Down
Expand Up @@ -91,7 +91,9 @@ public void handleSalvage(Location location, ItemStack item) {

// Level check
if (getSkillLevel() < minimumSalvageableLevel) {
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Salvage.Skills.Adept.Level", String.valueOf(salvageable.getMinimumLevel()), StringUtils.getPrettyItemString(item.getType()));
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET,
"Salvage.Skills.Adept.Level",
String.valueOf(minimumSalvageableLevel), StringUtils.getPrettyItemString(item.getType()));
return;
}

Expand Down

0 comments on commit 592851e

Please sign in to comment.