diff --git a/src/main/java/com/gmail/nossr50/runnables/mcRankAsync.java b/src/main/java/com/gmail/nossr50/runnables/mcRankAsync.java index 66c9d494d..f995e881a 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcRankAsync.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcRankAsync.java @@ -31,9 +31,9 @@ public class mcRankAsync implements Runnable { for (SkillType skillType : SkillType.values()) { if (skillType.equals(SkillType.ALL)) continue; // We want the overall ranking to be at the bottom - sender.sendMessage(ChatColor.YELLOW + Misc.getCapitalized(skillType.name()) + ChatColor.GREEN + " - " + ChatColor.GOLD + "Rank " + ChatColor.WHITE + "#" + ChatColor.GREEN + skills.get(skillType.name())); + sender.sendMessage(ChatColor.YELLOW + Misc.getCapitalized(skillType.name()) + ChatColor.GREEN + " - " + (skills.get(skillType.name()) == null ? ChatColor.WHITE + "Unranked" : ChatColor.GOLD + "Rank " + ChatColor.WHITE + "#" + ChatColor.GREEN + skills.get(skillType.name()))); } - sender.sendMessage(ChatColor.YELLOW + "Overall" + ChatColor.GREEN + " - " + ChatColor.GOLD + "Rank " + ChatColor.WHITE + "#" + ChatColor.GREEN + skills.get("ALL")); + sender.sendMessage(ChatColor.YELLOW + "Overall" + ChatColor.GREEN + " - " + (skills.get("ALL") == null ? ChatColor.WHITE + "Unranked" : ChatColor.GOLD + "Rank " + ChatColor.WHITE + "#" + ChatColor.GREEN + skills.get("ALL"))); } diff --git a/src/main/java/com/gmail/nossr50/util/Database.java b/src/main/java/com/gmail/nossr50/util/Database.java index 1af592864..f33faa0d9 100644 --- a/src/main/java/com/gmail/nossr50/util/Database.java +++ b/src/main/java/com/gmail/nossr50/util/Database.java @@ -461,15 +461,18 @@ public class Database { for (SkillType skillType: SkillType.values()) { String sql; if(skillType != SkillType.ALL) { - sql = "SELECT rank AS '" + skillType.name() + "' FROM (SELECT @rownum:=@rownum+1 rank, user, NOW() FROM (SELECT @rownum:=0) AS r, ((SELECT user FROM " + tablePrefix + "users, " + tablePrefix + "skills WHERE id = user_id ORDER BY " + skillType.name().toLowerCase() + " desc) AS p)) AS d WHERE user = '" + playerName + "'"; + sql = "SELECT user, " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "users, " + tablePrefix + "skills WHERE id = user_id AND " + skillType.name().toLowerCase() + " > 0 AND " + skillType.name().toLowerCase() + " >= (SELECT " + skillType.name().toLowerCase() + " FROM " + tablePrefix + "skills, " + tablePrefix + "users WHERE user = '" + playerName + "' AND id = user_id) ORDER BY " + skillType.name().toLowerCase() + " desc"; } else { - sql = "SELECT rank AS 'ALL' FROM (SELECT @rownum:=@rownum+1 rank, user, NOW() FROM (SELECT @rownum:=0) AS r, ((SELECT user FROM " + tablePrefix + "users, " + tablePrefix + "skills WHERE id = user_id ORDER BY taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing desc) AS p)) AS d WHERE user = '" + playerName + "'"; + sql = "SELECT user, taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "users, " + tablePrefix + "skills WHERE id = user_id AND taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing >= (SELECT taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing FROM " + tablePrefix + "skills, " + tablePrefix + "users WHERE user = '" + playerName + "' AND id = user_id) ORDER BY taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing desc"; } PreparedStatement statement = connection.prepareStatement(sql); resultSet = statement.executeQuery(); while (resultSet.next()) { - skills.put(skillType.name(), resultSet.getInt(skillType.name())); + if(resultSet.getString("user").equalsIgnoreCase(playerName)) { + skills.put(skillType.name(), resultSet.getRow()); + break; + } } statement.close(); }