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 ;
2020-09-28 03:17:01 +00:00
@CommandPermissions ( level = Rank . ADMIN , source = SourceType . BOTH )
2020-03-30 23:43:57 +00:00
@CommandParameters ( description = " Block all commands for everyone on the server, or 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
{
2020-12-04 00:28:53 +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 " ) )
{
2020-12-04 00:28:53 +00:00
FUtil . adminAction ( sender . getName ( ) , " Blocking commands for all non-admins " , true ) ;
2016-05-12 19:40:39 +00:00
int counter = 0 ;
for ( Player player : server . getOnlinePlayers ( ) )
{
2020-12-04 00:28:53 +00:00
if ( isAdmin ( player ) )
2016-05-12 19:40:39 +00:00
{
continue ;
}
counter + = 1 ;
plugin . pl . getPlayer ( player ) . setCommandsBlocked ( true ) ;
2020-12-04 00:28:53 +00:00
msg ( player , " Your commands have been blocked by an admin. " , ChatColor . RED ) ;
2016-05-12 19:40:39 +00:00
}
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 ;
}
2020-12-04 00:28:53 +00:00
if ( isAdmin ( player ) )
2013-01-07 14:56:53 +00:00
{
2020-12-04 00:28:53 +00:00
msg ( player . getName ( ) + " is an admin, 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 ) ;
2020-07-25 03:24:14 +00:00
if ( ! playerdata . allCommandsBlocked ( ) )
{
playerdata . setCommandsBlocked ( true ) ;
2020-12-04 00:28:53 +00:00
FUtil . adminAction ( sender . getName ( ) , " Blocking all commands for " + player . getName ( ) , true ) ;
2020-07-25 03:24:14 +00:00
msg ( " Blocked commands for " + player . getName ( ) + " . " ) ;
}
else
{
msg ( " That players commands are already blocked. " , ChatColor . RED ) ;
}
2012-12-06 09:32:08 +00:00
return true ;
}
2020-07-25 03:24:14 +00:00
}