slightly optimize

This commit is contained in:
JohnCorby 2021-12-27 15:38:29 -08:00
parent acd2ff486f
commit ce37ecff9e
2 changed files with 5 additions and 26 deletions

View File

@ -24,12 +24,6 @@ namespace QSB.Player
return uint.MaxValue;
}
if (localInstance.NetIdentity == null)
{
DebugLog.ToConsole($"Error - Trying to get LocalPlayerId when the local PlayerTransformSync instance's QNetworkIdentity is null.", MessageType.Error);
return uint.MaxValue;
}
return localInstance.NetIdentity.NetId.Value;
}
}
@ -38,13 +32,13 @@ namespace QSB.Player
public static Action<uint> OnAddPlayer;
public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId);
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
public static readonly List<PlayerInfo> PlayerList = new();
private static readonly List<PlayerSyncObject> PlayerSyncObjects = new();
public static PlayerInfo GetPlayer(uint id)
{
if (id is uint.MaxValue or 0U)
if (id is uint.MaxValue or 0)
{
return default;
}
@ -74,7 +68,7 @@ namespace QSB.Player
}
public static bool PlayerExists(uint id) =>
id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
id is not (uint.MaxValue or 0) && PlayerList.Any(x => x.PlayerId == id);
public static IEnumerable<T> GetSyncObjects<T>() where T : PlayerSyncObject =>
PlayerSyncObjects.OfType<T>().Where(x => x != null);

View File

@ -1,6 +1,5 @@
using OWML.Common;
using QSB.Player;
using QSB.Player.TransformSync;
using QuantumUNET;
using System;
using System.Collections.Generic;
@ -41,28 +40,14 @@ namespace QSB.Utility
return uint.MaxValue;
}
var playerController = connection.PlayerControllers[0];
var playerController = connection.PlayerControllers.FirstOrDefault();
if (playerController == null)
{
DebugLog.ToConsole($"Error - Player Controller of {connection.address} is null.", MessageType.Error);
return uint.MaxValue;
}
var go = playerController.Gameobject;
if (go == null)
{
DebugLog.ToConsole($"Error - GameObject of {playerController.UnetView.NetId.Value} is null.", MessageType.Error);
return uint.MaxValue;
}
var controller = go.GetComponent<PlayerTransformSync>();
if (controller == null)
{
DebugLog.ToConsole($"Error - No PlayerTransformSync found on {go.name}", MessageType.Error);
return uint.MaxValue;
}
return controller.NetId.Value;
return playerController.UnetView.NetId.Value;
}
public static void SpawnWithServerAuthority(this GameObject go)