Updating gamemode to allow essentials.gamemode.other.

This commit is contained in:
KHobbits 2011-11-18 12:08:27 +00:00
parent 37bd9bc9b5
commit a9b77b3486

View File

@ -16,28 +16,43 @@ public class Commandgamemode extends EssentialsCommand
} }
@Override @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 < 1)
if (args.length == 0)
{
if (sender instanceof Player)
{
player = ess.getUser(sender); }
else
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
gamemodeOtherPlayers(server, sender, args[0]);
} }
else
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{ {
player = server.getPlayer(args[0]); if (args.length > 0 && user.isAuthorized("essentials.gamemode.others"))
if (player == null)
{ {
throw new Exception(Util.i18n("playerNotFound")); 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())
{
continue;
}
player.setGameMode(player.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL); player.setGameMode(player.getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL);
sender.sendMessage(Util.format("gameMode", Util.i18n(player.getGameMode().toString().toLowerCase()), player.getDisplayName())); sender.sendMessage(Util.format("gameMode", Util.i18n(player.getGameMode().toString().toLowerCase()), player.getDisplayName()));
} }
} }
}