2020-08-13 14:40:27 +02:00
using System ;
using System.Collections.Generic ;
2020-10-30 16:06:48 +01:00
using Content.Shared.Administration ;
2021-02-01 16:49:43 -08:00
using Robust.Shared.Console ;
2020-06-24 10:52:52 -07:00
using Robust.Shared.GameObjects ;
using Robust.Shared.IoC ;
using Robust.Shared.Localization ;
2020-10-30 16:06:48 +01:00
namespace Content.Server.Administration.Commands
2020-06-24 10:52:52 -07:00
{
2020-10-30 16:06:48 +01:00
[AdminCommand(AdminFlags.Admin)]
2021-02-01 16:49:43 -08:00
class DeleteEntitiesWithComponent : IConsoleCommand
2020-06-24 10:52:52 -07:00
{
public string Command = > "deleteewc" ;
public string Description
{
get
{
2020-09-17 09:55:50 +12:00
return Loc . GetString ( "Deletes entities with the specified components." ) ;
2020-06-24 10:52:52 -07:00
}
}
public string Help
{
get
{
2020-09-17 09:55:50 +12:00
return Loc . GetString ( "Usage: deleteewc <componentName_1> <componentName_2> ... <componentName_n>\nDeletes any entities with the components specified." ) ;
2020-06-24 10:52:52 -07:00
}
}
2021-02-01 16:49:43 -08:00
public void Execute ( IConsoleShell shell , string argStr , string [ ] args )
2020-06-24 10:52:52 -07:00
{
if ( args . Length < 1 )
{
2021-02-01 16:49:43 -08:00
shell . WriteLine ( Help ) ;
2020-06-24 10:52:52 -07:00
return ;
}
var factory = IoCManager . Resolve < IComponentFactory > ( ) ;
var components = new List < Type > ( ) ;
foreach ( var arg in args )
{
components . Add ( factory . GetRegistration ( arg ) . Type ) ;
}
var entityManager = IoCManager . Resolve < IEntityManager > ( ) ;
var entities = entityManager . GetEntities ( new MultipleTypeEntityQuery ( components ) ) ;
var count = 0 ;
foreach ( var entity in entities )
{
entity . Delete ( ) ;
count + = 1 ;
}
2021-02-01 16:49:43 -08:00
shell . WriteLine ( Loc . GetString ( "Deleted {0} entities" , count ) ) ;
2020-06-24 10:52:52 -07:00
}
}
}