Files
tbd-station-14/Content.Server/Administration/Commands/DeleteComponent.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

53 lines
1.8 KiB
C#

#nullable enable
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
public class DeleteComponent : IConsoleCommand
{
public string Command => "deletecomponent";
public string Description => "Deletes all instances of the specified component.";
public string Help => $"Usage: {Command} <name>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
switch (args.Length)
{
case 0:
shell.WriteLine($"Not enough arguments.\n{Help}");
break;
default:
var name = string.Join(" ", args);
var componentFactory = IoCManager.Resolve<IComponentFactory>();
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!componentFactory.TryGetRegistration(name, out var registration))
{
shell.WriteLine($"No component exists with name {name}.");
break;
}
var componentType = registration.Type;
var components = entityManager.ComponentManager.GetAllComponents(componentType, true);
var i = 0;
foreach (var component in components)
{
var uid = component.Owner.Uid;
entityManager.ComponentManager.RemoveComponent(uid, component);
i++;
}
shell.WriteLine($"Removed {i} components with name {name}.");
break;
}
}
}
}