2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.player;
|
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2013-03-28 17:57:49 +01:00
|
|
|
import org.bukkit.command.TabExecutor;
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2013-03-28 17:57:49 +01:00
|
|
|
import org.bukkit.util.StringUtil;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-04-18 23:37:36 +02:00
|
|
|
import com.gmail.nossr50.database.FlatfileDatabaseManager;
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.runnables.commands.MctopCommandAsyncTask;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
2013-03-12 21:25:42 +01:00
|
|
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
|
|
public class MctopCommand implements TabExecutor {
|
2013-03-12 21:25:42 +01:00
|
|
|
private SkillType skill;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
2013-04-18 23:37:36 +02:00
|
|
|
display(1, "ALL", sender, command);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (StringUtils.isInt(args[0])) {
|
2013-04-18 23:37:36 +02:00
|
|
|
display(Math.abs(Integer.parseInt(args[0])), "ALL", sender, command);
|
2013-03-12 21:25:42 +01:00
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-01 16:38:14 +01:00
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (!extractSkill(sender, args[0])) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 23:37:36 +02:00
|
|
|
display(1, skill.toString(), sender, command);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2:
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.isInvalidInteger(sender, args[1])) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (!extractSkill(sender, args[0])) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 23:37:36 +02:00
|
|
|
display(Math.abs(Integer.parseInt(args[1])), skill.toString(), sender, command);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
2013-04-15 18:52:11 +02:00
|
|
|
return StringUtil.copyPartialMatches(args[0], SkillType.SKILL_NAMES, new ArrayList<String>(SkillType.SKILL_NAMES.size()));
|
2013-03-28 17:57:49 +01:00
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 23:37:36 +02:00
|
|
|
private void display(int page, String skill, CommandSender sender, Command command) {
|
2013-03-12 21:25:42 +01:00
|
|
|
if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, this.skill)) {
|
2013-03-10 20:45:25 +01:00
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
if (sender instanceof Player && Config.getInstance().getMctopScoreboardEnabled()) {
|
|
|
|
ScoreboardManager.enableGlobalStatsScoreboard((Player) sender, skill, page);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
else {
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
if (Config.getInstance().getUseMySQL()) {
|
|
|
|
sqlDisplay(page, skill, sender);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
flatfileDisplay(page, skill, sender);
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-11 17:48:00 +01:00
|
|
|
private void flatfileDisplay(int page, String skill, CommandSender sender) {
|
2013-04-18 23:37:36 +02:00
|
|
|
FlatfileDatabaseManager.updateLeaderboards(); // Make sure we have the latest information
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
if (skill.equalsIgnoreCase("all")) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
int position = (page * 10) - 9;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
for (PlayerStat stat : FlatfileDatabaseManager.retrieveInfo(skill, page, 10)) {
|
|
|
|
String digit = (position < 10) ? "0" : "" + String.valueOf(position);
|
2013-03-12 21:25:42 +01:00
|
|
|
|
|
|
|
// Format: 1. Playername - skill value
|
mcMMO - Now with 100% more scoreboards!
mcMMO now allows for the use of scoreboards to display information in
several instances. By default, all scoreboards are enabled in the config,
and will only display for 10 seconds. After 10 seconds, the scoreboard
will go away and revert to the previously displayed scoreboard, if one
exists.
A global scoreboard now exists for tracking all player stats, and will be
displayed when /mctop is used. Your name will be highlighted in gold when
looking through the scoreboard. Additionally, the scoreboard will display
players in groups of 15, rather than groups of 10 like in chat.
Unfortunately, due to the limitations of scoreboards, the player's rank
will not be displayed in front of their name.
The scoreboard area is now also used for displaying data for /mcrank,
/inspect. and /mcstats. Due to the way scoreboards are handled, the power
level is not guarenteed to show up at any given location in the
scoreboard, but is instead displayed in gold so that it can be easily
found.
Lastly, the scoreboard area is also now used for displaying current data
on skills when the relevant /<skillname> command is used. The effects and
ability stats will still be shown in chat, but the current level, xp, and
remaining xp will be shown in the scoreboard.
2013-04-14 05:16:25 +02:00
|
|
|
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.name + " - " + ChatColor.WHITE + stat.statVal);
|
2013-03-12 21:25:42 +01:00
|
|
|
position++;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
|
|
|
|
}
|
|
|
|
|
2013-03-11 17:48:00 +01:00
|
|
|
private void sqlDisplay(int page, String query, CommandSender sender) {
|
2013-03-20 08:11:16 +01:00
|
|
|
new MctopCommandAsyncTask(page, query, sender).runTaskAsynchronously(mcMMO.p);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-12 21:25:42 +01:00
|
|
|
|
|
|
|
private boolean extractSkill(CommandSender sender, String skillName) {
|
|
|
|
if (CommandUtils.isInvalidSkill(sender, skillName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
skill = SkillType.getSkill(skillName);
|
|
|
|
|
|
|
|
if (CommandUtils.isChildSkill(sender, skill)) {
|
2013-04-01 22:41:20 +02:00
|
|
|
return false;
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|