Implement DeleteEntitiesWithComponent console command (#1210)
Deletes entities that have all of the provided components
This commit is contained in:
62
Content.Server/Administration/DeleteEntitiesWithComponent.cs
Normal file
62
Content.Server/Administration/DeleteEntitiesWithComponent.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Robust.Server.Interfaces.Console;
|
||||||
|
using Robust.Server.Interfaces.Player;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Localization;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Content.Server.Administration
|
||||||
|
{
|
||||||
|
class DeleteEntitiesWithComponent : IClientCommand
|
||||||
|
{
|
||||||
|
public string Command => "deleteewc";
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||||
|
return localizationManager.GetString("Deletes entities with the specified components.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string Help
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||||
|
return localizationManager.GetString("Usage: deleteewc <componentName_1> <componentName_2> ... <componentName_n>\nDeletes any entities with the components specified.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
|
||||||
|
{
|
||||||
|
var localizationManager = IoCManager.Resolve<ILocalizationManager>();
|
||||||
|
if (args.Length < 1)
|
||||||
|
{
|
||||||
|
shell.SendText(player, Help);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.SendText(player, localizationManager.GetString("Deleted {0} entities", count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,6 +79,7 @@
|
|||||||
- addai
|
- addai
|
||||||
- warp
|
- warp
|
||||||
- hostlogin
|
- hostlogin
|
||||||
|
- deleteewc
|
||||||
CanViewVar: true
|
CanViewVar: true
|
||||||
CanAdminPlace: true
|
CanAdminPlace: true
|
||||||
|
|
||||||
@@ -145,6 +146,7 @@
|
|||||||
- gc
|
- gc
|
||||||
- gc_mode
|
- gc_mode
|
||||||
- warp
|
- warp
|
||||||
|
- deleteewc
|
||||||
CanViewVar: true
|
CanViewVar: true
|
||||||
CanAdminPlace: true
|
CanAdminPlace: true
|
||||||
CanScript: true
|
CanScript: true
|
||||||
|
|||||||
Reference in New Issue
Block a user