diff options
author | KHobbits <rob@khobbits.co.uk> | 2011-11-18 12:08:27 +0000 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2011-11-18 12:08:27 +0000 |
commit | a9b77b34868ac2bf7576b11c99699ad1c34c98d1 (patch) | |
tree | db580b7268251f7926e40afb325f885a31cd5a56 | |
parent | 37bd9bc9b57de2636fd93d430f56890c62cab8d8 (diff) | |
download | Essentials-a9b77b34868ac2bf7576b11c99699ad1c34c98d1.tar Essentials-a9b77b34868ac2bf7576b11c99699ad1c34c98d1.tar.gz Essentials-a9b77b34868ac2bf7576b11c99699ad1c34c98d1.tar.lz Essentials-a9b77b34868ac2bf7576b11c99699ad1c34c98d1.tar.xz Essentials-a9b77b34868ac2bf7576b11c99699ad1c34c98d1.zip |
Updating gamemode to allow essentials.gamemode.other.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java index b19aa5d14..f8cfdf81c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java @@ -16,28 +16,43 @@ public class Commandgamemode extends EssentialsCommand } @Override - public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - Player player; - if (args.length == 0) + if (args.length < 1) { - if (sender instanceof Player) - { - player = ess.getUser(sender); } - else - { - throw new NotEnoughArgumentsException(); - } + throw new NotEnoughArgumentsException(); } - else + + gamemodeOtherPlayers(server, sender, args[0]); + } + + @Override + protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + { + if (args.length > 0 && user.isAuthorized("essentials.gamemode.others")) { - player = server.getPlayer(args[0]); - if (player == null) + gamemodeOtherPlayers(server, user, args[0]); + return; + } + + user.setGameMode(user.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL); + user.sendMessage(Util.format("gameMode", Util.i18n(user.getGameMode().toString().toLowerCase()), user.getDisplayName())); + } + + private void gamemodeOtherPlayers(final Server server, final CommandSender sender, final String name) + { + for (Player matchPlayer : server.matchPlayer(name)) + { + final User player = ess.getUser(matchPlayer); + if (player.isHidden()) { - throw new Exception(Util.i18n("playerNotFound")); + continue; } + + player.setGameMode(player.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL); + sender.sendMessage(Util.format("gameMode", Util.i18n(player.getGameMode().toString().toLowerCase()), player.getDisplayName())); } - player.setGameMode(player.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL); - sender.sendMessage(Util.format("gameMode", Util.i18n(player.getGameMode().toString().toLowerCase()), player.getDisplayName())); } + + } |