mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Tidying up Permission checks for /mcrank and /mctop
This commit is contained in:
parent
3a7d88db4f
commit
410c946faf
@ -23,15 +23,15 @@ public class McrankCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Permissions.mcrank(sender)) {
|
||||
sender.sendMessage(command.getPermissionMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
sqlDisplay(sender, sender.getName());
|
||||
}
|
||||
@ -94,11 +94,7 @@ public class McrankCommand implements CommandExecutor {
|
||||
for (SkillType skillType : SkillType.values()) {
|
||||
int[] rankInts = LeaderboardManager.getPlayerRank(playerName, skillType);
|
||||
|
||||
if (skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((sender instanceof Player) && !Permissions.skillEnabled((Player) sender, skillType)) {
|
||||
if ((sender instanceof Player && !Permissions.skillEnabled(sender, skillType)) || skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -79,18 +79,18 @@ public class MctopCommand implements CommandExecutor {
|
||||
|
||||
if (sql) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
sqlDisplay(page, skill, sender, command);
|
||||
sqlDisplay(page, skill, sender);
|
||||
}
|
||||
}
|
||||
else {
|
||||
flatfileDisplay(page, skill, sender, command);
|
||||
flatfileDisplay(page, skill, sender);
|
||||
}
|
||||
}
|
||||
|
||||
private void flatfileDisplay(int page, String skill, CommandSender sender, Command command) {
|
||||
private void flatfileDisplay(int page, String skill, CommandSender sender) {
|
||||
LeaderboardManager.updateLeaderboards(); // Make sure we have the latest information
|
||||
|
||||
String[] info = LeaderboardManager.retrieveInfo(skill, page);
|
||||
@ -122,7 +122,7 @@ public class MctopCommand implements CommandExecutor {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
|
||||
}
|
||||
|
||||
private void sqlDisplay(int page, String query, CommandSender sender, Command command) {
|
||||
mcMMO.p.getServer().getScheduler().runTaskAsynchronously(mcMMO.p, new MctopCommandAsyncTask(page, query, sender, command));
|
||||
private void sqlDisplay(int page, String query, CommandSender sender) {
|
||||
mcMMO.p.getServer().getScheduler().runTaskAsynchronously(mcMMO.p, new MctopCommandAsyncTask(page, query, sender));
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,7 @@ public class McrankCommandAsyncTask implements Runnable {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
|
||||
|
||||
for (SkillType skillType : SkillType.values()) {
|
||||
if (skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((sender instanceof Player) && !Permissions.skillEnabled((Player) sender, skillType)) {
|
||||
if ((sender instanceof Player && !Permissions.skillEnabled(sender, skillType)) || skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -4,15 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class MctopCommandAsyncTask implements Runnable {
|
||||
@ -20,23 +17,15 @@ public class MctopCommandAsyncTask implements Runnable {
|
||||
private CommandSender sender;
|
||||
private String query;
|
||||
private int page;
|
||||
private Command command;
|
||||
|
||||
public MctopCommandAsyncTask(int page, String query, CommandSender sender, Command command) {
|
||||
public MctopCommandAsyncTask(int page, String query, CommandSender sender) {
|
||||
this.page = page;
|
||||
this.query = query;
|
||||
this.sender = sender;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
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");
|
||||
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new Runnable() {
|
||||
|
Loading…
Reference in New Issue
Block a user