RemoveObjectiveCommand.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Content.Shared.Mind;
  4. using Robust.Server.Player;
  5. using Robust.Shared.Console;
  6. namespace Content.Server.Objectives.Commands
  7. {
  8. [AdminCommand(AdminFlags.Admin)]
  9. public sealed class RemoveObjectiveCommand : IConsoleCommand
  10. {
  11. [Dependency] private readonly IEntityManager _entityManager = default!;
  12. public string Command => "rmobjective";
  13. public string Description => "Removes an objective from the player's mind.";
  14. public string Help => "rmobjective <username> <index>";
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. if (args.Length != 2)
  18. {
  19. shell.WriteLine("Expected exactly 2 arguments.");
  20. return;
  21. }
  22. var mgr = IoCManager.Resolve<IPlayerManager>();
  23. var minds = _entityManager.System<SharedMindSystem>();
  24. if (!mgr.TryGetSessionByUsername(args[0], out var session))
  25. {
  26. shell.WriteLine("Can't find the playerdata.");
  27. return;
  28. }
  29. if (!minds.TryGetMind(session, out var mindId, out var mind))
  30. {
  31. shell.WriteLine("Can't find the mind.");
  32. return;
  33. }
  34. if (int.TryParse(args[1], out var i))
  35. {
  36. var mindSystem = _entityManager.System<SharedMindSystem>();
  37. shell.WriteLine(mindSystem.TryRemoveObjective(mindId, mind, i)
  38. ? "Objective successfully removed!"
  39. : "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
  40. }
  41. else
  42. {
  43. shell.WriteLine($"Invalid index {args[1]}!");
  44. }
  45. }
  46. }
  47. }