TotalFreedomMod/src/me/StevenLawson/TotalFreedomMod/Commands/Command_survival.java

80 lines
2.6 KiB
Java
Raw Normal View History

2011-10-19 00:37:00 +00:00
package me.StevenLawson.TotalFreedomMod.Commands;
2012-11-13 01:42:30 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
2013-06-09 19:52:13 +00:00
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
2011-10-19 00:37:00 +00:00
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.BOTH)
@CommandParameters(description = "Quickly change your own gamemode to survival, or define someone's username to change theirs.", usage = "/<command> <[partialname] | -a>")
2011-10-19 00:37:00 +00:00
public class Command_survival extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (senderIsConsole)
{
if (args.length == 0)
{
playerMsg("When used from the console, you must define a target user to change gamemode on.");
2011-10-19 00:37:00 +00:00
return true;
}
}
2011-10-19 00:37:00 +00:00
Player p;
2013-06-09 19:52:13 +00:00
2011-10-19 00:37:00 +00:00
if (args.length == 0)
{
p = sender_p;
2011-10-19 00:37:00 +00:00
}
else
{
if (args[0].equalsIgnoreCase("-a"))
{
if (!TFM_SuperadminList.isUserSuperadmin(sender) || senderIsConsole)
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
for (Player player : server.getOnlinePlayers())
{
player.setGameMode(GameMode.SURVIVAL);
}
TFM_Util.adminAction(sender.getName(), "Changing everyone's gamemode to survival", false);
return true;
}
2012-11-13 01:42:30 +00:00
if (senderIsConsole || TFM_SuperadminList.isUserSuperadmin(sender))
2011-10-19 00:37:00 +00:00
{
try
{
p = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true;
}
2011-10-19 00:37:00 +00:00
}
else
2011-10-19 00:37:00 +00:00
{
playerMsg("Only superadmins can change other user's gamemode.");
return true;
2011-10-19 00:37:00 +00:00
}
}
playerMsg("Setting " + p.getName() + " to game mode 'Survival'.");
2011-10-19 00:37:00 +00:00
p.sendMessage(sender.getName() + " set your game mode to 'Survival'.");
p.setGameMode(GameMode.SURVIVAL);
return true;
}
}