2012-11-28 16:35:31 +00:00
package me.StevenLawson.TotalFreedomMod.Commands ;
import me.StevenLawson.TotalFreedomMod.TFM_Util ;
import org.bukkit.ChatColor ;
import org.bukkit.Material ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2013-03-19 22:05:20 +00:00
@CommandPermissions ( level = AdminLevel . SUPER , source = SourceType . BOTH , block_host_console = false )
2013-04-10 02:05:24 +00:00
@CommandParameters ( description = " Remove all blocks of a certain type in the radius of certain players. " , usage = " /<command> <block> [radius (default=50)] [player] " )
2012-11-28 16:35:31 +00:00
public class Command_ro extends TFM_Command
{
@Override
public boolean run ( CommandSender sender , Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
2012-12-01 20:11:00 +00:00
if ( args . length < 1 | | args . length > 3 )
2012-11-28 16:35:31 +00:00
{
2012-12-01 20:11:00 +00:00
return false ;
2012-11-28 16:35:31 +00:00
}
2012-12-01 20:11:00 +00:00
Material from_material = Material . matchMaterial ( args [ 0 ] ) ;
if ( from_material = = null )
2012-11-28 16:35:31 +00:00
{
try
{
2012-12-01 20:11:00 +00:00
from_material = Material . getMaterial ( Integer . parseInt ( args [ 0 ] ) ) ;
}
2013-08-14 13:28:19 +00:00
catch ( NumberFormatException ex )
2012-12-01 20:11:00 +00:00
{
2012-11-28 16:35:31 +00:00
}
2012-12-01 20:11:00 +00:00
if ( from_material = = null )
2012-11-28 16:35:31 +00:00
{
2013-01-07 14:56:53 +00:00
playerMsg ( " Invalid block: " + args [ 0 ] , ChatColor . RED ) ;
2012-11-28 16:35:31 +00:00
return true ;
}
2012-12-01 20:11:00 +00:00
}
2012-12-01 20:45:50 +00:00
int radius = 20 ;
2012-12-01 20:11:00 +00:00
if ( args . length > = 2 )
{
try
2012-11-28 16:35:31 +00:00
{
2012-12-01 20:11:00 +00:00
radius = Math . max ( 1 , Math . min ( 50 , Integer . parseInt ( args [ 1 ] ) ) ) ;
}
2013-08-14 13:28:19 +00:00
catch ( NumberFormatException ex )
2012-12-01 20:11:00 +00:00
{
2013-01-07 14:56:53 +00:00
playerMsg ( " Invalid radius: " + args [ 1 ] , ChatColor . RED ) ;
2012-11-28 16:35:31 +00:00
return true ;
}
}
2012-12-01 20:11:00 +00:00
Player target_player = null ;
if ( args . length = = 3 )
2012-11-28 16:35:31 +00:00
{
try
{
2012-12-01 20:11:00 +00:00
target_player = getPlayer ( args [ 2 ] ) ;
2012-11-28 16:35:31 +00:00
}
2013-08-14 13:28:19 +00:00
catch ( PlayerNotFoundException ex )
2012-11-28 16:35:31 +00:00
{
2013-08-14 13:28:19 +00:00
playerMsg ( ex . getMessage ( ) , ChatColor . RED ) ;
2012-11-28 16:35:31 +00:00
return true ;
}
}
2012-12-01 20:50:33 +00:00
int affected = 0 ;
2012-12-01 20:11:00 +00:00
if ( target_player = = null )
2012-11-28 16:35:31 +00:00
{
2012-12-01 20:50:33 +00:00
TFM_Util . adminAction ( sender . getName ( ) , " Removing all " + from_material . name ( ) + " within " + radius + " blocks of all players. Brace for lag... " , senderIsConsole ) ;
2013-08-14 14:01:42 +00:00
for ( Player player : server . getOnlinePlayers ( ) )
2012-11-28 16:35:31 +00:00
{
2013-08-14 14:01:42 +00:00
affected + = TFM_Util . replaceBlocks ( player . getLocation ( ) , from_material , Material . AIR , radius ) ;
2012-11-28 16:35:31 +00:00
}
}
else
{
2012-12-01 20:45:50 +00:00
TFM_Util . adminAction ( sender . getName ( ) , " Removing all " + from_material . name ( ) + " within " + radius + " blocks of " + target_player . getName ( ) + " . " , senderIsConsole ) ;
2012-12-01 20:50:33 +00:00
affected + = TFM_Util . replaceBlocks ( target_player . getLocation ( ) , from_material , Material . AIR , radius ) ;
2012-11-28 16:35:31 +00:00
}
2012-12-01 20:11:00 +00:00
2012-12-01 20:50:33 +00:00
TFM_Util . adminAction ( sender . getName ( ) , " Remove complete. " + affected + " blocks removed. " , senderIsConsole ) ;
2012-12-01 20:45:50 +00:00
2012-11-28 16:35:31 +00:00
return true ;
}
2012-12-01 20:11:00 +00:00
}