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

97 lines
3.6 KiB
Java
Raw Normal View History

2011-10-19 00:37:00 +00:00
package me.StevenLawson.TotalFreedomMod.Commands;
2013-01-21 18:58:42 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
2011-10-19 00:37:00 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
2011-10-19 00:37:00 +00:00
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
@CommandParameters(description = "Freeze players (toggles on and off).", usage = "/<command> [target | purge]")
2011-10-19 00:37:00 +00:00
public class Command_fr extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
2011-10-19 00:37:00 +00:00
{
TotalFreedomMod.allPlayersFrozen = !TotalFreedomMod.allPlayersFrozen;
if (TotalFreedomMod.allPlayersFrozen)
{
TFM_Util.adminAction(sender.getName(), "Freezing all players due to rule breakers", false);
2013-01-16 14:48:56 +00:00
TotalFreedomMod.allPlayersFrozen = true;
if (TotalFreedomMod.freezePurgeTask != null)
{
TotalFreedomMod.freezePurgeTask.cancel();
}
TotalFreedomMod.freezePurgeTask = new BukkitRunnable()
2013-01-16 14:48:56 +00:00
{
@Override
public void run()
{
TFM_Util.adminAction("FreezeTimer", "Unfreezing all players", false);
TotalFreedomMod.allPlayersFrozen = false;
}
}.runTaskLater(plugin, 20L * 60L * 5L);
playerMsg("Players are now frozen.");
}
else
2011-10-19 00:37:00 +00:00
{
TFM_Util.adminAction(sender.getName(), "Unfreezing all players", false);
2013-01-16 14:48:56 +00:00
TotalFreedomMod.allPlayersFrozen = false;
if (TotalFreedomMod.freezePurgeTask != null)
2013-01-16 14:48:56 +00:00
{
TotalFreedomMod.freezePurgeTask.cancel();
2013-01-16 14:48:56 +00:00
}
playerMsg("Players are now free to move.");
}
}
else
{
if (args[0].toLowerCase().equals("purge"))
{
TotalFreedomMod.allPlayersFrozen = false;
if (TotalFreedomMod.freezePurgeTask != null)
{
TotalFreedomMod.freezePurgeTask.cancel();
}
2011-10-19 00:37:00 +00:00
2013-08-14 14:01:42 +00:00
for (Player player : server.getOnlinePlayers())
2011-10-19 00:37:00 +00:00
{
2013-08-14 14:01:42 +00:00
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.setFrozen(false);
2011-10-19 00:37:00 +00:00
}
TFM_Util.adminAction(sender.getName(), "Lifting all global and player freezes", false);
2011-10-19 00:37:00 +00:00
}
else
{
2013-08-14 14:01:42 +00:00
Player player;
try
2011-10-19 00:37:00 +00:00
{
2013-08-14 14:01:42 +00:00
player = getPlayer(args[0]);
2011-10-19 00:37:00 +00:00
}
catch (PlayerNotFoundException ex)
2011-10-19 00:37:00 +00:00
{
playerMsg(ex.getMessage(), ChatColor.RED);
return true;
}
2011-10-19 00:37:00 +00:00
2013-08-14 14:01:42 +00:00
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.setFrozen(!playerdata.isFrozen());
2011-10-19 00:37:00 +00:00
2013-08-14 14:01:42 +00:00
playerMsg(player.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
playerMsg(player, "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".", ChatColor.AQUA);
2011-10-19 00:37:00 +00:00
}
}
return true;
}
}