Files
tbd-station-14/Content.Server/Administration/Commands/SetAdminOOC.cs
Brandon Hu 31c5d3555e fix(Commands): Improve Localization of commands. Standardize some behaviors. (#30362)
* I should be studying for school but that is sofucking boring, I will pass my class no matter, however getting an A might be a challenge. My gpa is important but is the tourture for 1 point of GPA worth it? The american government says yes but they are responsible for the majority of all genocides that have ever been conducted since the dawn of man

* ugh

* ugh
2024-08-11 19:46:57 +10:00

48 lines
1.6 KiB
C#

using Content.Server.Database;
using Content.Server.Preferences.Managers;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.NameColor)]
internal sealed class SetAdminOOC : IConsoleCommand
{
public string Command => "setadminooc";
public string Description => Loc.GetString("set-admin-ooc-command-description", ("command", Command));
public string Help => Loc.GetString("set-admin-ooc-command-help-text", ("command", Command));
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player == null)
{
shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
return;
}
if (args.Length < 1)
return;
var colorArg = string.Join(" ", args).Trim();
if (string.IsNullOrEmpty(colorArg))
return;
var color = Color.TryFromHex(colorArg);
if (!color.HasValue)
{
shell.WriteError(Loc.GetString("shell-invalid-color-hex"));
return;
}
var userId = shell.Player.UserId;
// Save the DB
var dbMan = IoCManager.Resolve<IServerDbManager>();
dbMan.SaveAdminOOCColorAsync(userId, color.Value);
// Update the cached preference
var prefManager = IoCManager.Resolve<IServerPreferencesManager>();
var prefs = prefManager.GetPreferences(userId);
prefs.AdminOOCColor = color.Value;
}
}
}