summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java47
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()));
}
+
+
}