From 749443454d72878c7f6ce232094b6688fa3d0d29 Mon Sep 17 00:00:00 2001 From: Glitchfinder Date: Fri, 1 Feb 2013 14:01:11 -0800 Subject: [PATCH] Updating permissions for the /mcgod command. --- .../nossr50/commands/admin/McgodCommand.java | 84 ++++++++++++++----- .../com/gmail/nossr50/util/Permissions.java | 13 ++- src/main/resources/plugin.yml | 8 ++ 3 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/admin/McgodCommand.java b/src/main/java/com/gmail/nossr50/commands/admin/McgodCommand.java index ecddf0328..6446d3cd1 100644 --- a/src/main/java/com/gmail/nossr50/commands/admin/McgodCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/admin/McgodCommand.java @@ -5,38 +5,80 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class McgodCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (CommandHelper.noConsoleUsage(sender)) { + PlayerProfile profile; + + switch (args.length) { + case 0: + if (CommandHelper.noConsoleUsage(sender)) { + return true; + } + + if (!Permissions.mcgodCommand(sender)) { + return true; + } + + profile = Users.getProfile((Player) sender); + + if (profile == null) { + sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); + return true; + } + + if (profile.getGodMode()) { + sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled")); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled")); + } + + profile.toggleGodMode(); return true; - } + case 1: + if (!Permissions.hasPermission(sender, "mcmmo.commands.mcgod.others")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]); - if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mcgod")) { + // If the mcMMOPlayer doesn't exist, create a temporary profile and + // check if it's present in the database. If it's not, abort the process. + if (mcMMOPlayer == null) { + profile = new PlayerProfile(args[0], false); + + if (!profile.isLoaded()) { + sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); + return true; + } + } + else { + profile = mcMMOPlayer.getProfile(); + Player player = mcMMOPlayer.getPlayer(); + + // Check if the player is online before we try to send them a message. + if (player.isOnline()) { + if (profile.getGodMode()) { + player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled")); + } + else { + player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled")); + } + } + } + + profile.toggleGodMode(); return true; + default: + return false; } - - PlayerProfile profile = Users.getProfile((Player) sender); - - if (profile == null) { - sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); - return true; - } - - if (profile.getGodMode()) { - sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled")); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled")); - } - - profile.toggleGodMode(); - - return true; } } diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index 7807d3211..51ff5b16a 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -83,8 +83,12 @@ public final class Permissions { return hasPermission(sender, "mcmmo.tools.mmoedit"); } - public static boolean mcgod(Player player) { - return hasPermission(player, "mcmmo.tools.mcgod"); + /** + * @deprecated Use {@link #mcgodCommand(player)} instead. + */ + @Deprecated + public static boolean mcgod(CommandSender sender) { + return hasPermission(sender, "mcmmo.tools.mcgod"); } /* @@ -568,6 +572,10 @@ public final class Permissions { return (hasPermission(player, "mcmmo.commands.mcability") || mcAbility(player)); } + public static boolean mcgodCommand(CommandSender sender) { + return (hasPermission(sender, "mcmmo.commands.mcgod")); + } + /** * @deprecated Use {@link #mcAbilityCommand(player)} instead. */ @@ -596,7 +604,6 @@ public final class Permissions { return hasPermission(player, "mcmmo.skillreset"); } - /* * MCMMO.CHAT.* */ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 48c7e6158..2819b5ef6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -337,6 +337,8 @@ permissions: description: Allows access to mmoedit command mcmmo.tools.mcgod: description: Allows access to mcgod command + children: + mcmmo.commands.mcgod: true mcmmo.tools.mcremove: decription: Allows access to mcremove and mcpurge command mcmmo.ability.*: @@ -698,6 +700,8 @@ permissions: mcmmo.commands.inspect.far: true mcmmo.commands.inspect.offline: true mcmmo.commands.mcability.others: true + mcmmo.commands.mcgod: true + mcmmo.commands.mcgod.others: true mcmmo.commands.mmoedit: true mcmmo.commands.mmoedit.others: true mcmmo.commands.mmoupdate: true @@ -742,6 +746,10 @@ permissions: description: Allows access to the mcability command mcmmo.commands.mcability.others: description: Allows access to the mcability command for other players + mcmmo.commands.mcgod: + description: Allows access to the mcgod command + mcmmo.commands.mcgod.others: + description: Allows access to the mcgod command for other players mcmmo.commands.mmoedit: description: Allows access to the mmoedit command mcmmo.commands.mmoedit.others: