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