From dd7ec537b9a32996f2dd5c6f187e07f90cef0c17 Mon Sep 17 00:00:00 2001 From: Karim Rizk Date: Fri, 5 Jan 2024 16:26:19 +0200 Subject: [PATCH] Fix null returns in extension methods --- NebulaAPI/Extensions/IEnumerableExtensions.cs | 5 ++--- NebulaAPI/Extensions/PlayerCollectionExtensions.cs | 6 +++--- .../PacketProcessors/Session/SyncCompleteProcessor.cs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/NebulaAPI/Extensions/IEnumerableExtensions.cs b/NebulaAPI/Extensions/IEnumerableExtensions.cs index 5411cff45..b56ad3e68 100644 --- a/NebulaAPI/Extensions/IEnumerableExtensions.cs +++ b/NebulaAPI/Extensions/IEnumerableExtensions.cs @@ -6,12 +6,13 @@ using System; using System.Collections.Generic; +using System.Linq; namespace NebulaAPI.Extensions; public static class IEnumerableExtensions { - public static IEnumerable ForEach(this IEnumerable source, Action action) + public static void ForEach(this IEnumerable source, Action action) { if (source is null) throw new ArgumentNullException(nameof(source)); if (action is null) throw new ArgumentNullException(nameof(action)); @@ -20,7 +21,5 @@ public static IEnumerable ForEach(this IEnumerable source, Action ac { action(item); } - - return source; } } diff --git a/NebulaAPI/Extensions/PlayerCollectionExtensions.cs b/NebulaAPI/Extensions/PlayerCollectionExtensions.cs index 0f67d4ae6..96e077306 100644 --- a/NebulaAPI/Extensions/PlayerCollectionExtensions.cs +++ b/NebulaAPI/Extensions/PlayerCollectionExtensions.cs @@ -102,13 +102,13 @@ public static IReadOnlyCollection GetConnected( /// Returns a collection of all player data, including host. /// /// - public static ICollection GetAllPlayerData(this IReadOnlyCollection players) + public static IEnumerable GetAllPlayerData(this IReadOnlyCollection players) { var saves = players - .Select(p => p.Data) as ICollection; + .Select(p => p.Data).ToList(); // If the host is a player, append their data to the list if (!NebulaModAPI.MultiplayerSession.IsDedicated) - saves?.Add(NebulaModAPI.MultiplayerSession.LocalPlayer.Data); + saves.Add(NebulaModAPI.MultiplayerSession.LocalPlayer.Data); return saves; } diff --git a/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs b/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs index 4b3a2b0e4..ed566a746 100644 --- a/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/SyncCompleteProcessor.cs @@ -69,7 +69,7 @@ private void ServerSyncComplete(SyncComplete packet, NebulaConnection conn) return; } - var inGamePlayersDatas = Multiplayer.Session.Server.Players.GetAllPlayerData().ToArray(); + var inGamePlayersDatas = Multiplayer.Session.Server.Players.GetAllPlayerData(); playerManager.SendPacketToAllPlayers(new SyncComplete(inGamePlayersDatas)); // Since the host is always in the game he could already have changed his mecha armor, so send it to the new player.