|
@@ -3,120 +3,200 @@ package com.gmail.nossr50.util.commands;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
+import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
+import com.gmail.nossr50.util.Misc;
|
|
import com.gmail.nossr50.util.Permissions;
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
+import com.gmail.nossr50.util.StringUtils;
|
|
|
|
+import com.gmail.nossr50.util.player.UserManager;
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
|
public final class CommandUtils {
|
|
public final class CommandUtils {
|
|
private CommandUtils() {}
|
|
private CommandUtils() {}
|
|
|
|
|
|
- public static boolean noConsoleUsage(CommandSender sender) {
|
|
|
|
- if (!(sender instanceof Player)) {
|
|
|
|
- sender.sendMessage(LocaleLoader.getString("Commands.NoConsole"));
|
|
|
|
|
|
+ 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"));
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static boolean tooFar(CommandSender sender, Player target, boolean hasPermission) {
|
|
|
|
+ if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !hasPermission) {
|
|
|
|
+ sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PlayerProfile playerProfile = new PlayerProfile(playerName, false);
|
|
|
|
+
|
|
|
|
+ if (unloadedProfile(sender, playerProfile)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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");
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Print out details on Gathering skills. Only for online players.
|
|
* Print out details on Gathering skills. Only for online players.
|
|
*
|
|
*
|
|
* @param inspect The player to retrieve stats for
|
|
* @param inspect The player to retrieve stats for
|
|
- * @param profile The player's profile
|
|
|
|
* @param display The sender to display stats to
|
|
* @param display The sender to display stats to
|
|
*/
|
|
*/
|
|
- public static void printGatheringSkills(Player inspect, PlayerProfile profile, CommandSender display) {
|
|
|
|
|
|
+ public static void printGatheringSkills(Player inspect, CommandSender display) {
|
|
if (SkillUtils.hasGatheringSkills(inspect)) {
|
|
if (SkillUtils.hasGatheringSkills(inspect)) {
|
|
- display.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.EXCAVATION)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Excavation.Listener"), profile.getSkillLevel(SkillType.EXCAVATION), profile.getSkillXpLevel(SkillType.EXCAVATION), profile.getXpToLevel(SkillType.EXCAVATION)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.FISHING)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Fishing.Listener"), profile.getSkillLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING), profile.getXpToLevel(SkillType.FISHING)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.HERBALISM)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Herbalism.Listener"), profile.getSkillLevel(SkillType.HERBALISM), profile.getSkillXpLevel(SkillType.HERBALISM), profile.getXpToLevel(SkillType.HERBALISM)));
|
|
|
|
- }
|
|
|
|
|
|
+ PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
|
|
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.MINING)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Mining.Listener"), profile.getSkillLevel(SkillType.MINING), profile.getSkillXpLevel(SkillType.MINING), profile.getXpToLevel(SkillType.MINING)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.WOODCUTTING)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Woodcutting.Listener"), profile.getSkillLevel(SkillType.WOODCUTTING), profile.getSkillXpLevel(SkillType.WOODCUTTING), profile.getXpToLevel(SkillType.WOODCUTTING)));
|
|
|
|
- }
|
|
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void printGatheringSkills(Player player, PlayerProfile profile) {
|
|
|
|
- printGatheringSkills(player, profile, player);
|
|
|
|
|
|
+ public static void printGatheringSkills(Player player) {
|
|
|
|
+ printGatheringSkills(player, player);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Print out details on Combat skills. Only for online players.
|
|
* Print out details on Combat skills. Only for online players.
|
|
*
|
|
*
|
|
* @param inspect The player to retrieve stats for
|
|
* @param inspect The player to retrieve stats for
|
|
- * @param profile The player's profile
|
|
|
|
* @param display The sender to display stats to
|
|
* @param display The sender to display stats to
|
|
*/
|
|
*/
|
|
- public static void printCombatSkills(Player inspect, PlayerProfile profile, CommandSender display) {
|
|
|
|
|
|
+ public static void printCombatSkills(Player inspect, CommandSender display) {
|
|
if (SkillUtils.hasCombatSkills(inspect)) {
|
|
if (SkillUtils.hasCombatSkills(inspect)) {
|
|
- display.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.AXES)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Axes.Listener"), profile.getSkillLevel(SkillType.AXES), profile.getSkillXpLevel(SkillType.AXES), profile.getXpToLevel(SkillType.AXES)));
|
|
|
|
- }
|
|
|
|
|
|
+ PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
|
|
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.ARCHERY)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Archery.Listener"), profile.getSkillLevel(SkillType.ARCHERY), profile.getSkillXpLevel(SkillType.ARCHERY), profile.getXpToLevel(SkillType.ARCHERY)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.SWORDS)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Swords.Listener"), profile.getSkillLevel(SkillType.SWORDS), profile.getSkillXpLevel(SkillType.SWORDS), profile.getXpToLevel(SkillType.SWORDS)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.TAMING)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Taming.Listener"), profile.getSkillLevel(SkillType.TAMING), profile.getSkillXpLevel(SkillType.TAMING), profile.getXpToLevel(SkillType.TAMING)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.UNARMED)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Unarmed.Listener"), profile.getSkillLevel(SkillType.UNARMED), profile.getSkillXpLevel(SkillType.UNARMED), profile.getXpToLevel(SkillType.UNARMED)));
|
|
|
|
- }
|
|
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void printCombatSkills(Player player, PlayerProfile profile) {
|
|
|
|
- printCombatSkills(player, profile, player);
|
|
|
|
|
|
+ public static void printCombatSkills(Player player) {
|
|
|
|
+ printCombatSkills(player, player);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Print out details on Misc skills. Only for online players.
|
|
* Print out details on Misc skills. Only for online players.
|
|
*
|
|
*
|
|
* @param inspect The player to retrieve stats for
|
|
* @param inspect The player to retrieve stats for
|
|
- * @param profile The player's profile
|
|
|
|
* @param display The sender to display stats to
|
|
* @param display The sender to display stats to
|
|
*/
|
|
*/
|
|
- public static void printMiscSkills(Player inspect, PlayerProfile profile, CommandSender display) {
|
|
|
|
|
|
+ public static void printMiscSkills(Player inspect, CommandSender display) {
|
|
if (SkillUtils.hasMiscSkills(inspect)) {
|
|
if (SkillUtils.hasMiscSkills(inspect)) {
|
|
|
|
+ PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
|
|
|
|
+
|
|
display.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
|
|
display.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
|
|
|
|
+ displaySkill(inspect, profile, SkillType.ACROBATICS, display);
|
|
|
|
+ displaySkill(inspect, profile, SkillType.REPAIR, display);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.ACROBATICS)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Acrobatics.Listener"), profile.getSkillLevel(SkillType.ACROBATICS), profile.getSkillXpLevel(SkillType.ACROBATICS), profile.getXpToLevel(SkillType.ACROBATICS)));
|
|
|
|
- }
|
|
|
|
|
|
+ public static void printMiscSkills(Player player) {
|
|
|
|
+ printMiscSkills(player, player);
|
|
|
|
+ }
|
|
|
|
|
|
- if (Permissions.skillEnabled(inspect, SkillType.REPAIR)) {
|
|
|
|
- display.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Repair.Listener"), profile.getSkillLevel(SkillType.REPAIR), profile.getSkillXpLevel(SkillType.REPAIR), profile.getXpToLevel(SkillType.REPAIR)));
|
|
|
|
- }
|
|
|
|
|
|
+ private static void displaySkill(Player player, PlayerProfile profile, SkillType skill, CommandSender display) {
|
|
|
|
+ if (Permissions.skillEnabled(player, skill)) {
|
|
|
|
+ displaySkill(display, profile, skill);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void printMiscSkills(Player player, PlayerProfile profile) {
|
|
|
|
- printMiscSkills(player, profile, player);
|
|
|
|
|
|
+ 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)));
|
|
}
|
|
}
|
|
}
|
|
}
|