2015-10-19 19:43:46 +02:00
package me.totalfreedom.totalfreedommod.commands ;
2012-12-06 10:32:08 +01:00
2015-11-16 00:32:04 +01:00
import me.totalfreedom.totalfreedommod.rank.PlayerRank ;
2015-10-19 19:43:46 +02:00
import me.totalfreedom.totalfreedommod.player.FPlayer ;
import me.totalfreedom.totalfreedommod.util.FUtil ;
2012-12-06 10:32:08 +01:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2015-10-19 19:43:46 +02:00
@CommandPermissions ( level = PlayerRank . SUPER_ADMIN , source = SourceType . BOTH )
2013-04-09 22:05:24 -04:00
@CommandParameters ( description = " Block all commands for a specific player. " , usage = " /<command> <purge | <partialname>> " , aliases = " blockcommands,blockcommand " )
2015-10-19 19:43:46 +02:00
public class Command_blockcmd extends FreedomCommand
2012-12-06 10:32:08 +01:00
{
@Override
public boolean run ( CommandSender sender , Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
2012-12-07 20:01:52 -05:00
if ( args . length ! = 1 )
{
2012-12-06 10:32:08 +01:00
return false ;
}
2013-01-07 15:56:53 +01:00
if ( args [ 0 ] . equalsIgnoreCase ( " purge " ) )
{
2015-10-19 19:43:46 +02:00
FUtil . adminAction ( sender . getName ( ) , " Unblocking commands for all players " , true ) ;
2013-01-07 15:56:53 +01:00
int counter = 0 ;
2013-08-14 16:01:42 +02:00
for ( Player player : server . getOnlinePlayers ( ) )
2013-01-07 15:56:53 +01:00
{
2015-10-19 19:43:46 +02:00
FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
2013-01-07 15:56:53 +01:00
if ( playerdata . allCommandsBlocked ( ) )
{
counter + = 1 ;
playerdata . setCommandsBlocked ( false ) ;
}
}
2013-01-16 15:48:56 +01:00
playerMsg ( " Unblocked commands for " + counter + " players. " ) ;
2013-01-07 15:56:53 +01:00
return true ;
}
2014-04-26 13:55:24 +02:00
final Player player = getPlayer ( args [ 0 ] ) ;
2014-05-04 23:03:34 +02:00
2014-04-26 13:55:24 +02:00
if ( player = = null )
2012-12-06 10:32:08 +01:00
{
2015-10-19 19:43:46 +02:00
playerMsg ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2013-01-07 15:56:53 +01:00
return true ;
}
2015-10-19 19:43:46 +02:00
if ( isAdmin ( sender ) )
2013-01-07 15:56:53 +01:00
{
2013-08-14 16:01:42 +02:00
playerMsg ( player . getName ( ) + " is a Superadmin, and cannot have their commands blocked. " ) ;
2012-12-06 10:32:08 +01:00
return true ;
}
2015-10-19 19:43:46 +02:00
FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
2012-12-06 10:32:08 +01:00
2012-12-07 20:01:52 -05:00
playerdata . setCommandsBlocked ( ! playerdata . allCommandsBlocked ( ) ) ;
2012-12-06 10:32:08 +01:00
2015-10-19 19:43:46 +02:00
FUtil . adminAction ( sender . getName ( ) , ( playerdata . allCommandsBlocked ( ) ? " B " : " Unb " ) + " locking all commands for " + player . getName ( ) , true ) ;
2013-01-07 15:56:53 +01:00
playerMsg ( ( playerdata . allCommandsBlocked ( ) ? " B " : " Unb " ) + " locked all commands. " ) ;
2012-12-06 10:32:08 +01:00
return true ;
}
}