76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CommandSystem;
|
|
using RemoteAdmin;
|
|
|
|
namespace DeathLog;
|
|
|
|
[CommandHandler(typeof(RemoteAdminCommandHandler))]
|
|
public sealed class ToggleLogsCommand : ICommand
|
|
{
|
|
|
|
public static readonly HashSet<string> HiddenIdList = new();
|
|
public static readonly Dictionary<string, float> SizeScalar = new();
|
|
|
|
public string Command => "toggleKillLogs";
|
|
public string[] Aliases { get; } = {"tkl"};
|
|
public string Description => "Toggles the visibility of kill logs or changes the font size scalar for the caller.";
|
|
public bool SanitizeResponse => false;
|
|
|
|
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
|
|
{
|
|
if (sender is not PlayerCommandSender {ReferenceHub.authManager.UserId: var id})
|
|
{
|
|
response = "You must be a player to use this command.";
|
|
return false;
|
|
}
|
|
|
|
if (arguments.Count < 1)
|
|
{
|
|
if (HiddenIdList.Add(id))
|
|
response = "You will no longer see kill logs.";
|
|
else
|
|
{
|
|
HiddenIdList.Remove(id);
|
|
response = "You will now see kill logs.";
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
switch (arguments.At(0).ToLower())
|
|
{
|
|
case "on" or "enable" or "true" or "yes":
|
|
HiddenIdList.Remove(id);
|
|
response = "You will now see kill logs.";
|
|
return true;
|
|
case "off" or "disable" or "false" or "no":
|
|
HiddenIdList.Add(id);
|
|
response = "You will no longer see kill logs.";
|
|
return true;
|
|
default:
|
|
return ParseScalar(arguments, id, out response);
|
|
}
|
|
}
|
|
|
|
private static bool ParseScalar(ArraySegment<string> arguments, string id, out string response)
|
|
{
|
|
if (!float.TryParse(arguments.At(0), out var scalar))
|
|
{
|
|
response = "Invalid argument. Expected a float or a boolean.";
|
|
return false;
|
|
}
|
|
|
|
if (scalar is not (> 0 and <= 5))
|
|
{
|
|
response = "Invalid argument. Expected a float in range 0-5.";
|
|
return false;
|
|
}
|
|
|
|
SizeScalar[id] = scalar;
|
|
response = $"Your kill log font size scalar is now {scalar}.";
|
|
return true;
|
|
}
|
|
|
|
}
|