FollowCommand.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Shared.Administration;
  2. using Content.Shared.Follower;
  3. using Robust.Shared.Console;
  4. using Robust.Shared.Enums;
  5. namespace Content.Server.Administration.Commands;
  6. [AdminCommand(AdminFlags.Admin)]
  7. public sealed class FollowCommand : IConsoleCommand
  8. {
  9. [Dependency] private readonly IEntityManager _entManager = default!;
  10. public string Command => "follow";
  11. public string Description => Loc.GetString("follow-command-description");
  12. public string Help => Loc.GetString("follow-command-help");
  13. public void Execute(IConsoleShell shell, string argStr, string[] args)
  14. {
  15. if (shell.Player is not { } player)
  16. {
  17. shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
  18. return;
  19. }
  20. if (args.Length != 1)
  21. {
  22. shell.WriteError(Loc.GetString("shell-need-exactly-one-argument"));
  23. return;
  24. }
  25. if (player.Status != SessionStatus.InGame || player.AttachedEntity is not { Valid: true } playerEntity)
  26. {
  27. shell.WriteError(Loc.GetString("shell-must-be-attached-to-entity"));
  28. return;
  29. }
  30. var entity = args[0];
  31. if (NetEntity.TryParse(entity, out var uidNet) && _entManager.TryGetEntity(uidNet, out var uid))
  32. {
  33. _entManager.System<FollowerSystem>().StartFollowingEntity(playerEntity, uid.Value);
  34. }
  35. }
  36. }