Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,12 @@ public bool TryAddFriendlyFire(Dictionary<RoleTypeId, float> ffRules, bool overw
return true;
}

/// <summary>
/// Returns the CustomRole in a human-readable format.
/// </summary>
/// <returns>A string containing CustomRole-related data.</returns>
public override string ToString() => $"{Name} ({Id})";

/// <summary>
/// Tries to register this role.
/// </summary>
Expand Down
116 changes: 116 additions & 0 deletions EXILED/Exiled.CustomRoles/Commands/Get.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// -----------------------------------------------------------------------
// <copyright file="Get.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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;

/// <summary>
/// The command to get specified player(s) current custom roles.
/// </summary>
internal sealed class Get : ICommand
{
private Get()
{
}

/// <summary>
/// Gets the <see cref="Get"/> command instance.
/// </summary>
public static Get Instance { get; } = new();

/// <inheritdoc/>
public string Command => "get";

/// <inheritdoc/>
public string[] Aliases { get; } = Array.Empty<string>();

/// <inheritdoc/>
public string Description => "Gets the specified player(s)' current custom role(s).";

/// <inheritdoc/>
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("customroles.get"))
{
response = "Permission Denied, required: customroles.get";
return false;
}

List<Player> players = ListPool<Player>.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 <Nickname/PlayerID/UserID/all/*>";
return false;
}

StringBuilder builder = StringBuilderPool.Pool.Get();

builder.AppendLine();
builder.AppendLine("================= Custom Roles =================");

foreach (Player target in players)
{
ReadOnlyCollection<CustomRole> 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<Player>.Pool.Return(players);

response = StringBuilderPool.Pool.ToStringReturn(builder);
return true;
}
}
}
3 changes: 2 additions & 1 deletion EXILED/Exiled.CustomRoles/Commands/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ public override void LoadGeneratedCommands()
RegisterCommand(Give.Instance);
RegisterCommand(Info.Instance);
RegisterCommand(List.List.Instance);
RegisterCommand(Get.Instance);
}

/// <inheritdoc/>
protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = "Invalid subcommand! Available: give, info, list";
response = "Invalid subcommand! Available: give, info, list, get";
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.CustomRoles/Exiled.CustomRoles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
<PostBuildEvent>if [[ ! -z "$EXILED_DEV_REFERENCES" ]]; then cp "$(OutputPath)$(AssemblyName).dll" "$EXILED_DEV_REFERENCES/Plugins/"; fi</PostBuildEvent>
</PropertyGroup>

</Project>
</Project>
Loading