mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 19:01:13 +03:00
45 lines
1.4 KiB
C#
45 lines
1.4 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 partial class SetAdminOOC : LocalizedCommands
|
|
{
|
|
[Dependency] private IServerDbManager _dbManager = default!;
|
|
[Dependency] private IServerPreferencesManager _preferenceManager = default!;
|
|
|
|
public override string Command => "setadminooc";
|
|
|
|
public override 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;
|
|
|
|
if (!Color.TryFromHex(colorArg, out var color))
|
|
{
|
|
shell.WriteError(Loc.GetString("shell-invalid-color-hex"));
|
|
return;
|
|
}
|
|
|
|
var userId = shell.Player.UserId;
|
|
// Save the DB
|
|
_dbManager.SaveAdminOOCColorAsync(userId, color);
|
|
// Update the cached preference
|
|
var prefs = _preferenceManager.GetPreferences(userId);
|
|
prefs.AdminOOCColor = color;
|
|
}
|
|
}
|
|
}
|