2015-10-19 17:43:46 +00:00
package me.totalfreedom.totalfreedommod.commands ;
2012-11-28 16:35:31 +00:00
2014-04-23 15:00:44 +00:00
import java.util.ArrayList ;
import java.util.List ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.permission.PlayerRank ;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator ;
import me.totalfreedom.totalfreedommod.util.FUtil ;
2014-11-29 19:16:00 +00:00
import org.apache.commons.lang3.StringUtils ;
2012-11-28 16:35:31 +00:00
import org.bukkit.ChatColor ;
import org.bukkit.Material ;
2014-08-30 19:18:45 +00:00
import org.bukkit.World ;
2012-11-28 16:35:31 +00:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2015-10-19 17:43:46 +00:00
@CommandPermissions ( level = PlayerRank . SUPER_ADMIN , source = SourceType . BOTH , blockHostConsole = 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] " )
2015-10-19 17:43:46 +00:00
public class Command_ro extends FreedomCommand
2012-11-28 16:35:31 +00:00
{
@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
}
2014-04-23 15:00:44 +00:00
final List < Material > materials = new ArrayList < Material > ( ) ;
2014-08-30 19:18:45 +00:00
for ( String materialName : StringUtils . split ( args [ 0 ] , " , " ) )
2014-04-23 15:00:44 +00:00
{
Material fromMaterial = Material . matchMaterial ( materialName ) ;
if ( fromMaterial = = null )
2012-12-01 20:11:00 +00:00
{
2014-04-23 15:00:44 +00:00
try
{
2015-10-19 17:43:46 +00:00
fromMaterial = DepreciationAggregator . getMaterial ( Integer . parseInt ( materialName ) ) ;
2014-04-23 15:00:44 +00:00
}
catch ( NumberFormatException ex )
{
}
2012-11-28 16:35:31 +00:00
}
2012-12-01 20:11:00 +00:00
2014-04-23 15:00:44 +00:00
if ( fromMaterial = = null )
2012-11-28 16:35:31 +00:00
{
2014-04-23 15:00:44 +00:00
playerMsg ( " Invalid block: " + materialName , ChatColor . RED ) ;
2012-11-28 16:35:31 +00:00
return true ;
}
2014-04-23 15:00:44 +00:00
materials . add ( fromMaterial ) ;
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 ;
}
}
2014-04-23 15:00:44 +00:00
final Player targetPlayer ;
2012-12-01 20:11:00 +00:00
if ( args . length = = 3 )
2012-11-28 16:35:31 +00:00
{
2014-04-26 11:55:24 +00:00
targetPlayer = getPlayer ( args [ 2 ] ) ;
if ( targetPlayer = = null )
2012-11-28 16:35:31 +00:00
{
2015-10-19 17:43:46 +00:00
playerMsg ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2012-11-28 16:35:31 +00:00
return true ;
}
}
2014-04-23 15:00:44 +00:00
else
{
targetPlayer = null ;
}
2012-11-28 16:35:31 +00:00
2014-04-23 15:00:44 +00:00
final String names = StringUtils . join ( materials , " , " ) ;
2012-12-01 20:50:33 +00:00
2014-08-30 19:18:45 +00:00
World adminWorld = null ;
try
{
2015-10-19 17:43:46 +00:00
adminWorld = plugin . wm . adminworld . getWorld ( ) ;
2014-08-30 19:18:45 +00:00
}
catch ( Exception ex )
{
}
2014-04-23 15:00:44 +00:00
int affected = 0 ;
2013-08-14 14:55:37 +00:00
if ( targetPlayer = = null )
2012-11-28 16:35:31 +00:00
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Removing all " + names + " within " + radius + " blocks of all players... Brace for lag! " , false ) ;
2014-04-23 15:00:44 +00:00
2014-08-30 19:18:45 +00:00
for ( final Player player : server . getOnlinePlayers ( ) )
2012-11-28 16:35:31 +00:00
{
2014-08-30 19:18:45 +00:00
if ( player . getWorld ( ) = = adminWorld )
{
continue ;
}
for ( final Material material : materials )
2014-04-23 15:00:44 +00:00
{
2015-10-19 17:43:46 +00:00
affected + = FUtil . replaceBlocks ( player . getLocation ( ) , material , Material . AIR , radius ) ;
2014-04-23 15:00:44 +00:00
}
2012-11-28 16:35:31 +00:00
}
}
else
{
2014-08-30 19:18:45 +00:00
if ( targetPlayer . getWorld ( ) ! = adminWorld )
2014-04-23 15:00:44 +00:00
{
2014-08-30 19:18:45 +00:00
for ( Material material : materials )
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Removing all " + names + " within " + radius + " blocks of " + targetPlayer . getName ( ) , false ) ;
affected + = FUtil . replaceBlocks ( targetPlayer . getLocation ( ) , material , Material . AIR , radius ) ;
2014-08-30 19:18:45 +00:00
}
2014-04-23 15:00:44 +00:00
}
2012-11-28 16:35:31 +00:00
}
2012-12-01 20:11:00 +00:00
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Remove complete! " + affected + " blocks removed. " , false ) ;
2014-04-23 15:00:44 +00:00
2012-11-28 16:35:31 +00:00
return true ;
}
2012-12-01 20:11:00 +00:00
}