2013-02-01 19:41:26 +01:00
|
|
|
package com.gmail.nossr50.commands.player;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2013-02-15 18:47:00 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2012-06-05 16:13:10 +02:00
|
|
|
|
2013-02-15 18:47:00 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-02-05 18:56:31 +01:00
|
|
|
import com.gmail.nossr50.database.Leaderboard;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-02-15 18:47:00 +01:00
|
|
|
import com.gmail.nossr50.runnables.McTopAsync;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
2013-02-15 15:26:01 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2013-02-19 06:56:25 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-02-13 17:45:48 +01:00
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
public class MctopCommand implements CommandExecutor {
|
2012-04-20 20:01:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2013-02-05 16:54:53 +01:00
|
|
|
boolean useMySQL = Config.getInstance().getUseMySQL();
|
2012-04-20 20:01:21 +02:00
|
|
|
|
2013-01-10 04:43:21 +01:00
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
2013-02-13 03:58:53 +01:00
|
|
|
display(1, "ALL", sender, useMySQL, command);
|
2013-01-10 04:43:21 +01:00
|
|
|
return true;
|
2012-04-20 20:01:21 +02:00
|
|
|
|
2013-01-10 04:43:21 +01:00
|
|
|
case 1:
|
2013-02-13 17:45:48 +01:00
|
|
|
if (StringUtils.isInt(args[0])) {
|
|
|
|
display(Integer.parseInt(args[0]), "ALL", sender, useMySQL, command);
|
2013-01-10 04:43:21 +01:00
|
|
|
}
|
2013-01-26 23:01:55 +01:00
|
|
|
else if (SkillTools.isSkill(args[0])) {
|
2013-02-15 15:26:01 +01:00
|
|
|
display(1, SkillType.getSkill(args[0]).toString(), sender, useMySQL, command);
|
2013-01-16 06:06:14 +01:00
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
else {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
|
|
|
}
|
2012-04-23 01:34:34 +02:00
|
|
|
|
2013-01-10 04:43:21 +01:00
|
|
|
return true;
|
2012-04-20 20:01:21 +02:00
|
|
|
|
2013-01-10 04:43:21 +01:00
|
|
|
case 2:
|
2013-02-13 17:45:48 +01:00
|
|
|
if (!StringUtils.isInt(args[1])) {
|
2013-02-05 16:54:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SkillTools.isSkill(args[0])) {
|
2013-02-15 15:26:01 +01:00
|
|
|
display(Integer.parseInt(args[1]), SkillType.getSkill(args[0]).toString(), sender, useMySQL, command);
|
2013-01-10 04:43:21 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-02-05 16:54:53 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
2012-04-20 20:01:21 +02:00
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2013-02-05 16:54:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 03:58:53 +01:00
|
|
|
private void display(int page, String skill, CommandSender sender, boolean sql, Command command) {
|
2013-02-05 16:54:53 +01:00
|
|
|
if (sql) {
|
|
|
|
if (skill.equalsIgnoreCase("all")) {
|
2013-02-13 03:58:53 +01:00
|
|
|
sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender, command);
|
2013-02-05 16:54:53 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-02-13 03:58:53 +01:00
|
|
|
sqlDisplay(page, skill, sender, command);
|
2013-02-05 16:54:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-02-13 03:58:53 +01:00
|
|
|
flatfileDisplay(page, skill, sender, command);
|
2012-04-20 20:01:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 03:58:53 +01:00
|
|
|
private void flatfileDisplay(int page, String skill, CommandSender sender, Command command) {
|
2013-02-19 06:56:25 +01:00
|
|
|
if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, SkillType.getSkill(skill))) {
|
2013-02-13 03:58:53 +01:00
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
2013-02-03 23:17:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-21 23:22:54 +01:00
|
|
|
Leaderboard.updateLeaderboards(); //Make sure we have the latest information
|
2012-04-20 20:01:21 +02:00
|
|
|
|
2013-02-04 16:33:34 +01:00
|
|
|
String[] info = Leaderboard.retrieveInfo(skill, page);
|
|
|
|
|
|
|
|
if (skill.equalsIgnoreCase("all")) {
|
2012-04-27 11:47:11 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
2012-04-20 20:01:21 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-02-13 17:45:48 +01:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
|
2012-04-20 20:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int n = (page * 10) - 9; // Position
|
|
|
|
for (String x : info) {
|
|
|
|
if (x != null) {
|
|
|
|
String digit = String.valueOf(n);
|
|
|
|
|
|
|
|
if (n < 10) {
|
|
|
|
digit = "0" + digit;
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] splitx = x.split(":");
|
|
|
|
|
|
|
|
// Format: 1. Playername - skill value
|
|
|
|
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
2013-01-17 07:36:56 +01:00
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
|
2012-04-20 20:01:21 +02:00
|
|
|
}
|
|
|
|
|
2013-02-13 03:58:53 +01:00
|
|
|
private void sqlDisplay(int page, String query, CommandSender sender, Command command) {
|
2013-02-15 18:47:00 +01:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(mcMMO.p, new McTopAsync(page, query, sender, command));
|
2012-04-20 20:01:21 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|