From 7ad0c5ae157997aa59baaa39a4c1d165622d87e3 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 17:55:36 -0800 Subject: [PATCH 1/3] player creation as separate method --- QSB/Player/QSBPlayerManager.cs | 24 ++++++++++++------- .../TransformSync/PlayerTransformSync.cs | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 6895a1da..9ee8503f 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -47,26 +47,32 @@ namespace QSB.Player { if (id is uint.MaxValue or 0U) { + DebugLog.ToConsole($"Warning - GetPlayer was given bad id {id}! Stacktrace : {Environment.StackTrace}", MessageType.Warning); return default; } var player = PlayerList.FirstOrDefault(x => x.PlayerId == id); - if (player != null) + if (player == null) { - return player; - } - - if (!QSBCore.IsInMultiplayer) - { - DebugLog.ToConsole($"Error - Tried to create player id:{id} when not in multiplayer! Stacktrace : {Environment.StackTrace}", MessageType.Error); + DebugLog.ToConsole($"Error - Player with id {id} does not exist! Stacktrace : {Environment.StackTrace}", MessageType.Error); return default; } + return player; + } + + public static void AddPlayer(uint id) + { + if (!QSBCore.IsInMultiplayer) + { + DebugLog.ToConsole($"Error - Tried to create player id:{id} when not in multiplayer!", MessageType.Error); + return; + } + DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); - player = new PlayerInfo(id); + var player = new PlayerInfo(id); PlayerList.Add(player); OnAddPlayer?.Invoke(id); - return player; } public static void RemovePlayer(uint id) diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index 8c90ead7..ef2e0209 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -50,6 +50,7 @@ namespace QSB.Player.TransformSync public override void Start() { base.Start(); + QSBPlayerManager.AddPlayer(PlayerId); Player.TransformSync = this; } From 3e8dee7c594129aa8e720c2c0bafc63136963d9f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 18:00:54 -0800 Subject: [PATCH 2/3] remove warning. it's okay --- QSB/Player/QSBPlayerManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 9ee8503f..762f375d 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -47,7 +47,6 @@ namespace QSB.Player { if (id is uint.MaxValue or 0U) { - DebugLog.ToConsole($"Warning - GetPlayer was given bad id {id}! Stacktrace : {Environment.StackTrace}", MessageType.Warning); return default; } From dd6b9f19e36b91e4250299a0ca7c9e58d85b4107 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 18:02:30 -0800 Subject: [PATCH 3/3] remove error that can't happen --- QSB/Player/QSBPlayerManager.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 762f375d..59a5361c 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -62,12 +62,6 @@ namespace QSB.Player public static void AddPlayer(uint id) { - if (!QSBCore.IsInMultiplayer) - { - DebugLog.ToConsole($"Error - Tried to create player id:{id} when not in multiplayer!", MessageType.Error); - return; - } - DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); var player = new PlayerInfo(id); PlayerList.Add(player);