mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Cleanup of /mctop, bug fixing, and locale.
This commit is contained in:
parent
46d7212d1b
commit
153ecf4d13
@ -20,6 +20,7 @@ Version 1.3.06-dev
|
||||
= Fixed bug with Nether Wart not awarding XP
|
||||
= Fixed bug with fishing treasures when treasures list is empty
|
||||
= Fixed bug with only getting one level when there was enough XP for multiple levels.
|
||||
= Fixed bugs with the way /mctop displayed
|
||||
! Changed mcremove to check for users in the MySQL DB before sending queries to remove them
|
||||
! Changed how the tree feller threshold worked for the better
|
||||
! Changed /mcremove to no longer kick players when they are removed from database
|
||||
|
@ -214,7 +214,16 @@ public class Leaderboard {
|
||||
try {
|
||||
FileReader file = new FileReader(theLocation);
|
||||
BufferedReader in = new BufferedReader(file);
|
||||
int destination = (pagenumber - 1) * 10; //How many lines to skip through
|
||||
int destination;
|
||||
|
||||
//How many lines to skip through
|
||||
if (pagenumber == 1) {
|
||||
destination = 0;
|
||||
}
|
||||
else {
|
||||
destination = (pagenumber * 10) - 9;
|
||||
}
|
||||
|
||||
int x = 0; //how many lines we've gone through
|
||||
int y = 0; //going through the lines
|
||||
String line = "";
|
||||
|
@ -23,7 +23,7 @@ public class McremoveCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String playerName;
|
||||
String usage = ChatColor.RED + "Correct usage is /mcremove <playername>"; //TODO: Needs more locale.
|
||||
String usage = ChatColor.RED + "Proper usage is /mcremove <playername>"; //TODO: Needs more locale.
|
||||
String success;
|
||||
|
||||
if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mcremove")) {
|
||||
|
@ -11,176 +11,130 @@ import com.gmail.nossr50.Leaderboard;
|
||||
import com.gmail.nossr50.m;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.LoadProperties;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
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) {
|
||||
|
||||
if (LoadProperties.useMySQL == false) {
|
||||
/*
|
||||
* POWER LEVEL INFO RETRIEVAL
|
||||
*/
|
||||
if (args.length == 0) {
|
||||
int p = 1;
|
||||
String[] info = Leaderboard.retrieveInfo(SkillType.ALL.toString(), p);
|
||||
sender.sendMessage(mcLocale.getString("mcPlayerListener.PowerLevelLeaderboard"));
|
||||
int n = 1 * p; // Position
|
||||
for (String x : info) {
|
||||
if (x != null) {
|
||||
String digit = String.valueOf(n);
|
||||
if (n < 10)
|
||||
digit = "0" + String.valueOf(n);
|
||||
String[] splitx = x.split(":");
|
||||
// Format: 1. Playername - skill value
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.length >= 1 && m.isInt(args[0])) {
|
||||
int p = 1;
|
||||
// Grab page value if specified
|
||||
if (args.length >= 1) {
|
||||
if (m.isInt(args[0])) {
|
||||
p = Integer.valueOf(args[0]);
|
||||
}
|
||||
}
|
||||
int pt = p;
|
||||
if (p > 1) {
|
||||
pt -= 1;
|
||||
pt += (pt * 10);
|
||||
pt = 10;
|
||||
}
|
||||
String[] info = Leaderboard.retrieveInfo(SkillType.ALL.toString(), p);
|
||||
sender.sendMessage(mcLocale.getString("mcPlayerListener.PowerLevelLeaderboard"));
|
||||
int n = 1 * pt; // Position
|
||||
for (String x : info) {
|
||||
if (x != null) {
|
||||
String digit = String.valueOf(n);
|
||||
if (n < 10)
|
||||
digit = "0" + String.valueOf(n);
|
||||
String[] splitx = x.split(":");
|
||||
// Format: 1. Playername - skill value
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* SKILL SPECIFIED INFO RETRIEVAL
|
||||
*/
|
||||
if (args.length >= 1 && Skills.isSkill(args[0])) {
|
||||
int p = 1;
|
||||
// Grab page value if specified
|
||||
if (args.length >= 2) {
|
||||
if (m.isInt(args[1])) {
|
||||
p = Integer.valueOf(args[1]);
|
||||
}
|
||||
}
|
||||
int pt = p;
|
||||
if (p > 1) {
|
||||
pt -= 1;
|
||||
pt += (pt * 10);
|
||||
pt = 10;
|
||||
}
|
||||
String firstLetter = args[0].substring(0, 1); // Get first letter
|
||||
String remainder = args[0].substring(1); // Get remainder of word.
|
||||
String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase();
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String usage = ChatColor.RED + "Proper usage is /mctop [skillname] [page]"; //TODO: Needs more locale.
|
||||
if (!LoadProperties.useMySQL) {
|
||||
|
||||
String[] info = Leaderboard.retrieveInfo(args[0].toUpperCase(), p);
|
||||
sender.sendMessage(mcLocale.getString("mcPlayerListener.SkillLeaderboard", new Object[] { capitalized }));
|
||||
int n = 1 * pt; // Position
|
||||
for (String x : info) {
|
||||
if (x != null) {
|
||||
String digit = String.valueOf(n);
|
||||
if (n < 10)
|
||||
digit = "0" + String.valueOf(n);
|
||||
String[] splitx = x.split(":");
|
||||
// Format: 1. Playername - skill value
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + splitx[1] + " - " + ChatColor.WHITE + splitx[0]);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* MYSQL LEADERBOARDS
|
||||
*/
|
||||
String powerlevel = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing";
|
||||
if (args.length >= 1 && Skills.isSkill(args[0])) {
|
||||
/*
|
||||
* Create a nice consistent capitalized leaderboard name
|
||||
*/
|
||||
String lowercase = args[0].toLowerCase(); // For the query
|
||||
String firstLetter = args[0].substring(0, 1); // Get first letter
|
||||
String remainder = args[0].substring(1); // Get remainder of word.
|
||||
String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase();
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
flatfileDisplay(1, "ALL", sender);
|
||||
return true;
|
||||
|
||||
sender.sendMessage(mcLocale.getString("mcPlayerListener.SkillLeaderboard", new Object[] { capitalized }));
|
||||
if (args.length >= 2 && m.isInt(args[1])) {
|
||||
int n = 1; // For the page number
|
||||
int n2 = Integer.valueOf(args[1]);
|
||||
if (n2 > 1) {
|
||||
// Figure out the 'page' here
|
||||
n = 10;
|
||||
n = n * (n2 - 1);
|
||||
}
|
||||
// If a page number is specified
|
||||
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + lowercase + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + lowercase + " > 0 ORDER BY `" + LoadProperties.MySQLtablePrefix + "skills`.`" + lowercase + "` DESC ");
|
||||
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(usage);
|
||||
}
|
||||
|
||||
for (int i = n; i <= n + 10; i++) {
|
||||
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
|
||||
break;
|
||||
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "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));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// If no page number is specified
|
||||
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + lowercase + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + lowercase + " > 0 ORDER BY `" + LoadProperties.MySQLtablePrefix + "skills`.`" + lowercase + "` DESC ");
|
||||
for (int i = 1; i <= 10; i++) { // i<=userslist.size()
|
||||
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
|
||||
break;
|
||||
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "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));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length >= 0) {
|
||||
sender.sendMessage(mcLocale.getString("mcPlayerListener.PowerLevelLeaderboard"));
|
||||
if (args.length >= 1 && m.isInt(args[0])) {
|
||||
int n = 1; // For the page number
|
||||
int n2 = Integer.valueOf(args[0]);
|
||||
if (n2 > 1) {
|
||||
// Figure out the 'page' here
|
||||
n = 10;
|
||||
n = n * (n2 - 1);
|
||||
}
|
||||
// If a page number is specified
|
||||
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + powerlevel + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + powerlevel + " > 0 ORDER BY " + powerlevel + " DESC ");
|
||||
for (int i = n; i <= n + 10; i++) {
|
||||
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
|
||||
break;
|
||||
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "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));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + powerlevel + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + powerlevel + " > 0 ORDER BY " + powerlevel + " DESC ");
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
|
||||
break;
|
||||
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "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));
|
||||
// System.out.println(username.get(1).get(0));
|
||||
// System.out.println("Mining : " + userslist.get(i).get(0) + ", User id : " + userslist.get(i).get(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
case 2:
|
||||
if (Skills.isSkill(args[0]) && 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(usage);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
if (Skills.isSkill(args[0]) && m.isInt(args[1])) {
|
||||
sqlDisplay(Integer.valueOf(args[1]), args[0].toLowerCase(), sender);
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(usage);
|
||||
}
|
||||
|
||||
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) {
|
||||
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + query + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "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 " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user