mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
Update /mcrank to use Bukkit CommandAPI. Addresses #628
This commit is contained in:
parent
0de7e22408
commit
5349b46122
@ -16,6 +16,7 @@ import com.gmail.nossr50.commands.admin.XprateCommand;
|
||||
import com.gmail.nossr50.commands.player.InspectCommand;
|
||||
import com.gmail.nossr50.commands.player.McabilityCommand;
|
||||
import com.gmail.nossr50.commands.player.McmmoCommand;
|
||||
import com.gmail.nossr50.commands.player.McrankCommand;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
|
||||
import com.gmail.nossr50.skills.archery.ArcheryCommand;
|
||||
@ -219,4 +220,13 @@ public final class CommandRegistrationHelper {
|
||||
command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.1", "mcmmo", "?"));
|
||||
command.setExecutor(new McmmoCommand());
|
||||
}
|
||||
|
||||
public static void registerMcrankCommand() {
|
||||
PluginCommand command = mcMMO.p.getCommand("mcrank");
|
||||
command.setDescription(LocaleLoader.getString("Commands.Description.mcrank"));
|
||||
command.setPermission("mcmmo.commands.mcrank;mcmmo.commands.mcrank.others;mcmmo.commands.mcrank.others.far;mcmmo.commands.mcrank.others.offline");
|
||||
command.setPermissionMessage(permissionsMessage);
|
||||
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcrank", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
|
||||
command.setExecutor(new McrankCommand());
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.CommandHelper;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.McRankAsync;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
@ -22,62 +22,70 @@ import com.gmail.nossr50.util.Users;
|
||||
public class McrankCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
// TODO: Better input handling, add usage string
|
||||
if (!Config.getInstance().getUseMySQL()) {
|
||||
Leaderboard.updateLeaderboards(); // Make sure the information is up to date
|
||||
}
|
||||
|
||||
if (CommandHelper.noConsoleUsage(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcrank")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
String playerName;
|
||||
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
playerName = player.getName();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcrank.others")) {
|
||||
if (!Permissions.hasPermission(sender, "mcmmo.commands.mcrank")) {
|
||||
sender.sendMessage(command.getPermissionMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
playerName = args[0];
|
||||
McMMOPlayer mcmmoPlayer = Users.getPlayer(playerName);
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mcmmoPlayer != null) {
|
||||
Player target = mcmmoPlayer.getPlayer();
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
sqlDisplay(sender, sender.getName());
|
||||
}
|
||||
else {
|
||||
Leaderboard.updateLeaderboards(); // Make sure the information is up to date
|
||||
flatfileDisplay(sender, sender.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
if (!Permissions.hasPermission(sender, "mcmmo.commands.mcrank.others")) {
|
||||
sender.sendMessage(command.getPermissionMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
PlayerProfile profile = new PlayerProfile(args[0], false); //Temporary Profile
|
||||
|
||||
if (!profile.isLoaded()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender instanceof Player && !!Permissions.hasPermission(sender, "mcmmo.commands.mcrank.others.offline")) {
|
||||
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Player target = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.hasPermission(sender, "mcmmo.commands.mcrank.others.far")) {
|
||||
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (sender instanceof Player && !Permissions.hasPermission(sender, "mcmmo.commands.mcrank.others.offline")) {
|
||||
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
|
||||
return true;
|
||||
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
sqlDisplay(sender, args[0]);
|
||||
}
|
||||
else {
|
||||
Leaderboard.updateLeaderboards(); // Make sure the information is up to date
|
||||
flatfileDisplay(sender, args[0]);
|
||||
}
|
||||
|
||||
break;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
sqlDisplay(sender, playerName);
|
||||
}
|
||||
else {
|
||||
flatfileDisplay(sender, playerName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void flatfileDisplay(CommandSender sender, String playerName) {
|
||||
|
@ -26,7 +26,6 @@ import com.gmail.nossr50.chat.commands.ACommand;
|
||||
import com.gmail.nossr50.chat.commands.PCommand;
|
||||
import com.gmail.nossr50.commands.CommandRegistrationHelper;
|
||||
import com.gmail.nossr50.commands.player.MccCommand;
|
||||
import com.gmail.nossr50.commands.player.McrankCommand;
|
||||
import com.gmail.nossr50.commands.player.McstatsCommand;
|
||||
import com.gmail.nossr50.commands.player.MctopCommand;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
@ -446,7 +445,7 @@ public class mcMMO extends JavaPlugin {
|
||||
CommandRegistrationHelper.registerMcmmoCommand();
|
||||
CommandRegistrationHelper.registerMcrefreshCommand();
|
||||
getCommand("mctop").setExecutor(new MctopCommand());
|
||||
getCommand("mcrank").setExecutor(new McrankCommand());
|
||||
CommandRegistrationHelper.registerMcrankCommand();
|
||||
getCommand("mcstats").setExecutor(new McstatsCommand());
|
||||
|
||||
// Party commands
|
||||
|
@ -695,6 +695,7 @@ Commands.Description.inspect=View detailed mcMMO info on another player
|
||||
Commands.Description.mcability=Toggle mcMMO abilities being readied on right-click on/off
|
||||
Commands.Description.mcgod=Toggle mcMMO god-mode on/off
|
||||
Commands.Description.mcmmo=Show a brief description of mcMMO
|
||||
Commands.Description.mcrank=Show mcMMO ranking for a player
|
||||
Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
|
||||
Commands.Description.mmoedit=Edit mcMMO levels for a user
|
||||
Commands.Description.Skill=Display detailed mcMMO skill info for {0}
|
||||
|
@ -37,8 +37,7 @@ commands:
|
||||
aliases: []
|
||||
description: Shows leader boards for mcMMO
|
||||
mcrank:
|
||||
aliases: []
|
||||
description: Show your individual ranking in mcMMO
|
||||
description: Show mcMMO ranking for a player
|
||||
addxp:
|
||||
description: Add mcMMO XP to a user
|
||||
addlevels:
|
||||
|
Loading…
Reference in New Issue
Block a user