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.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;
|
2014-08-20 00:11:56 +02:00
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
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-09-12 04:42:27 +02:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
2013-09-12 04:42:27 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-03-01 06:52:01 +01:00
|
|
|
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;
|
2013-09-12 04:42:27 +02:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
|
|
public class MctopCommand implements TabExecutor {
|
2013-03-01 06:52:01 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2013-10-28 19:14:20 +01:00
|
|
|
SkillType skill = null;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
2013-10-28 19:14:20 +01:00
|
|
|
display(1, skill, sender, command);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (StringUtils.isInt(args[0])) {
|
2013-10-28 19:14:20 +01:00
|
|
|
display(Math.abs(Integer.parseInt(args[0])), skill, 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-10-28 19:14:20 +01:00
|
|
|
skill = extractSkill(sender, args[0]);
|
|
|
|
|
|
|
|
if (skill == null) {
|
2013-03-12 21:25:42 +01:00
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:14:20 +01:00
|
|
|
display(1, skill, 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-10-28 19:14:20 +01:00
|
|
|
skill = extractSkill(sender, args[0]);
|
|
|
|
|
|
|
|
if (skill == null) {
|
2013-03-12 21:25:42 +01:00
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:14:20 +01:00
|
|
|
display(Math.abs(Integer.parseInt(args[1])), skill, 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-10-28 19:14:20 +01:00
|
|
|
private void display(int page, SkillType skill, CommandSender sender, Command command) {
|
2013-09-12 04:42:27 +02:00
|
|
|
if (skill != null && !Permissions.mctop(sender, skill)) {
|
2013-03-10 20:45:25 +01:00
|
|
|
sender.sendMessage(command.getPermissionMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 04:42:27 +02:00
|
|
|
if (sender instanceof Player) {
|
2014-08-20 06:23:19 +02:00
|
|
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-28 18:04:06 +01:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
2014-03-29 17:02:08 +01:00
|
|
|
long cooldownMillis = Math.max(Config.getInstance().getDatabasePlayerCooldown(), 1750);
|
2013-10-28 18:04:06 +01:00
|
|
|
|
2014-03-29 17:02:08 +01:00
|
|
|
if (mcMMOPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) {
|
2013-09-12 04:42:27 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Database.Cooldown"));
|
|
|
|
return;
|
|
|
|
}
|
2013-10-28 18:04:06 +01:00
|
|
|
|
2014-08-20 00:11:56 +02:00
|
|
|
if (((Player) sender).hasMetadata(mcMMO.databaseCommandKey)) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Database.Processing"));
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
((Player) sender).setMetadata(mcMMO.databaseCommandKey, new FixedMetadataValue(mcMMO.p, null));
|
|
|
|
}
|
|
|
|
|
2013-10-28 18:04:06 +01:00
|
|
|
mcMMOPlayer.actualizeDatabaseATS();
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-09-12 04:42:27 +02:00
|
|
|
|
|
|
|
display(page, skill, sender);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-09-12 04:42:27 +02:00
|
|
|
private void display(int page, SkillType skill, CommandSender sender) {
|
|
|
|
boolean useBoard = (sender instanceof Player) && (Config.getInstance().getTopUseBoard());
|
2014-01-20 22:58:40 +01:00
|
|
|
boolean useChat = !useBoard || Config.getInstance().getTopUseChat();
|
2013-09-12 04:42:27 +02:00
|
|
|
|
|
|
|
new MctopCommandAsyncTask(page, skill, sender, useBoard, useChat).runTaskAsynchronously(mcMMO.p);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-12 21:25:42 +01:00
|
|
|
|
2013-10-28 19:14:20 +01:00
|
|
|
private SkillType extractSkill(CommandSender sender, String skillName) {
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.isInvalidSkill(sender, skillName)) {
|
2013-10-28 19:14:20 +01:00
|
|
|
return null;
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:14:20 +01:00
|
|
|
SkillType skill = SkillType.getSkill(skillName);
|
2013-10-28 18:04:06 +01:00
|
|
|
|
|
|
|
if (CommandUtils.isChildSkill(sender, skill)) {
|
2013-10-28 19:14:20 +01:00
|
|
|
return null;
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
|
|
|
|
2013-10-28 19:14:20 +01:00
|
|
|
return skill;
|
2013-03-12 21:25:42 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|