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

132 lines
4.0 KiB
Java
Raw Normal View History

package me.StevenLawson.TotalFreedomMod.Commands;
2013-01-21 18:58:42 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
@CommandParameters(description = "Block target's minecraft input. This is evil, and I never should have wrote it.", usage = "/<command> <all | purge | <<partialname> on | off>>")
public class Command_lockup extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("all"))
{
TFM_Util.adminAction(sender.getName(), "Locking up all players", true);
2013-08-14 14:01:42 +00:00
for (Player player : server.getOnlinePlayers())
{
2013-08-14 14:01:42 +00:00
startLockup(player);
}
playerMsg("Locked up all players.");
}
else if (args[0].equalsIgnoreCase("purge"))
{
TFM_Util.adminAction(sender.getName(), "Unlocking all players", true);
2013-08-14 14:01:42 +00:00
for (Player player : server.getOnlinePlayers())
{
2013-08-14 14:01:42 +00:00
cancelLockup(player);
}
playerMsg("Unlocked all players.");
}
else
{
return false;
}
}
else if (args.length == 2)
{
if (args[1].equalsIgnoreCase("on"))
{
2013-08-14 14:01:42 +00:00
final Player player;
try
{
2013-08-14 14:01:42 +00:00
player = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
2013-08-14 14:01:42 +00:00
TFM_Util.adminAction(sender.getName(), "Locking up " + player.getName(), true);
startLockup(player);
playerMsg("Locked up " + player.getName() + ".");
}
2012-11-18 03:57:24 +00:00
else if (TFM_Util.isStopCommand(args[1]))
{
2013-08-14 14:01:42 +00:00
final Player player;
try
{
2013-08-14 14:01:42 +00:00
player = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
2013-08-14 14:01:42 +00:00
TFM_Util.adminAction(sender.getName(), "Unlocking " + player.getName(), true);
cancelLockup(player);
playerMsg("Unlocked " + player.getName() + ".");
}
else
{
return false;
}
}
else
{
return false;
}
return true;
}
2013-01-21 18:58:42 +00:00
private void cancelLockup(TFM_PlayerData playerdata)
{
BukkitTask lockupScheduleID = playerdata.getLockupScheduleID();
if (lockupScheduleID != null)
{
lockupScheduleID.cancel();
playerdata.setLockupScheduleID(null);
}
}
2013-08-14 14:01:42 +00:00
private void cancelLockup(final Player player)
{
2013-08-14 14:01:42 +00:00
cancelLockup(TFM_PlayerData.getPlayerData(player));
}
2013-08-14 14:01:42 +00:00
private void startLockup(final Player player)
{
2013-08-14 14:01:42 +00:00
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
cancelLockup(playerdata);
playerdata.setLockupScheduleID(new BukkitRunnable()
{
@Override
public void run()
{
2013-08-14 14:01:42 +00:00
if (player.isOnline())
{
2013-08-14 14:01:42 +00:00
player.openInventory(player.getInventory());
}
else
{
cancelLockup(playerdata);
}
}
}.runTaskTimer(plugin, 0L, 5L));
}
}