]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix rmobjective command and add completion options (#36396)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Tue, 8 Apr 2025 14:54:13 +0000 (16:54 +0200)
committerGitHub <noreply@github.com>
Tue, 8 Apr 2025 14:54:13 +0000 (16:54 +0200)
fix rmobjective command

Content.Server/Objectives/Commands/RemoveObjectiveCommand.cs
Content.Shared/Mind/SharedMindSystem.cs
Resources/Locale/en-US/objectives/commands/rmobjective.ftl [new file with mode: 0644]

index b174ca94b6320871e1c2e577f3d5a3c419415081..4b300cd195189f644eb32ac1594f1bbe7b8a04d3 100644 (file)
@@ -1,52 +1,81 @@
 using Content.Server.Administration;
 using Content.Shared.Administration;
 using Content.Shared.Mind;
+using Content.Shared.Objectives.Systems;
 using Robust.Server.Player;
 using Robust.Shared.Console;
 
 namespace Content.Server.Objectives.Commands
 {
     [AdminCommand(AdminFlags.Admin)]
-    public sealed class RemoveObjectiveCommand : IConsoleCommand
+    public sealed class RemoveObjectiveCommand : LocalizedEntityCommands
     {
-        [Dependency] private readonly IEntityManager _entityManager = default!;
+        [Dependency] private readonly IPlayerManager _players = default!;
+        [Dependency] private readonly SharedMindSystem _mind = default!;
+        [Dependency] private readonly SharedObjectivesSystem _objectives = default!;
 
-        public string Command => "rmobjective";
-        public string Description => "Removes an objective from the player's mind.";
-        public string Help => "rmobjective <username> <index>";
-        public void Execute(IConsoleShell shell, string argStr, string[] args)
+        public override string Command => "rmobjective";
+        public override void Execute(IConsoleShell shell, string argStr, string[] args)
         {
             if (args.Length != 2)
             {
-                shell.WriteLine("Expected exactly 2 arguments.");
+                shell.WriteError(Loc.GetString(Loc.GetString("cmd-rmobjective-invalid-args")));
                 return;
             }
 
-            var mgr = IoCManager.Resolve<IPlayerManager>();
-            var minds = _entityManager.System<SharedMindSystem>();
-            if (!mgr.TryGetSessionByUsername(args[0], out var session))
+            if (!_players.TryGetSessionByUsername(args[0], out var session))
             {
-                shell.WriteLine("Can't find the playerdata.");
+                shell.WriteError(Loc.GetString("cmd-rmojective-player-not-found"));
                 return;
             }
 
-            if (!minds.TryGetMind(session, out var mindId, out var mind))
+            if (!_mind.TryGetMind(session, out var mindId, out var mind))
             {
-                shell.WriteLine("Can't find the mind.");
+                shell.WriteError(Loc.GetString("cmd-rmojective-mind-not-found"));
                 return;
             }
 
             if (int.TryParse(args[1], out var i))
             {
-                var mindSystem = _entityManager.System<SharedMindSystem>();
-                shell.WriteLine(mindSystem.TryRemoveObjective(mindId, mind, i)
-                    ? "Objective successfully removed!"
-                    : "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
+                shell.WriteLine(Loc.GetString(_mind.TryRemoveObjective(mindId, mind, i)
+                    ? "cmd-rmobjective-success"
+                    : "cmd-rmobjective-failed"));
             }
             else
             {
-                shell.WriteLine($"Invalid index {args[1]}!");
+                shell.WriteError(Loc.GetString("cmd-rmobjective-invalid-index", ("index", args[1])));
             }
         }
+
+        public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+        {
+            if (args.Length == 1)
+            {
+                return CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), LocalizationManager.GetString("shell-argument-username-hint"));
+            }
+            if (args.Length == 2)
+            {
+                if (!_players.TryGetSessionByUsername(args[0], out var session))
+                    return CompletionResult.Empty;
+
+                if (!_mind.TryGetMind(session, out var mindId, out var mind))
+                    return CompletionResult.Empty;
+
+                if (mind.Objectives.Count == 0)
+                    return CompletionResult.Empty;
+
+                var options = new List<CompletionOption>();
+                for (int i = 0; i < mind.Objectives.Count; i++)
+                {
+                    var info = _objectives.GetInfo(mind.Objectives[i], mindId, mind);
+                    var hint = info == null ? Loc.GetString("cmd-rmobjective-invalid-objective-info") : $"{mind.Objectives[i]} ({info.Value.Title})";
+                    options.Add(new CompletionOption(i.ToString(), hint));
+                }
+
+                return CompletionResult.FromOptions(options);
+            }
+
+            return CompletionResult.Empty;
+        }
     }
 }
index b2e053f5f1d00f84f45ec40a259aafb72f2362d2..1b1fcabc981cece9b80486de468d797e79a9bd34 100644 (file)
@@ -371,7 +371,7 @@ public abstract partial class SharedMindSystem : EntitySystem
 
         // garbage collection - only delete the objective entity if no mind uses it anymore
         // This comes up for stuff like paradox clones where the objectives share the same entity
-        var mindQuery = new AllEntityQueryEnumerator<MindComponent>();
+        var mindQuery = AllEntityQuery<MindComponent>();
         while (mindQuery.MoveNext(out _, out var queryComp))
         {
             if (queryComp.Objectives.Contains(objective))
diff --git a/Resources/Locale/en-US/objectives/commands/rmobjective.ftl b/Resources/Locale/en-US/objectives/commands/rmobjective.ftl
new file mode 100644 (file)
index 0000000..82640f6
--- /dev/null
@@ -0,0 +1,14 @@
+# addobjectives
+cmd-rmobjective-desc = Removes an objective from the player's mind.
+cmd-rmobjective-help = rmobjective <username> <index>
+
+cmd-rmobjective-invalid-args = Expected exactly 2 arguments.
+cmd-rmobjective-player-not-found = Can't find the playerdata.
+cmd-rmobjective-mind-not-found = Can't find the mind.
+cmd-rmobjective-success = Objective successfully removed!
+cmd-rmobjective-failed = Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!
+cmd-rmobjective-invalid-index = Could not parse index { $index } as an integer.
+cmd-rmobjective-invalid-objective-info = INVALID
+
+cmd-rmobjective-player-completion = <Player>
+cmd-rmobjective-index-completion = <Index>