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..e0e29d7759 --- /dev/null +++ b/EXILED/Exiled.CustomRoles/Commands/Get.cs @@ -0,0 +1,91 @@ +// ----------------------------------------------------------------------- +// +// 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; } = "get"; + + /// + public string[] Aliases { get; } = Array.Empty(); + + /// + public string Description { get; } = "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; + } + + IEnumerable players = Player.GetProcessedData(arguments); + if (players.IsEmpty()) + { + if (arguments.Count > 0 || !Player.TryGet(sender, out Player player)) + { + response = $"Player not found: {arguments.ElementAtOrDefault(0)}"; + return false; + } + + players.AddItem(player); + } + + StringBuilder builder = StringBuilderPool.Pool.Get(); + + builder.AppendLine("===== Custom Roles ====="); + + foreach (Player target in players) + { + ReadOnlyCollection role = target.GetCustomRoles(); + if (role.IsEmpty()) + { + builder.AppendLine($"{target.DisplayNickname.PadRight(30)} | None"); + } + else + { + builder.AppendLine($"{target.DisplayNickname.PadRight(30)} ({target.Id}) | {string.Join("-", role.ToString())}]"); + } + } + + builder.AppendLine("========================"); + + 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..13365edf0b 100644 --- a/EXILED/Exiled.CustomRoles/Commands/Parent.cs +++ b/EXILED/Exiled.CustomRoles/Commands/Parent.cs @@ -41,6 +41,7 @@ public override void LoadGeneratedCommands() RegisterCommand(Give.Instance); RegisterCommand(Info.Instance); RegisterCommand(List.List.Instance); + RegisterCommand(Get.Instance); } /// 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