@@ -28,11 +28,14 @@ public PlayerHeldItemChangedProcessor(PlayerManager playerManager)
2828
2929 public Task Process ( ClientProcessorContext context , PlayerHeldItemChanged packet )
3030 {
31- Optional < RemotePlayer > opPlayer = playerManager . Find ( packet . SessionId ) ;
32- Validate . IsPresent ( opPlayer ) ;
33-
31+ if ( ! playerManager . TryFind ( packet . SessionId , out RemotePlayer player ) )
32+ {
33+ Log . Warn ( $ "[{ nameof ( PlayerHeldItemChangedProcessor ) } ] Could not find player with session id: { packet . SessionId } .") ;
34+ return Task . CompletedTask ;
35+ }
3436 if ( ! NitroxEntity . TryGetObjectFrom ( packet . ItemId , out GameObject item ) )
3537 {
38+ Log . Warn ( $ "[{ nameof ( PlayerHeldItemChangedProcessor ) } ] Could not find entity with id: { packet . ItemId } .") ;
3639 return Task . CompletedTask ;
3740 }
3841
@@ -41,15 +44,15 @@ public Task Process(ClientProcessorContext context, PlayerHeldItemChanged packet
4144
4245 Validate . NotNull ( pickupable . inventoryItem ) ;
4346
44- ItemsContainer inventory = opPlayer . Value . Inventory ;
47+ ItemsContainer inventory = player . Inventory ;
4548 PlayerTool tool = item . GetComponent < PlayerTool > ( ) ;
4649
4750 // Copied from QuickSlots
4851 switch ( packet . Type )
4952 {
5053 case PlayerHeldItemChanged . ChangeType . DRAW_AS_TOOL :
5154 Validate . IsTrue ( tool ) ;
52- ModelPlug . PlugIntoSocket ( tool , opPlayer . Value . ItemAttachPoint ) ;
55+ ModelPlug . PlugIntoSocket ( tool , player . ItemAttachPoint ) ;
5356 Utils . SetLayerRecursively ( item , viewModelLayer ) ;
5457 foreach ( Animator componentsInChild in tool . GetComponentsInChildren < Animator > ( ) )
5558 {
@@ -66,8 +69,8 @@ public Task Process(ClientProcessorContext context, PlayerHeldItemChanged packet
6669 }
6770 item . SetActive ( true ) ;
6871 tool . SetHandIKTargetsEnabled ( true ) ;
69- SafeAnimator . SetBool ( opPlayer . Value . ArmsController . GetComponent < Animator > ( ) , $ "holding_{ tool . animToolName } ", true ) ;
70- opPlayer . Value . AnimationController [ "using_tool_first" ] = packet . IsFirstTime != null ;
72+ SafeAnimator . SetBool ( player . ArmsController . GetComponent < Animator > ( ) , $ "holding_{ tool . animToolName } ", true ) ;
73+ player . AnimationController [ "using_tool_first" ] = packet . IsFirstTime != null ;
7174
7275 if ( item . TryGetComponent ( out FPModel fpModelDraw ) ) //FPModel needs to be updated
7376 {
@@ -93,8 +96,8 @@ public Task Process(ClientProcessorContext context, PlayerHeldItemChanged packet
9396 {
9497 componentsInChild . cullingMode = AnimatorCullingMode . CullUpdateTransforms ;
9598 }
96- SafeAnimator . SetBool ( opPlayer . Value . ArmsController . GetComponent < Animator > ( ) , $ "holding_{ tool . animToolName } ", false ) ;
97- opPlayer . Value . AnimationController [ "using_tool_first" ] = false ;
99+ SafeAnimator . SetBool ( player . ArmsController . GetComponent < Animator > ( ) , $ "holding_{ tool . animToolName } ", false ) ;
100+ player . AnimationController [ "using_tool_first" ] = false ;
98101
99102 if ( item . TryGetComponent ( out FPModel fpModelHolster ) ) //FPModel needs to be updated
100103 {
@@ -104,7 +107,7 @@ public Task Process(ClientProcessorContext context, PlayerHeldItemChanged packet
104107 break ;
105108
106109 case PlayerHeldItemChanged . ChangeType . DRAW_AS_ITEM :
107- pickupable . inventoryItem . item . Reparent ( opPlayer . Value . ItemAttachPoint ) ;
110+ pickupable . inventoryItem . item . Reparent ( player . ItemAttachPoint ) ;
108111 pickupable . inventoryItem . item . SetVisible ( true ) ;
109112 Utils . SetLayerRecursively ( pickupable . inventoryItem . item . gameObject , viewModelLayer ) ;
110113 break ;
0 commit comments