Skip to content
Open
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
91 changes: 91 additions & 0 deletions EXILED/Exiled.CustomRoles/Commands/Get.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// -----------------------------------------------------------------------
// <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; } = "get";

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

/// <inheritdoc/>
public string Description { get; } = "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;
}

IEnumerable<Player> 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again iirc IEnumerable::AddItem returns new IEnumerable

}

StringBuilder builder = StringBuilderPool.Pool.Get();

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

foreach (Player target in players)
{
ReadOnlyCollection<CustomRole> 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;
}
}
}
1 change: 1 addition & 0 deletions EXILED/Exiled.CustomRoles/Commands/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public override void LoadGeneratedCommands()
RegisterCommand(Give.Instance);
RegisterCommand(Info.Instance);
RegisterCommand(List.List.Instance);
RegisterCommand(Get.Instance);
}

/// <inheritdoc/>
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