Files
tbd-station-14/Content.Server/Administration/Commands/DeleteComponent.cs
Kara db1dfc8958 Command perm modifications (#11273)
* Command perm modifications

* actually not this one

* string
2022-09-14 19:02:38 -05:00

50 lines
1.7 KiB
C#

using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Spawn)]
public sealed 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.GetAllComponents(componentType, true);
var i = 0;
foreach (var component in components)
{
var uid = component.Owner;
entityManager.RemoveComponent(uid, component);
i++;
}
shell.WriteLine($"Removed {i} components with name {name}.");
break;
}
}
}
}