2021-12-05 18:09:01 +01:00
|
|
|
using System.Linq;
|
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-09-01 12:24:28 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
2020-10-30 16:06:48 +01:00
|
|
|
namespace Content.Server.Administration.Commands
|
2020-09-01 12:24:28 +02:00
|
|
|
{
|
2021-10-08 02:41:30 -05:00
|
|
|
[AdminCommand(AdminFlags.Spawn)]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class DeleteEntitiesWithId : IConsoleCommand
|
2020-09-01 12:24:28 +02:00
|
|
|
{
|
|
|
|
|
public string Command => "deleteewi";
|
|
|
|
|
public string Description => "Deletes entities with the specified prototype ID.";
|
|
|
|
|
public string Help => $"Usage: {Command} <prototypeID>";
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-09-01 12:24:28 +02:00
|
|
|
{
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine(Help);
|
2020-09-01 12:24:28 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var id = args[0].ToLower();
|
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
2021-12-08 17:04:21 +01:00
|
|
|
var entities = entityManager.GetEntities().Where(e => entityManager.GetComponent<MetaDataComponent>(e).EntityPrototype?.ID.ToLower() == id);
|
2020-09-01 12:24:28 +02:00
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
entityManager.DeleteEntity(entity);
|
2020-09-01 12:24:28 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"Deleted all entities with id {id}. Occurrences: {i}");
|
2020-09-01 12:24:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|