check permissions earlier

This commit is contained in:
T00thpick1 2013-03-08 20:30:24 -05:00 committed by NuclearW
parent a97b889af5
commit aeae60f968
2 changed files with 10 additions and 13 deletions

View File

@ -72,17 +72,22 @@ public class MctopCommand implements CommandExecutor {
} }
private void display(int page, String skill, CommandSender sender, boolean sql, Command command) { private void display(int page, String skill, CommandSender sender, boolean sql, Command command) {
if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, SkillType.getSkill(skill))) { if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, SkillType.getSkill(skill))) {
sender.sendMessage(command.getPermissionMessage()); sender.sendMessage(command.getPermissionMessage());
return; return;
} }
if (sql) { if (sql) {
if (skill.equalsIgnoreCase("all")) { if (skill.equalsIgnoreCase("all")) {
sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender, command); sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender, command);
sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender);
} }
else { else {
sqlDisplay(page, skill, sender, command); sqlDisplay(page, skill, sender, command);
sqlDisplay(page, skill, sender);
} }
} }
else { else {
@ -124,7 +129,10 @@ public class MctopCommand implements CommandExecutor {
private void sqlDisplay(int page, String query, CommandSender sender, Command command) { private void sqlDisplay(int page, String query, CommandSender sender, Command command) {
if (mcMMO.queueManager.contains(sender.getName()) || !mcMMO.queueManager.queue(new McTopAsync(page, query, sender, command))) { if (mcMMO.queueManager.contains(sender.getName()) || !mcMMO.queueManager.queue(new McTopAsync(page, query, sender, command))) {
private void sqlDisplay(int page, String query, CommandSender sender) {
if (mcMMO.queueManager.contains(sender.getName()) || !mcMMO.queueManager.queue(new McTopAsync(page, query, sender))) {
//Warn that queue is unable to accept //Warn that queue is unable to accept
} }
} }
} }

View File

@ -5,40 +5,29 @@ import java.util.HashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.datatypes.skills.SkillType;
public class McTopAsync implements Queueable { public class McTopAsync implements Queueable {
private CommandSender sender; private CommandSender sender;
private String query; private String query;
private int page; private int page;
private Command command;
private String player; private String player;
public McTopAsync(int page, String query, CommandSender sender, Command command) { public McTopAsync(int page, String query, CommandSender sender) {
this.page = page; this.page = page;
this.query = query; this.query = query;
this.sender = sender; this.sender = sender;
this.command = command;
this.player = sender.getName(); this.player = sender.getName();
} }
public void run() { public void run() {
if (!query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
if (!Permissions.mctop(sender, SkillType.getSkill(query))) {
sender.sendMessage(command.getPermissionMessage());
return;
}
}
String tablePrefix = Config.getInstance().getMySQLTablePrefix(); String tablePrefix = Config.getInstance().getMySQLTablePrefix();
final HashMap<Integer, ArrayList<String>> userslist = DatabaseManager.read("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT " + ((page * 10) - 10) + ",10"); final HashMap<Integer, ArrayList<String>> userslist = DatabaseManager.read("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT " + ((page * 10) - 10) + ",10");
Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, new Runnable() {