AddEntityStorageCommand.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Server.Storage.Components;
  2. using Content.Server.Storage.EntitySystems;
  3. using Content.Shared.Administration;
  4. using Robust.Shared.Console;
  5. namespace Content.Server.Administration.Commands
  6. {
  7. [AdminCommand(AdminFlags.Admin)]
  8. public sealed class AddEntityStorageCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IEntityManager _entManager = default!;
  11. public string Command => "addstorage";
  12. public string Description => "Adds a given entity to a containing storage.";
  13. public string Help => "Usage: addstorage <entity uid> <storage uid>";
  14. public void Execute(IConsoleShell shell, string argStr, string[] args)
  15. {
  16. if (args.Length != 2)
  17. {
  18. shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
  19. return;
  20. }
  21. if (!NetEntity.TryParse(args[0], out var entityUidNet) || !_entManager.TryGetEntity(entityUidNet, out var entityUid))
  22. {
  23. shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
  24. return;
  25. }
  26. if (!NetEntity.TryParse(args[1], out var storageUidNet) || !_entManager.TryGetEntity(storageUidNet, out var storageUid))
  27. {
  28. shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
  29. return;
  30. }
  31. if (_entManager.HasComponent<EntityStorageComponent>(storageUid) &&
  32. _entManager.EntitySysManager.TryGetEntitySystem<EntityStorageSystem>(out var storageSys))
  33. {
  34. storageSys.Insert(entityUid.Value, storageUid.Value);
  35. }
  36. else
  37. {
  38. shell.WriteError("Could not insert into non-storage.");
  39. }
  40. }
  41. }
  42. }