mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Add checks for loaded/unloaded profiles in commands
This commit is contained in:
parent
1503e58d11
commit
a3943aab24
@ -29,6 +29,10 @@ public class KrakenCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
UserManager.getPlayer(sender.getName()).getFishingManager().unleashTheKraken();
|
UserManager.getPlayer(sender.getName()).getFishingManager().unleashTheKraken();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -37,6 +37,10 @@ public class MobhealthCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
try {
|
try {
|
||||||
|
@ -28,6 +28,10 @@ public abstract class ToggleCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
applyCommandAction(UserManager.getPlayer(sender.getName()));
|
applyCommandAction(UserManager.getPlayer(sender.getName()));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -41,6 +41,10 @@ public abstract class ChatCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||||
|
|
||||||
if (mcMMOPlayer.isChatEnabled(chatMode)) {
|
if (mcMMOPlayer.isChatEnabled(chatMode)) {
|
||||||
@ -53,6 +57,10 @@ public abstract class ChatCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (CommandUtils.shouldEnableToggle(args[0])) {
|
if (CommandUtils.shouldEnableToggle(args[0])) {
|
||||||
if (CommandUtils.noConsoleUsage(sender)) {
|
if (CommandUtils.noConsoleUsage(sender)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -71,6 +71,11 @@ public class PartyCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
if (!UserManager.hasPlayerDataKey(player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
|
@ -42,6 +42,11 @@ public class PtpCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
if (!UserManager.hasPlayerDataKey(player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
if (!mcMMOPlayer.inParty()) {
|
if (!mcMMOPlayer.inParty()) {
|
||||||
|
@ -34,6 +34,10 @@ public class InspectCommand implements TabExecutor {
|
|||||||
if (mcMMOPlayer == null) {
|
if (mcMMOPlayer == null) {
|
||||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); // Temporary Profile
|
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false); // Temporary Profile
|
||||||
|
|
||||||
|
if (!CommandUtils.isLoaded(sender, profile)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
|
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,10 @@ public class MccooldownCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
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.Permissions;
|
||||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class McrankCommand implements TabExecutor {
|
public class McrankCommand implements TabExecutor {
|
||||||
@ -35,6 +35,10 @@ public class McrankCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
display(sender, sender.getName());
|
display(sender, sender.getName());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -45,6 +49,10 @@ public class McrankCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
|
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
|
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
|
||||||
|
|
||||||
|
@ -22,6 +22,10 @@ public class McstatsCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
@ -83,6 +83,10 @@ public class MctopCommand implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
||||||
long cooldownMillis = Math.max(Config.getInstance().getDatabasePlayerCooldown(), 1750);
|
long cooldownMillis = Math.max(Config.getInstance().getDatabasePlayerCooldown(), 1750);
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@ public abstract class SkillCommand implements TabExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
@ -116,6 +116,29 @@ public final class CommandUtils {
|
|||||||
return true;
|
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) {
|
public static boolean isInvalidInteger(CommandSender sender, String value) {
|
||||||
if (StringUtils.isInt(value)) {
|
if (StringUtils.isInt(value)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -498,6 +498,7 @@ Commands.NoConsole=This command does not support console usage.
|
|||||||
Commands.Notifications.Off=Ability notifications toggled [[RED]]off
|
Commands.Notifications.Off=Ability notifications toggled [[RED]]off
|
||||||
Commands.Notifications.On=Ability notifications toggled [[GREEN]]on
|
Commands.Notifications.On=Ability notifications toggled [[GREEN]]on
|
||||||
Commands.Offline=[[RED]]This command does not work for offline players.
|
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.Other=[[RED]]---[][[GREEN]]OTHER COMMANDS[[RED]][]---
|
||||||
Commands.Party.Header=[[RED]]-----[][[GREEN]]PARTY[[RED]][]-----
|
Commands.Party.Header=[[RED]]-----[][[GREEN]]PARTY[[RED]][]-----
|
||||||
Commands.Party.Features.Header=[[RED]]-----[][[GREEN]]FEATURES[[RED]][]-----
|
Commands.Party.Features.Header=[[RED]]-----[][[GREEN]]FEATURES[[RED]][]-----
|
||||||
|
Loading…
Reference in New Issue
Block a user