2016-03-02 19:28:01 +00:00
package me.totalfreedom.totalfreedommod.command ;
2015-10-19 17:43:46 +00:00
2020-01-25 06:27:16 +00:00
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.List ;
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 ;
2020-01-25 06:27:16 +00:00
import me.totalfreedom.totalfreedommod.util.Groups ;
import org.bukkit.ChatColor ;
2015-10-19 17:43:46 +00:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
2020-01-25 06:27:16 +00:00
import org.bukkit.entity.EntityType ;
2015-10-19 17:43:46 +00:00
import org.bukkit.entity.Player ;
2016-03-06 15:56:15 +00:00
@CommandPermissions ( level = Rank . SUPER_ADMIN , source = SourceType . BOTH )
2020-01-25 06:27:16 +00:00
@CommandParameters ( description = " Remove various server entities that may cause lag, such as dropped items, minecarts, and boats. " , usage = " /<command> [name | -a] " , aliases = " ew,rd " )
2016-02-29 21:27:11 +00:00
public class Command_entitywipe extends FreedomCommand
2015-10-19 17:43:46 +00:00
{
2015-11-22 18:26:47 +00:00
2015-10-19 17:43:46 +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 )
2015-10-19 17:43:46 +00:00
{
2020-01-25 06:27:16 +00:00
EntityType type = null ;
String entityName = null ;
boolean bypassBlacklist = false ;
if ( args . length > 0 )
{
if ( args [ 0 ] . equals ( " -a " ) )
{
bypassBlacklist = true ;
}
else
{
try
{
type = EntityType . valueOf ( args [ 0 ] . toUpperCase ( ) ) ;
}
catch ( Exception e )
{
msg ( args [ 0 ] + " is not a valid entity type. " , ChatColor . RED ) ;
return true ;
}
2015-10-19 17:43:46 +00:00
2020-01-25 06:27:16 +00:00
if ( ! getAllEntities ( ) . contains ( type ) )
{
msg ( FUtil . formatName ( type . name ( ) ) + " is an entity, however: it is a mob. " , ChatColor . RED ) ;
return true ;
}
}
}
if ( type ! = null )
{
entityName = FUtil . formatName ( type . name ( ) ) ;
}
FUtil . adminAction ( sender . getName ( ) , " Purging all " + ( type ! = null ? entityName + " s " : " entities " ) , true ) ;
int count ;
if ( type ! = null )
{
count = plugin . ew . wipeEntities ( type ) ;
}
else
{
count = plugin . ew . wipeEntities ( bypassBlacklist ) ;
}
msg ( count + " " + ( type ! = null ? entityName : " entities " ) + FUtil . showS ( count ) + " removed. " ) ;
2015-10-19 17:43:46 +00:00
return true ;
}
2020-01-25 06:27:16 +00:00
public static List < EntityType > getAllEntities ( )
{
List < EntityType > entityTypes = new ArrayList < > ( ) ;
for ( EntityType entityType : EntityType . values ( ) )
{
if ( ! Groups . MOB_TYPES . contains ( entityType ) )
{
entityTypes . add ( entityType ) ;
}
}
return entityTypes ;
}
public static List < String > getAllEntityNames ( )
{
List < String > names = new ArrayList < > ( ) ;
for ( EntityType entityType : getAllEntities ( ) )
{
names . add ( entityType . name ( ) ) ;
}
return names ;
}
@Override
public List < String > getTabCompleteOptions ( CommandSender sender , Command command , String alias , String [ ] args )
{
List < String > names = getAllEntityNames ( ) ;
names . add ( " -a " ) ;
if ( args . length = = 1 )
{
return names ;
}
return Collections . emptyList ( ) ;
}
2015-10-19 17:43:46 +00:00
}