mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 14:16:45 +01:00
155 lines
5.6 KiB
Java
155 lines
5.6 KiB
Java
package com.gmail.nossr50.commands.mc;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import com.gmail.nossr50.Leaderboard;
|
|
import com.gmail.nossr50.m;
|
|
import com.gmail.nossr50.mcMMO;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.locale.mcLocale;
|
|
import com.gmail.nossr50.skills.Skills;
|
|
|
|
public class MctopCommand implements CommandExecutor {
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
String usage = ChatColor.RED + "Proper usage is /mctop [skill] [page]"; //TODO: Needs more locale.
|
|
|
|
if (!Config.getInstance().getUseMySQL()) {
|
|
|
|
switch (args.length) {
|
|
case 0:
|
|
flatfileDisplay(1, "ALL", sender);
|
|
return true;
|
|
|
|
case 1:
|
|
if (m.isInt(args[0])) {
|
|
flatfileDisplay(Integer.valueOf(args[0]), "ALL", sender);
|
|
}
|
|
else if (Skills.isSkill(args[0])) {
|
|
flatfileDisplay(1, args[0].toUpperCase(), sender);
|
|
}
|
|
else {
|
|
sender.sendMessage(mcLocale.getString("Commands.Skill.Invalid"));
|
|
}
|
|
|
|
return true;
|
|
|
|
case 2:
|
|
if (!Skills.isSkill(args[0])) {
|
|
sender.sendMessage(mcLocale.getString("Commands.Skill.Invalid"));
|
|
return true;
|
|
}
|
|
|
|
if (m.isInt(args[1])) {
|
|
flatfileDisplay(Integer.valueOf(args[1]), args[0].toUpperCase(), sender);
|
|
}
|
|
else {
|
|
sender.sendMessage(usage);
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
sender.sendMessage(usage);
|
|
return true;
|
|
}
|
|
}
|
|
else {
|
|
String powerlevel = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing";
|
|
|
|
switch (args.length) {
|
|
case 0:
|
|
sqlDisplay(1, powerlevel, sender);
|
|
return true;
|
|
|
|
case 1:
|
|
if (m.isInt(args[0])) {
|
|
sqlDisplay(Integer.valueOf(args[0]), powerlevel, sender);
|
|
}
|
|
else if (Skills.isSkill(args[0])) {
|
|
sqlDisplay(1, args[0].toLowerCase(), sender);
|
|
}
|
|
else {
|
|
sender.sendMessage(mcLocale.getString("Commands.Skill.Invalid"));
|
|
}
|
|
|
|
return true;
|
|
|
|
case 2:
|
|
if (!Skills.isSkill(args[0])) {
|
|
sender.sendMessage(mcLocale.getString("Commands.Skill.Invalid"));
|
|
return true;
|
|
}
|
|
|
|
if (m.isInt(args[1])) {
|
|
sqlDisplay(Integer.valueOf(args[1]), args[0].toLowerCase(), sender);
|
|
}
|
|
else {
|
|
sender.sendMessage(usage);
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
sender.sendMessage(usage);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void flatfileDisplay(int page, String skill, CommandSender sender) {
|
|
String[] info = Leaderboard.retrieveInfo(skill, page);
|
|
|
|
if (skill == "ALL") {
|
|
sender.sendMessage(mcLocale.getString("Commands.PowerLevel.Leaderboard"));
|
|
}
|
|
else {
|
|
sender.sendMessage(mcLocale.getString("Commands.Skill.Leaderboard", new Object[] { m.getCapitalized(skill) }));
|
|
}
|
|
|
|
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++;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void sqlDisplay(int page, String query, CommandSender sender) {
|
|
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
|
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC ");
|
|
|
|
if (query == "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing") {
|
|
sender.sendMessage(mcLocale.getString("Commands.PowerLevel.Leaderboard"));
|
|
}
|
|
else {
|
|
sender.sendMessage(mcLocale.getString("Commands.Skill.Leaderboard", new Object[] { m.getCapitalized(query) }));
|
|
}
|
|
|
|
for (int i = (page * 10) - 9; i <= (page * 10); i++) {
|
|
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null) {
|
|
break;
|
|
}
|
|
|
|
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
|
|
sender.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
|
|
}
|
|
}
|
|
}
|