Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
50 changes: 35 additions & 15 deletions EXILED/Exiled.CustomItems/Commands/Give.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Exiled.CustomItems.Commands
using Exiled.Permissions.Extensions;

using RemoteAdmin;
using Utils;

/// <summary>
/// The command to give a player an item.
Expand Down Expand Up @@ -83,7 +84,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
response = "Failed to provide a valid player, please follow the syntax.";
return false;
}

string identifier = string.Join(" ", arguments.Skip(1));

switch (identifier)
Expand All @@ -97,27 +98,46 @@ 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;
}

string[] newargs;
List<ReferenceHub> list = RAUtils.ProcessPlayerIdOrNamesList(arguments, 1, out newargs);
Comment thread
louis1706 marked this conversation as resolved.
Outdated
if (list == null)
Comment thread
icedchai marked this conversation as resolved.
Outdated
{
response = "Cannot find player! Try using the player ID!";
return false;
}

foreach (ReferenceHub hub in list)
{
Player player = Player.Get(hub);
if (!CheckEligible(player))
{
list.Remove(hub);
}

if (!CheckEligible(player))
{
response = "Player cannot receive custom items!";
return false;
}
item?.Give(player);
}

if (list.Count == 1)
{
Player player = Player.Get(list[0]);
response = $"{item?.Name} given to {player.Nickname} ({player.UserId})";
}

item?.Give(player);
response = $"{item?.Name} given to {player.Nickname} ({player.UserId})";
return true;
else
{
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);
}
}
}
35 changes: 26 additions & 9 deletions EXILED/Exiled.CustomRoles/Commands/Give.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Exiled.CustomRoles.Commands
using Exiled.Permissions.Extensions;

using RemoteAdmin;
using static HarmonyLib.Code;
using Utils;

/// <summary>
/// The command to give a role to player(s).
Expand Down Expand Up @@ -96,16 +98,31 @@ 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;
}
string[] newargs;
List<ReferenceHub> list = RAUtils.ProcessPlayerIdOrNamesList(arguments, 1, out newargs);
if (list == null)
Comment thread
icedchai marked this conversation as resolved.
Outdated
{
response = "Cannot find player! Try using the player ID!";
return false;
}
foreach (ReferenceHub hub in list)
{
Player player = Player.Get(hub);
role.AddRole(player);
}
if (list.Count == 1)
{
Player player = Player.Get(list[0]);
role.AddRole(player);
response = $"Customrole {role.Name} given to {player.Nickname} ({player.UserId})";
}
Comment thread
louis1706 marked this conversation as resolved.
Outdated
else
{
response = $"Customrole {role.Name} given to {list.Count} players!";
}
return true;
}
catch (Exception e)
{
Expand Down