Files
tbd-station-14/Content.Server/StationEvents/StationEventCommand.cs
DrSmugleaf 74943a2770 Typo, redundant string interpolation, namespaces and imports cleanup (#2068)
* Readonly, typos and redundant string interpolations

* Namespaces

* Optimize imports

* Address reviews

* but actually

* Localize missing strings

* Remove redundant vars
2020-09-13 14:23:52 +02:00

101 lines
3.6 KiB
C#

#nullable enable
using Content.Server.GameObjects.EntitySystems.StationEvents;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Localization;
namespace Content.Server.StationEvents
{
[UsedImplicitly]
public sealed class StationEventCommand : IClientCommand
{
public string Command => "events";
public string Description => "Provides admin control to station events";
public string Help => "events <list/pause/resume/stop/run <eventname/random>>\n" +
"list: return all event names that can be run\n " +
"pause: stop all random events from running\n" +
"resume: allow random events to run again\n" +
"run: start a particular event now; <eventname> is case-insensitive and not localized";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
if (args.Length == 0)
{
shell.SendText(player, "Need more args");
return;
}
if (args[0] == "list")
{
var resultText = "Random\n" + EntitySystem.Get<StationEventSystem>().GetEventNames();
shell.SendText(player, resultText);
return;
}
// Didn't use a "toggle" so it's explicit
if (args[0] == "pause")
{
var stationEventSystem = EntitySystem.Get<StationEventSystem>();
if (!stationEventSystem.Enabled)
{
shell.SendText(player, Loc.GetString("Station events are already paused"));
return;
}
else
{
stationEventSystem.Enabled = false;
shell.SendText(player, Loc.GetString("Station events paused"));
return;
}
}
if (args[0] == "resume")
{
var stationEventSystem = EntitySystem.Get<StationEventSystem>();
if (stationEventSystem.Enabled)
{
shell.SendText(player, Loc.GetString("Station events are already running"));
return;
}
else
{
stationEventSystem.Enabled = true;
shell.SendText(player, Loc.GetString("Station events resumed"));
return;
}
}
if (args[0] == "stop")
{
var resultText = EntitySystem.Get<StationEventSystem>().StopEvent();
shell.SendText(player, resultText);
return;
}
if (args[0] == "run" && args.Length == 2)
{
var eventName = args[1];
string resultText;
if (eventName == "random")
{
resultText = EntitySystem.Get<StationEventSystem>().RunRandomEvent();
}
else
{
resultText = EntitySystem.Get<StationEventSystem>().RunEvent(eventName);
}
shell.SendText(player, resultText);
return;
}
shell.SendText(player, Loc.GetString("Invalid events command"));
return;
}
}
}