Skip to content

Commit

Permalink
Updated CustomItems & CustomRoles give commands to use default RAUtil…
Browse files Browse the repository at this point in the history
…s.ProcessPlayerIdOrNamesList (#179)

* Update Give.cs

* Update Give.cs

* fixed style violation

* Fixed issue

* Player.GetProcessedData

* Update EXILED.props

* list.isempty

* Revert "Update EXILED.props"

This reverts commit 410fb61.

---------

Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
  • Loading branch information
icedchai and louis1706 authored Nov 25, 2024
1 parent e5c54b7 commit e63a7ca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
33 changes: 20 additions & 13 deletions EXILED/Exiled.CustomItems/Commands/Give.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Exiled.CustomItems.Commands
using Exiled.Permissions.Extensions;

using RemoteAdmin;
using UnityStandardAssets.Effects;
using Utils;

/// <summary>
/// The command to give a player an item.
Expand Down Expand Up @@ -97,27 +99,32 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
response = $"Custom item {item?.Name} given to all players who can receive them ({eligiblePlayers.Count} players)";
return true;
default:
if (Player.Get(identifier) is not { } player)
{
response = $"Unable to find player: {identifier}.";
return false;
}
break;
}

if (!CheckEligible(player))
{
response = "Player cannot receive custom items!";
return false;
}
IEnumerable<Player> list = Player.GetProcessedData(arguments, 1);

if (list.IsEmpty())
{
response = "Cannot find player! Try using the player ID!";
return false;
}

foreach (Player player in list)
{
if (CheckEligible(player))
{
item?.Give(player);
response = $"{item?.Name} given to {player.Nickname} ({player.UserId})";
return true;
}
}

response = $"{item?.Name} given to {list.Count()} players!";
return true;
}

/// <summary>
/// Checks if the player is eligible to receive custom items.
/// </summary>
private bool CheckEligible(Player player) => player.IsAlive && !player.IsCuffed && (player.Items.Count < 8);
}
}
}
27 changes: 18 additions & 9 deletions EXILED/Exiled.CustomRoles/Commands/Give.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Exiled.CustomRoles.Commands
using Exiled.Permissions.Extensions;

using RemoteAdmin;
using Utils;

/// <summary>
/// The command to give a role to player(s).
Expand Down Expand Up @@ -96,16 +97,24 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
ListPool<Player>.Pool.Return(players);
return true;
default:
if (Player.Get(identifier) is not Player ply)
{
response = $"Unable to find a player: {identifier}";
return false;
}

role.AddRole(ply);
response = $"{role.Name} given to {ply.Nickname}.";
return true;
break;
}

IEnumerable<Player> list = Player.GetProcessedData(arguments, 1);
if (list.IsEmpty())
{
response = "Cannot find player! Try using the player ID!";
return false;
}

foreach (Player player in list)
{
role.AddRole(player);
}

response = $"Customrole {role.Name} given to {list.Count()} players!";

return true;
}
catch (Exception e)
{
Expand Down

0 comments on commit e63a7ca

Please sign in to comment.