From 7bea8f51207c5a95709ea9920a121099a5999cfa Mon Sep 17 00:00:00 2001 From: T00thpick1 Date: Sat, 12 Jan 2013 21:26:48 -0500 Subject: [PATCH 1/4] Fix MctopCommand and make it more efficient --- .../nossr50/commands/mc/MctopCommand.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java index 1f207e4a8..bbf8c5e2f 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java @@ -63,7 +63,7 @@ public class MctopCommand implements CommandExecutor { } } - String powerlevel = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; + String powerlevel = "taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing"; switch (args.length) { case 0: @@ -136,23 +136,17 @@ public class MctopCommand implements CommandExecutor { String tablePrefix = Config.getInstance().getMySQLTablePrefix(); Database database = mcMMO.getPlayerDatabase(); - HashMap> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC "); + HashMap> userslist = database.read("SELECT s." + query + ", u.user FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE (s.user_id = u.id) AND s." + query + " > 0 ORDER BY s." + query + " DESC LIMIT "+((page * 10) - 10)+",10"); - if (query.equals("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) { + if (query.equals("taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing")) { sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", new Object[] { Misc.getCapitalized(query) })); } - - for (int i = (page * 10) - 9; i <= (page * 10); i++) { - HashMap> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'"); - - if (i > userslist.size() || username == null) { - break; - } - - sender.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0)); + int place = ((page * 10) - 9); + for (ArrayList entry : userslist.values()) { + sender.sendMessage(String.valueOf(place) + ". " + ChatColor.GREEN + entry.get(1) + " - " + ChatColor.WHITE + entry.get(0)); } } } From 07c9b614bce856ca24748a43cd9d195c77c2f970 Mon Sep 17 00:00:00 2001 From: T00thpick1 Date: Sat, 12 Jan 2013 21:29:28 -0500 Subject: [PATCH 2/4] Increment place for display --- src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java index bbf8c5e2f..6988c4344 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java @@ -147,6 +147,7 @@ public class MctopCommand implements CommandExecutor { int place = ((page * 10) - 9); for (ArrayList entry : userslist.values()) { sender.sendMessage(String.valueOf(place) + ". " + ChatColor.GREEN + entry.get(1) + " - " + ChatColor.WHITE + entry.get(0)); + place++; } } } From c54755b9c1abed7038131f728732d419baa70305 Mon Sep 17 00:00:00 2001 From: T00thpick1 Date: Sat, 12 Jan 2013 21:30:53 -0500 Subject: [PATCH 3/4] Forgot to format --- src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java index 6988c4344..944def973 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java @@ -147,7 +147,7 @@ public class MctopCommand implements CommandExecutor { int place = ((page * 10) - 9); for (ArrayList entry : userslist.values()) { sender.sendMessage(String.valueOf(place) + ". " + ChatColor.GREEN + entry.get(1) + " - " + ChatColor.WHITE + entry.get(0)); - place++; + place++; } } } From 4fb7d60eeeae3b63ff154a25f75c2fccc4f9990f Mon Sep 17 00:00:00 2001 From: T00thpick1 Date: Sat, 12 Jan 2013 21:58:02 -0500 Subject: [PATCH 4/4] Java loop should work right now, forgot to order it earlier --- .../java/com/gmail/nossr50/commands/mc/MctopCommand.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java index 944def973..d8429c0fe 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java @@ -144,9 +144,12 @@ public class MctopCommand implements CommandExecutor { else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", new Object[] { Misc.getCapitalized(query) })); } - int place = ((page * 10) - 9); - for (ArrayList entry : userslist.values()) { - sender.sendMessage(String.valueOf(place) + ". " + ChatColor.GREEN + entry.get(1) + " - " + ChatColor.WHITE + entry.get(0)); + int place = (page * 10) - 9; + for (int i =0; i < 10; i++) { + if(userslist.get(i) == null) { + break; + } + sender.sendMessage(String.valueOf(place) + ". " + ChatColor.GREEN + userslist.get(i).get(1) + " - " + ChatColor.WHITE + userslist.get(i).get(0)); place++; } }