Files
Pieter-Jan BriersandGitHub 5168b5f3d4 IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

43 lines
1.2 KiB
C#

using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.Spawn)]
public sealed partial class DeleteComponentCommand : LocalizedEntityCommands
{
[Dependency] private IComponentFactory _compFactory = default!;
public override string Command => "deletecomponent";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length == 0)
{
shell.WriteLine(Loc.GetString($"shell-need-exactly-one-argument"));
return;
}
var name = string.Join(" ", args);
if (!_compFactory.TryGetRegistration(name, out var registration))
{
shell.WriteLine(Loc.GetString($"cmd-deletecomponent-no-component-exists", ("name", name)));
return;
}
var componentType = registration.Type;
var components = EntityManager.GetAllComponents(componentType, true);
var i = 0;
foreach (var (uid, component) in components)
{
EntityManager.RemoveComponent(uid, component);
i++;
}
shell.WriteLine(Loc.GetString($"cmd-deletecomponent-success", ("count", i), ("name", name)));
}
}