diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index f29e2d525c..afce01ccdf 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -790,6 +790,12 @@ public bool TryAddFriendlyFire(Dictionary ffRules, bool overw return true; } + /// + /// Returns the CustomRole in a human-readable format. + /// + /// A string containing CustomRole-related data. + public override string ToString() => $"{Name} ({Id})"; + /// /// Tries to register this role. /// diff --git a/EXILED/Exiled.CustomRoles/Commands/Get.cs b/EXILED/Exiled.CustomRoles/Commands/Get.cs new file mode 100644 index 0000000000..2bc08b6299 --- /dev/null +++ b/EXILED/Exiled.CustomRoles/Commands/Get.cs @@ -0,0 +1,116 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.CustomRoles.Commands +{ + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Linq; + using System.Text; + + using CommandSystem; + using Exiled.API.Features; + using Exiled.API.Features.Pools; + using Exiled.CustomRoles.API; + using Exiled.CustomRoles.API.Features; + using Exiled.Permissions.Extensions; + using HarmonyLib; + + /// + /// The command to get specified player(s) current custom roles. + /// + internal sealed class Get : ICommand + { + private Get() + { + } + + /// + /// Gets the command instance. + /// + public static Get Instance { get; } = new(); + + /// + public string Command => "get"; + + /// + public string[] Aliases { get; } = Array.Empty(); + + /// + public string Description => "Gets the specified player(s)' current custom role(s)."; + + /// + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + if (!sender.CheckPermission("customroles.get")) + { + response = "Permission Denied, required: customroles.get"; + return false; + } + + List players = ListPool.Pool.Get(); + + if (arguments.Count > 0) + { + string identifier = string.Join(" ", arguments); + + switch (identifier) + { + case "*": + case "all": + players.AddRange(Player.List); + break; + default: + players.AddRange(Player.GetProcessedData(arguments)); + break; + } + + if (players.IsEmpty()) + { + if (arguments.Count > 0 || !Player.TryGet(sender, out Player player)) + { + response = $"Player not found: {identifier}"; + return false; + } + + players.Add(player); + } + } + else + { + response = "get "; + return false; + } + + StringBuilder builder = StringBuilderPool.Pool.Get(); + + builder.AppendLine(); + builder.AppendLine("================= Custom Roles ================="); + + foreach (Player target in players) + { + ReadOnlyCollection roles = target.GetCustomRoles(); + if (roles.IsEmpty()) + { + builder.AppendLine($"{target.DisplayNickname.PadRight(30)} | None"); + } + else + { + builder.AppendLine($"{target.DisplayNickname.PadRight(30)} ({target.Id}) | [{string.Join(", ", roles.Select(role => role.ToString()))}]"); + } + } + + builder.AppendLine("================================================"); + + ListPool.Pool.Return(players); + + response = StringBuilderPool.Pool.ToStringReturn(builder); + return true; + } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.CustomRoles/Commands/Parent.cs b/EXILED/Exiled.CustomRoles/Commands/Parent.cs index f64facabec..fd42b5e497 100644 --- a/EXILED/Exiled.CustomRoles/Commands/Parent.cs +++ b/EXILED/Exiled.CustomRoles/Commands/Parent.cs @@ -41,12 +41,13 @@ public override void LoadGeneratedCommands() RegisterCommand(Give.Instance); RegisterCommand(Info.Instance); RegisterCommand(List.List.Instance); + RegisterCommand(Get.Instance); } /// protected override bool ExecuteParent(ArraySegment arguments, ICommandSender sender, out string response) { - response = "Invalid subcommand! Available: give, info, list"; + response = "Invalid subcommand! Available: give, info, list, get"; return false; } } diff --git a/EXILED/Exiled.CustomRoles/Exiled.CustomRoles.csproj b/EXILED/Exiled.CustomRoles/Exiled.CustomRoles.csproj index 78b2030580..cd1a8b4769 100644 --- a/EXILED/Exiled.CustomRoles/Exiled.CustomRoles.csproj +++ b/EXILED/Exiled.CustomRoles/Exiled.CustomRoles.csproj @@ -49,4 +49,4 @@ if [[ ! -z "$EXILED_DEV_REFERENCES" ]]; then cp "$(OutputPath)$(AssemblyName).dll" "$EXILED_DEV_REFERENCES/Plugins/"; fi - + \ No newline at end of file