Files
Pieter-Jan BriersandGitHub 5168b5f3d4 IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

74 lines
2.4 KiB
C#

using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Mind;
using Content.Shared.Objectives.Components;
using Content.Shared.Prototypes;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
namespace Content.Server.Objectives.Commands;
[AdminCommand(AdminFlags.Admin)]
public sealed partial class AddObjectiveCommand : LocalizedEntityCommands
{
[Dependency] private IPlayerManager _players = default!;
[Dependency] private IPrototypeManager _prototypes = default!;
[Dependency] private SharedMindSystem _mind = default!;
[Dependency] private ObjectivesSystem _objectives = default!;
public override string Command => "addobjective";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("cmd-addobjective-invalid-args"));
return;
}
if (!_players.TryGetSessionByUsername(args[0], out var data))
{
shell.WriteError(Loc.GetString("cmd-addobjective-player-not-found"));
return;
}
if (!_mind.TryGetMind(data, out var mindId, out var mind))
{
shell.WriteError(Loc.GetString("cmd-addobjective-mind-not-found"));
return;
}
if (!_prototypes.TryIndex<EntityPrototype>(args[1], out var proto) ||
!proto.HasComponent<ObjectiveComponent>())
{
shell.WriteError(Loc.GetString("cmd-addobjective-objective-not-found", ("obj", args[1])));
return;
}
if (!_mind.TryAddObjective(mindId, mind, args[1]))
{
// can fail for other reasons so dont pretend to be right
shell.WriteError(Loc.GetString("cmd-addobjective-adding-failed"));
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = _players.Sessions.OrderBy(c => c.Name).Select(c => c.Name).ToArray();
return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-addobjective-player-completion"));
}
if (args.Length != 2)
return CompletionResult.Empty;
return CompletionResult.FromHintOptions(
_objectives.Objectives(),
Loc.GetString("cmd-add-objective-obj-completion"));
}
}