Files
tbd-station-14/Content.Server/GameTicking/Commands/ForceMapCommand.cs
ArkiveDev d9506ce3a6 Force map confirmation (#29391)
* Add map check to forcemap command

* remove debug line

* remove accidental newline
2024-06-24 13:56:21 +03:00

58 lines
1.9 KiB
C#

using System.Linq;
using Content.Server.Administration;
using Content.Server.Maps;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
namespace Content.Server.GameTicking.Commands
{
[AdminCommand(AdminFlags.Round)]
sealed class ForceMapCommand : IConsoleCommand
{
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
public string Command => "forcemap";
public string Description => Loc.GetString("forcemap-command-description");
public string Help => Loc.GetString("forcemap-command-help");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteLine(Loc.GetString("forcemap-command-need-one-argument"));
return;
}
var gameMap = IoCManager.Resolve<IGameMapManager>();
var name = args[0];
if (!gameMap.TrySelectMapIfEligible(name))
{
shell.WriteLine($"No eligible map exists with name {name}.");
return;
}
_configurationManager.SetCVar(CCVars.GameMap, name);
shell.WriteLine(Loc.GetString("forcemap-command-success", ("map", name)));
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = IoCManager.Resolve<IPrototypeManager>()
.EnumeratePrototypes<GameMapPrototype>()
.Select(p => new CompletionOption(p.ID, p.MapName))
.OrderBy(p => p.Value);
return CompletionResult.FromHintOptions(options, Loc.GetString("forcemap-command-arg-map"));
}
return CompletionResult.Empty;
}
}
}