Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
123 changes: 123 additions & 0 deletions EXILED/Exiled.CustomRoles/Commands/Get.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// -----------------------------------------------------------------------
// <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.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;

/// <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)
{
try
{
Player? playerSender = sender as Player;
if (playerSender is not null && !playerSender.CheckPermission("customroles.get"))
{
response = "Permission Denied, required: customroles.get";
return false;
}

List<Player> targets = ListPool<Player>.Pool.Get();

if (arguments.Count == 0)
{
if (playerSender == null)
{
response = "You need to provide arguments (ID/Nickname) in order to use this command.";
return false;
}

targets.Add(Player.Get(playerSender.ReferenceHub));
}
else
{
string identifier = string.Join(" ", arguments);

switch (identifier.ToLower())
{
case "*":
case "all":
targets.AddRange(Player.List);
break;

default:
IEnumerable<Player> foundPlayers = Player.GetProcessedData(arguments, 0);
if (foundPlayers.IsEmpty())
{
response = "No players found! Try using player ID or UserID.";
return false;
}

targets.AddRange(foundPlayers);
break;
}
}

StringBuilder builder = StringBuilderPool.Pool.Get();

foreach (Player target in targets)
{
CustomRole role = target.GetCustomRoles().FirstOrDefault();
if (role is null)
{
builder.AppendLine($"{target.Nickname.PadRight(30)} | None");
}
else
{
builder.AppendLine($"{target.Nickname.PadRight(30)} | {role.Name} [{role.Id}]");
}
}

builder.Insert(0, "===== Custom Roles =====\n");
builder.AppendLine("========================");

response = StringBuilderPool.Pool.ToStringReturn(builder);
ListPool<Player>.Pool.Return(targets);
return true;
}
catch (Exception e)
{
Log.Error(e);
response = "An error occurred while executing the command.";
return false;
}
}
}
}
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