mcMMO/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java

91 lines
3.3 KiB
Java
Raw Normal View History

package com.gmail.nossr50.commands.player;
2013-01-16 08:50:18 +01:00
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.McRankAsync;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Leaderboard;
public class McrankCommand implements CommandExecutor {
2013-01-16 00:35:21 +01:00
@Override
2013-01-16 08:50:18 +01:00
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;
}
Player player = (Player) sender;
String playerName;
switch (args.length) {
case 0:
playerName = player.getName();
break;
case 1:
playerName = args[0];
break;
2013-01-16 00:35:21 +01:00
default:
return false;
}
if (Config.getInstance().getUseMySQL()) {
sqlDisplay(sender, playerName);
}
else {
flatfileDisplay(sender, playerName);
2013-01-16 00:35:21 +01:00
}
return true;
}
2013-01-16 01:09:48 +01:00
public void flatfileDisplay(CommandSender sender, String playerName) {
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading"));
2013-02-02 08:55:49 +01:00
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName));
2013-01-16 00:35:21 +01:00
for (SkillType skillType : SkillType.values()) {
int[] rankInts = Leaderboard.getPlayerRank(playerName, skillType);
if (skillType.isChildSkill()) {
continue;
}
if (skillType.equals(SkillType.ALL)) {
2013-01-16 00:35:21 +01:00
continue; // We want the overall ranking to be at the bottom
}
if (rankInts[1] == 0) {
2013-02-02 08:55:49 +01:00
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); //Don't bother showing ranking for players without skills
}
else {
2013-02-02 08:55:49 +01:00
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillTools.localizeSkillName(skillType), String.valueOf(rankInts[0])));
}
}
//Show the powerlevel ranking
int[] rankInts = Leaderboard.getPlayerRank(playerName, SkillType.ALL);
if (rankInts[1] == 0) {
2013-02-02 08:55:49 +01:00
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overalll", LocaleLoader.getString("Commands.mcrank.Unranked"))); //Don't bother showing ranking for players without skills
}
else {
2013-02-02 08:55:49 +01:00
sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", String.valueOf(rankInts[0])));
2013-01-16 00:35:21 +01:00
}
}
private void sqlDisplay(CommandSender sender, String playerName) {
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("mcMMO"), new McRankAsync(playerName, sender));
2013-01-16 00:35:21 +01:00
}
}