ListVerbsCommand.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Content.Server.Administration;
  2. using Content.Server.Database;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Verbs;
  5. using Robust.Shared.Console;
  6. namespace Content.Server.Verbs.Commands
  7. {
  8. [AdminCommand(AdminFlags.Moderator)]
  9. public sealed class ListVerbsCommand : IConsoleCommand
  10. {
  11. [Dependency] private readonly IEntityManager _entManager = default!;
  12. public string Command => "listverbs";
  13. public string Description => Loc.GetString("list-verbs-command-description");
  14. public string Help => Loc.GetString("list-verbs-command-help");
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. if (args.Length != 2)
  18. {
  19. shell.WriteLine(Loc.GetString("list-verbs-command-invalid-args"));
  20. return;
  21. }
  22. var verbSystem = _entManager.System<SharedVerbSystem>();
  23. // get the 'player' entity (defaulting to command user, otherwise uses a uid)
  24. EntityUid? playerEntity = null;
  25. if (!int.TryParse(args[0], out var intPlayerUid))
  26. {
  27. if (args[0] == "self" && shell.Player?.AttachedEntity != null)
  28. {
  29. playerEntity = shell.Player.AttachedEntity;
  30. }
  31. else
  32. {
  33. shell.WriteError(Loc.GetString("list-verbs-command-invalid-player-uid"));
  34. return;
  35. }
  36. }
  37. else
  38. {
  39. _entManager.TryGetEntity(new NetEntity(intPlayerUid), out playerEntity);
  40. }
  41. // gets the target entity
  42. if (!int.TryParse(args[1], out var intUid))
  43. {
  44. shell.WriteError(Loc.GetString("list-verbs-command-invalid-target-uid"));
  45. return;
  46. }
  47. if (playerEntity == null)
  48. {
  49. shell.WriteError(Loc.GetString("list-verbs-command-invalid-player-entity"));
  50. return;
  51. }
  52. var targetNet = new NetEntity(intUid);
  53. if (!_entManager.TryGetEntity(targetNet, out var target))
  54. {
  55. shell.WriteError(Loc.GetString("list-verbs-command-invalid-target-entity"));
  56. return;
  57. }
  58. var verbs = verbSystem.GetLocalVerbs(target.Value, playerEntity.Value, Verb.VerbTypes);
  59. foreach (var verb in verbs)
  60. {
  61. shell.WriteLine(Loc.GetString("list-verbs-verb-listing", ("type", verb.GetType().Name), ("verb", verb.Text)));
  62. }
  63. }
  64. }
  65. }