2013-03-01 00:52:01 -05:00
|
|
|
package com.gmail.nossr50.util.commands;
|
|
|
|
|
2013-03-28 12:57:49 -04:00
|
|
|
import java.util.List;
|
|
|
|
|
2013-03-01 00:52:01 -05:00
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2013-05-16 19:31:12 -04:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-03-12 16:25:42 -04:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-01 00:52:01 -05:00
|
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-03-12 16:25:42 -04:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-03-01 00:52:01 -05:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-03-12 16:25:42 -04:00
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2013-03-01 00:52:01 -05:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
2013-03-28 12:57:49 -04:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
2013-03-01 00:52:01 -05:00
|
|
|
public final class CommandUtils {
|
2013-03-28 12:57:49 -04:00
|
|
|
public static final List<String> TRUE_FALSE_OPTIONS = ImmutableList.of("on", "off", "true", "false", "enabled", "disabled");
|
|
|
|
public static final List<String> RESET_OPTIONS = ImmutableList.of("clear", "reset");
|
|
|
|
|
2013-03-01 00:52:01 -05:00
|
|
|
private CommandUtils() {}
|
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
public static boolean isChildSkill(CommandSender sender, SkillType skill) {
|
|
|
|
if (!skill.isChildSkill()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage("Child skills are not supported by this command."); // TODO: Localize this
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean inspectOffline(CommandSender sender, PlayerProfile profile, boolean hasPermission) {
|
|
|
|
if (unloadedProfile(sender, profile)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasPermission) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
|
2013-03-01 00:52:01 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
public static boolean tooFar(CommandSender sender, Player target, boolean hasPermission) {
|
2013-05-16 19:31:12 -04:00
|
|
|
if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), Config.getInstance().getInspectDistance()) && !hasPermission) {
|
2013-03-12 16:25:42 -04:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-02 12:42:18 +02:00
|
|
|
public static boolean hidden(CommandSender sender, Player target, boolean hasPermission) {
|
2013-06-03 15:33:23 +02:00
|
|
|
if (sender instanceof Player && !((Player)sender).canSee(target) && !hasPermission) {
|
2013-06-02 12:42:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
public static boolean noConsoleUsage(CommandSender sender) {
|
|
|
|
if (sender instanceof Player) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.NoConsole"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isOffline(CommandSender sender, Player player) {
|
|
|
|
if (player.isOnline()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean checkPlayerExistence(CommandSender sender, String playerName, McMMOPlayer mcMMOPlayer) {
|
|
|
|
if (mcMMOPlayer != null) {
|
2013-03-21 22:04:52 +01:00
|
|
|
return true;
|
2013-03-12 16:25:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PlayerProfile playerProfile = new PlayerProfile(playerName, false);
|
|
|
|
|
|
|
|
if (unloadedProfile(sender, playerProfile)) {
|
2013-03-21 22:04:52 +01:00
|
|
|
return false;
|
2013-03-12 16:25:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
|
2013-03-21 22:04:52 +01:00
|
|
|
return false;
|
2013-03-12 16:25:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean unloadedProfile(CommandSender sender, PlayerProfile profile) {
|
|
|
|
if (profile.isLoaded()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInvalidInteger(CommandSender sender, String value) {
|
|
|
|
if (StringUtils.isInt(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage("That is not a valid integer."); // TODO: Localize
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInvalidDouble(CommandSender sender, String value) {
|
|
|
|
if (StringUtils.isDouble(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage("That is not a valid percentage."); // TODO: Localize
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isInvalidSkill(CommandSender sender, String skillName) {
|
|
|
|
if (SkillUtils.isSkill(skillName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean shouldEnableToggle(String arg) {
|
|
|
|
return arg.equalsIgnoreCase("on") || arg.equalsIgnoreCase("true") || arg.equalsIgnoreCase("enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean shouldDisableToggle(String arg) {
|
|
|
|
return arg.equalsIgnoreCase("off") || arg.equalsIgnoreCase("false") || arg.equalsIgnoreCase("disabled");
|
|
|
|
}
|
|
|
|
|
2013-03-01 00:52:01 -05:00
|
|
|
/**
|
|
|
|
* Print out details on Gathering skills. Only for online players.
|
|
|
|
*
|
|
|
|
* @param inspect The player to retrieve stats for
|
|
|
|
* @param display The sender to display stats to
|
|
|
|
*/
|
2013-03-12 16:25:42 -04:00
|
|
|
public static void printGatheringSkills(Player inspect, CommandSender display) {
|
2013-03-01 00:52:01 -05:00
|
|
|
if (SkillUtils.hasGatheringSkills(inspect)) {
|
2013-03-12 16:25:42 -04:00
|
|
|
PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
display.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
|
|
|
|
displaySkill(inspect, profile, SkillType.EXCAVATION, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.FISHING, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.HERBALISM, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.MINING, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.WOODCUTTING, display);
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
public static void printGatheringSkills(Player player) {
|
|
|
|
printGatheringSkills(player, player);
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print out details on Combat skills. Only for online players.
|
|
|
|
*
|
|
|
|
* @param inspect The player to retrieve stats for
|
|
|
|
* @param display The sender to display stats to
|
|
|
|
*/
|
2013-03-12 16:25:42 -04:00
|
|
|
public static void printCombatSkills(Player inspect, CommandSender display) {
|
2013-03-01 00:52:01 -05:00
|
|
|
if (SkillUtils.hasCombatSkills(inspect)) {
|
2013-03-12 16:25:42 -04:00
|
|
|
PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
display.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
|
|
|
|
displaySkill(inspect, profile, SkillType.AXES, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.ARCHERY, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.SWORDS, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.TAMING, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.UNARMED, display);
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
public static void printCombatSkills(Player player) {
|
|
|
|
printCombatSkills(player, player);
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print out details on Misc skills. Only for online players.
|
|
|
|
*
|
|
|
|
* @param inspect The player to retrieve stats for
|
|
|
|
* @param display The sender to display stats to
|
|
|
|
*/
|
2013-03-12 16:25:42 -04:00
|
|
|
public static void printMiscSkills(Player inspect, CommandSender display) {
|
2013-03-01 00:52:01 -05:00
|
|
|
if (SkillUtils.hasMiscSkills(inspect)) {
|
2013-03-12 16:25:42 -04:00
|
|
|
PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
|
|
|
|
|
2013-03-01 00:52:01 -05:00
|
|
|
display.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
|
2013-03-12 16:25:42 -04:00
|
|
|
displaySkill(inspect, profile, SkillType.ACROBATICS, display);
|
|
|
|
displaySkill(inspect, profile, SkillType.REPAIR, display);
|
|
|
|
}
|
|
|
|
}
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
public static void printMiscSkills(Player player) {
|
|
|
|
printMiscSkills(player, player);
|
|
|
|
}
|
2013-03-01 00:52:01 -05:00
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
private static void displaySkill(Player player, PlayerProfile profile, SkillType skill, CommandSender display) {
|
|
|
|
if (Permissions.skillEnabled(player, skill)) {
|
|
|
|
displaySkill(display, profile, skill);
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 16:25:42 -04:00
|
|
|
public static void displaySkill(CommandSender sender, PlayerProfile profile, SkillType skill) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener"), profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)));
|
2013-03-01 00:52:01 -05:00
|
|
|
}
|
|
|
|
}
|