2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.player;
|
|
|
|
|
|
|
|
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;
|
2018-07-15 16:08:52 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
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;
|
2018-07-15 16:08:52 +02:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.TabExecutor;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.metadata.FixedMetadataValue;
|
|
|
|
import org.bukkit.util.StringUtil;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
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()) {
|
2018-07-15 16:08:52 +02:00
|
|
|
double seconds = ((mcMMOPlayer.getDatabaseATS() + cooldownMillis) - System.currentTimeMillis()) / 1000;
|
|
|
|
if (seconds < 1) {
|
|
|
|
seconds = 1;
|
|
|
|
}
|
|
|
|
|
2018-07-27 01:52:15 +02:00
|
|
|
sender.sendMessage(LocaleLoader.formatString(LocaleLoader.getString("Commands.Database.Cooldown"), seconds));
|
2013-09-12 04:42:27 +02:00
|
|
|
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
|
|
|
}
|