2011-11-03 23:33:04 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-11-03 23:33:04 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.util.Locale;
|
2011-11-03 23:33:04 +00:00
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandgamemode extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandgamemode()
|
|
|
|
{
|
|
|
|
super("gamemode");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-11-18 12:08:27 +00:00
|
|
|
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
2011-11-03 23:33:04 +00:00
|
|
|
{
|
2012-08-02 12:48:13 +00:00
|
|
|
if (args.length < 2)
|
2011-11-03 23:33:04 +00:00
|
|
|
{
|
2011-11-18 12:08:27 +00:00
|
|
|
throw new NotEnoughArgumentsException();
|
2011-11-03 23:33:04 +00:00
|
|
|
}
|
2012-04-02 01:31:07 +00:00
|
|
|
gamemodeOtherPlayers(server, sender, args);
|
2011-11-18 12:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
|
|
|
{
|
2012-08-03 08:39:45 +00:00
|
|
|
if (args.length < 1)
|
2012-08-02 12:48:13 +00:00
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2012-08-03 08:39:45 +00:00
|
|
|
|
2012-08-04 11:17:41 +00:00
|
|
|
if (args.length > 1 && args[1].trim().length() > 2 && user.isAuthorized("essentials.gamemode.others"))
|
2011-11-03 23:33:04 +00:00
|
|
|
{
|
2012-04-02 01:31:07 +00:00
|
|
|
gamemodeOtherPlayers(server, user, args);
|
2011-11-18 12:08:27 +00:00
|
|
|
return;
|
2012-08-03 08:39:45 +00:00
|
|
|
}
|
2012-08-03 08:41:23 +00:00
|
|
|
performSetMode(args[0].toLowerCase(Locale.ENGLISH), user);
|
2011-11-21 01:55:26 +00:00
|
|
|
user.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
|
2011-11-18 12:08:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-12 00:12:10 +00:00
|
|
|
private void gamemodeOtherPlayers(final Server server, final CommandSender sender, final String[] args) throws NotEnoughArgumentsException
|
2011-11-18 12:08:27 +00:00
|
|
|
{
|
2012-08-12 00:12:10 +00:00
|
|
|
//TODO: TL this
|
|
|
|
if (args[1].trim().length() < 2)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException("You need to specify a valid player/mode.");
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean foundUser = false;
|
2012-08-02 16:43:58 +00:00
|
|
|
for (Player matchPlayer : server.matchPlayer(args[1]))
|
2011-11-18 12:08:27 +00:00
|
|
|
{
|
|
|
|
final User player = ess.getUser(matchPlayer);
|
|
|
|
if (player.isHidden())
|
2011-11-03 23:33:04 +00:00
|
|
|
{
|
2011-11-18 12:08:27 +00:00
|
|
|
continue;
|
2012-08-03 08:39:45 +00:00
|
|
|
}
|
2012-08-03 08:41:23 +00:00
|
|
|
performSetMode(args[0].toLowerCase(Locale.ENGLISH), player);
|
2012-08-02 12:48:13 +00:00
|
|
|
sender.sendMessage(_("gameMode", _(player.getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName()));
|
2012-08-12 00:12:10 +00:00
|
|
|
foundUser = true;
|
|
|
|
}
|
|
|
|
if (!foundUser)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException(_("playerNotFound"));
|
2012-08-02 12:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 08:39:45 +00:00
|
|
|
|
2012-08-02 12:48:13 +00:00
|
|
|
private void performSetMode(String mode, Player player)
|
|
|
|
{
|
2012-08-03 08:39:45 +00:00
|
|
|
if (mode.contains("survi") || mode.equalsIgnoreCase("0") || mode.equalsIgnoreCase("s"))
|
|
|
|
{
|
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
|
|
|
}
|
|
|
|
else if (mode.contains("creat") || mode.equalsIgnoreCase("1") || mode.equalsIgnoreCase("c"))
|
|
|
|
{
|
|
|
|
player.setGameMode(GameMode.CREATIVE);
|
|
|
|
}
|
|
|
|
else if (mode.contains("advent") || mode.equalsIgnoreCase("2") || mode.equalsIgnoreCase("a"))
|
|
|
|
{
|
|
|
|
player.setGameMode(GameMode.ADVENTURE);
|
|
|
|
}
|
2011-11-03 23:33:04 +00:00
|
|
|
}
|
2012-08-02 12:48:13 +00:00
|
|
|
}
|