Add checks for loaded/unloaded profiles in commands

This commit is contained in:
TfT_02 2014-08-19 22:23:19 -06:00
parent 1503e58d11
commit a3943aab24
14 changed files with 83 additions and 1 deletions

View File

@ -29,6 +29,10 @@ public class KrakenCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
UserManager.getPlayer(sender.getName()).getFishingManager().unleashTheKraken();
return true;

View File

@ -37,6 +37,10 @@ public class MobhealthCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
switch (args.length) {
case 1:
try {

View File

@ -28,6 +28,10 @@ public abstract class ToggleCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
applyCommandAction(UserManager.getPlayer(sender.getName()));
return true;

View File

@ -41,6 +41,10 @@ public abstract class ChatCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
mcMMOPlayer = UserManager.getPlayer(sender.getName());
if (mcMMOPlayer.isChatEnabled(chatMode)) {
@ -53,6 +57,10 @@ public abstract class ChatCommand implements TabExecutor {
return true;
case 1:
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
if (CommandUtils.shouldEnableToggle(args[0])) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;

View File

@ -71,6 +71,11 @@ public class PartyCommand implements TabExecutor {
}
Player player = (Player) sender;
if (!UserManager.hasPlayerDataKey(player)) {
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (args.length < 1) {

View File

@ -42,6 +42,11 @@ public class PtpCommand implements TabExecutor {
}
Player player = (Player) sender;
if (!UserManager.hasPlayerDataKey(player)) {
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.inParty()) {

View File

@ -34,6 +34,10 @@ public class InspectCommand implements TabExecutor {
if (mcMMOPlayer == null) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); // Temporary Profile
if (!CommandUtils.isLoaded(sender, profile)) {
return true;
}
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
return true;
}

View File

@ -24,6 +24,10 @@ public class MccooldownCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;

View File

@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.util.StringUtil;
import com.gmail.nossr50.mcMMO;
@ -19,6 +18,7 @@ import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
public class McrankCommand implements TabExecutor {
@ -35,6 +35,10 @@ public class McrankCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
display(sender, sender.getName());
return true;
@ -45,6 +49,10 @@ public class McrankCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);

View File

@ -22,6 +22,10 @@ public class McstatsCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;

View File

@ -83,6 +83,10 @@ public class MctopCommand implements TabExecutor {
}
if (sender instanceof Player) {
if (!CommandUtils.hasPlayerDataKey(sender)) {
return;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
long cooldownMillis = Math.max(Config.getInstance().getDatabasePlayerCooldown(), 1750);

View File

@ -48,6 +48,10 @@ public abstract class SkillCommand implements TabExecutor {
return true;
}
if (!CommandUtils.hasPlayerDataKey(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;

View File

@ -116,6 +116,29 @@ public final class CommandUtils {
return true;
}
public static boolean hasPlayerDataKey(CommandSender sender) {
if (sender == null || !(sender instanceof Player)) {
return false;
}
boolean hasPlayerDataKey = ((Player) sender).hasMetadata(mcMMO.playerDataKey);
if (!hasPlayerDataKey) {
sender.sendMessage(LocaleLoader.getString("Commands.NotLoaded"));
}
return hasPlayerDataKey;
}
public static boolean isLoaded(CommandSender sender, PlayerProfile profile) {
if (profile.isLoaded()) {
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.NotLoaded"));
return false;
}
public static boolean isInvalidInteger(CommandSender sender, String value) {
if (StringUtils.isInt(value)) {
return false;

View File

@ -498,6 +498,7 @@ Commands.NoConsole=This command does not support console usage.
Commands.Notifications.Off=Ability notifications toggled [[RED]]off
Commands.Notifications.On=Ability notifications toggled [[GREEN]]on
Commands.Offline=[[RED]]This command does not work for offline players.
Commands.NotLoaded=[[RED]]Player profile is not loaded yet.
Commands.Other=[[RED]]---[][[GREEN]]OTHER COMMANDS[[RED]][]---
Commands.Party.Header=[[RED]]-----[][[GREEN]]PARTY[[RED]][]-----
Commands.Party.Features.Header=[[RED]]-----[][[GREEN]]FEATURES[[RED]][]-----