forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 101
feat: added customroles get command #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
635e038
added customroles get command
An4r3w c57e08b
added multiple players logic, registered the command, removed PlayerC…
An4r3w 7e47704
fixed everything requested
An4r3w ab0a59a
Merge branch 'dev' into pr/661
louis1706 816f714
simplify
louis1706 b04633e
Merge branch 'dev' into feature2
louis1706 a4d76f4
Merge branch 'dev' into feature2
louis1706 dab3992
Make it actually work lol (+ look nicer)
Someone-193 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.