[Server] Suggest using `IEnumerable` for EmitClients instead of array in core implementation
duydang2311 opened this issue · comments
As for now, the Alt.EmitClients
takes IPlayer[]
as its first argument.
It seems better to prefer IEnumerable<IPlayer>
here, so in piece of code like below example can avoid creating a new array with ToArray
.
After having a look at the core implementation, I think this change can be made into the core, as a foreach
loop can replace the for
one https://github.com/FabianTerhorst/coreclr-module/blob/dev/api/AltV.Net/Core.cs#L343.
Plus, this change also doesn't break anything because IEnumerable
is array base type.
Example where an extra array must be created to satisfy EmitClients
first argument:
public void BroadcastMessage(Predicate<AltIPlayer> predicate, string color, string message)
{
var players = new LinkedList<AltIPlayer>();
foreach (var p in Alt.GetAllPlayers())
{
if (predicate(p))
{
players.AddLast(p);
}
}
Alt.EmitClients(players.ToArray(), "chat.message", color, message);
}
If it's reasonable, I can try working on this.