2016-03-02 19:28:01 +00:00
package me.totalfreedom.totalfreedommod.command ;
2012-12-06 09:32:08 +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 ;
2016-05-12 19:40:39 +00:00
import org.bukkit.ChatColor ;
2012-12-06 09:32:08 +00:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2016-03-06 15:56:15 +00:00
@CommandPermissions ( level = Rank . SUPER_ADMIN , source = SourceType . BOTH )
2016-05-12 19:40:39 +00:00
@CommandParameters ( description = " Block all commands for a specific player. " , usage = " /<command> <-a | purge | <player>> " , aliases = " blockcommands,blockcommand,bc,bcmd " )
2015-10-19 17:43:46 +00:00
public class Command_blockcmd extends FreedomCommand
2012-12-06 09:32:08 +00:00
{
2015-11-22 18:26:47 +00:00
2012-12-06 09:32:08 +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-12-06 09:32:08 +00:00
{
2012-12-08 01:01:52 +00:00
if ( args . length ! = 1 )
{
2012-12-06 09:32:08 +00:00
return false ;
}
2016-05-12 19:40:39 +00:00
if ( args [ 0 ] . equals ( " purge " ) )
2013-01-07 14:56:53 +00:00
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Unblocking commands for all players " , true ) ;
2013-01-07 14:56:53 +00:00
int counter = 0 ;
2013-08-14 14:01:42 +00:00
for ( Player player : server . getOnlinePlayers ( ) )
2013-01-07 14:56:53 +00:00
{
2015-10-19 17:43:46 +00:00
FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
2013-01-07 14:56:53 +00:00
if ( playerdata . allCommandsBlocked ( ) )
{
counter + = 1 ;
playerdata . setCommandsBlocked ( false ) ;
}
}
2016-03-02 19:28:01 +00:00
msg ( " Unblocked commands for " + counter + " players. " ) ;
2013-01-07 14:56:53 +00:00
return true ;
}
2016-05-12 19:40:39 +00:00
if ( args [ 0 ] . equals ( " -a " ) )
{
FUtil . adminAction ( sender . getName ( ) , " Blocking commands for all non-admins " , true ) ;
int counter = 0 ;
for ( Player player : server . getOnlinePlayers ( ) )
{
if ( isAdmin ( player ) )
{
continue ;
}
counter + = 1 ;
plugin . pl . getPlayer ( player ) . setCommandsBlocked ( true ) ;
msg ( player , " Your commands have been blocked by an admin. " , ChatColor . RED ) ;
}
msg ( " Blocked commands for " + counter + " players. " ) ;
return true ;
}
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-12-06 09:32:08 +00:00
{
2016-03-02 19:28:01 +00:00
msg ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2013-01-07 14:56:53 +00:00
return true ;
}
2016-05-12 19:40:39 +00:00
if ( isAdmin ( player ) )
2013-01-07 14:56:53 +00:00
{
2016-03-02 19:28:01 +00:00
msg ( player . getName ( ) + " is a Superadmin, and cannot have their commands blocked. " ) ;
2012-12-06 09:32:08 +00:00
return true ;
}
2015-10-19 17:43:46 +00:00
FPlayer playerdata = plugin . pl . getPlayer ( player ) ;
2012-12-06 09:32:08 +00:00
2012-12-08 01:01:52 +00:00
playerdata . setCommandsBlocked ( ! playerdata . allCommandsBlocked ( ) ) ;
2012-12-06 09:32:08 +00:00
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , ( playerdata . allCommandsBlocked ( ) ? " B " : " Unb " ) + " locking all commands for " + player . getName ( ) , true ) ;
2016-03-02 19:28:01 +00:00
msg ( ( playerdata . allCommandsBlocked ( ) ? " B " : " Unb " ) + " locked all commands. " ) ;
2012-12-06 09:32:08 +00:00
return true ;
}
}