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
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 (sender instanceof Player)
{
player = ess.getUser(sender); }
else
if (args.length < 1)
{
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 (player == null)
if (args.length > 0 && user.isAuthorized("essentials.gamemode.others"))
{
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);
sender.sendMessage(Util.format("gameMode", Util.i18n(player.getGameMode().toString().toLowerCase()), player.getDisplayName()));
}
}
}