2016-03-02 19:28:01 +00:00
package me.totalfreedom.totalfreedommod.command ;
2012-09-19 02:21:25 +00:00
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.player.FPlayer ;
2016-03-06 15:56:15 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.util.FUtil ;
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
2016-03-06 15:56:15 +00:00
@CommandPermissions ( level = Rank . SENIOR_ADMIN , 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>> " )
2015-10-19 17:43:46 +00:00
public class Command_lockup extends FreedomCommand
2012-09-19 02:21:25 +00:00
{
2015-11-22 18:26:47 +00:00
2012-09-19 02:21:25 +00:00
@Override
2015-11-22 18:26:47 +00:00
public boolean run ( CommandSender sender , Player playerSender , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
2012-09-19 02:21:25 +00:00
{
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 " ) )
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Locking up all players " , true ) ;
2012-10-03 22:50:16 +00:00
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
}
2016-03-02 19:28:01 +00:00
msg ( " Locked up all players. " ) ;
2012-09-20 01:43:12 +00:00
}
else if ( args [ 0 ] . equalsIgnoreCase ( " purge " ) )
{
2015-10-19 17:43:46 +00:00
FUtil . 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
2016-03-02 19:28:01 +00:00
msg ( " 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
{
2014-04-26 11:55:24 +00:00
final Player player = getPlayer ( args [ 0 ] ) ;
2014-05-04 21:03:34 +00:00
2014-04-26 11:55:24 +00:00
if ( player = = null )
2012-09-19 02:21:25 +00:00
{
2015-10-19 17:43:46 +00:00
sender . sendMessage ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2012-09-20 01:43:12 +00:00
return true ;
2012-09-19 02:21:25 +00:00
}
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Locking up " + player . getName ( ) , true ) ;
2013-08-14 14:01:42 +00:00
startLockup ( player ) ;
2016-03-02 19:28:01 +00:00
msg ( " Locked up " + player . getName ( ) + " . " ) ;
2012-09-20 01:43:12 +00:00
}
2014-05-05 13:31:12 +00:00
else if ( " off " . equals ( args [ 1 ] ) )
2012-09-20 01:43:12 +00:00
{
2014-04-26 11:55:24 +00:00
final Player player = getPlayer ( args [ 0 ] ) ;
2014-05-04 21:03:34 +00:00
2014-04-26 11:55:24 +00:00
if ( player = = null )
2012-09-20 01:43:12 +00:00
{
2015-10-19 17:43:46 +00:00
sender . sendMessage ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2012-09-20 01:43:12 +00:00
return true ;
}
2012-09-19 02:21:25 +00:00
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Unlocking " + player . getName ( ) , true ) ;
2013-08-14 14:01:42 +00:00
cancelLockup ( player ) ;
2016-03-02 19:28:01 +00:00
msg ( " 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 ;
}
2015-10-19 17:43:46 +00:00
private void cancelLockup ( FPlayer playerdata )
2012-09-19 02:21:25 +00:00
{
2015-11-22 18:26:47 +00:00
BukkitTask lockupScheduleId = playerdata . getLockupScheduleID ( ) ;
if ( lockupScheduleId ! = null )
2012-09-19 02:21:25 +00:00
{
2015-11-22 18:26:47 +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
{
2015-10-19 17:43:46 +00:00
cancelLockup ( plugin . pl . getPlayer ( 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
{
2015-10-19 17:43:46 +00:00
final FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
2012-09-20 01:43:12 +00:00
cancelLockup ( playerdata ) ;
2015-11-22 18:26:47 +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
}