RemoveRoleCommand.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Content.Shared.Players;
  4. using Content.Shared.Roles;
  5. using Content.Shared.Roles.Jobs;
  6. using Robust.Server.Player;
  7. using Robust.Shared.Console;
  8. namespace Content.Server.Roles
  9. {
  10. [AdminCommand(AdminFlags.Admin)]
  11. public sealed class RemoveRoleCommand : IConsoleCommand
  12. {
  13. [Dependency] private readonly IEntityManager _entityManager = default!;
  14. public string Command => "rmrole";
  15. public string Description => "Removes a role from a player's mind.";
  16. public string Help => "rmrole <session ID> <Role Type>\nThat role type is the actual C# type name.";
  17. public void Execute(IConsoleShell shell, string argStr, string[] args)
  18. {
  19. if (args.Length != 2)
  20. {
  21. shell.WriteLine("Expected exactly 2 arguments.");
  22. return;
  23. }
  24. var mgr = IoCManager.Resolve<IPlayerManager>();
  25. if (!mgr.TryGetPlayerDataByUsername(args[0], out var data))
  26. {
  27. shell.WriteLine("Can't find that mind");
  28. return;
  29. }
  30. var mind = data.ContentData()?.Mind;
  31. if (mind == null)
  32. {
  33. shell.WriteLine("Can't find that mind");
  34. return;
  35. }
  36. var roles = _entityManager.System<SharedRoleSystem>();
  37. var jobs = _entityManager.System<SharedJobSystem>();
  38. if (jobs.MindHasJobWithId(mind, args[1]))
  39. roles.MindTryRemoveRole<JobRoleComponent>(mind.Value);
  40. }
  41. }
  42. }