From 0ca3b6833af809711047ae78a5e1a0cc5e9663ba Mon Sep 17 00:00:00 2001 From: T'kael Date: Sat, 10 Aug 2024 16:12:04 -0700 Subject: [PATCH] Fix Rollbar# 26371 Null protect `GetCargoWithEDName()` --- CargoMonitor/CargoMonitor.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CargoMonitor/CargoMonitor.cs b/CargoMonitor/CargoMonitor.cs index ff06fdea2b..1b21f708d5 100644 --- a/CargoMonitor/CargoMonitor.cs +++ b/CargoMonitor/CargoMonitor.cs @@ -258,7 +258,8 @@ private void handleCommodityCollectedEvent(CommodityCollectedEvent @event) private void _handleCommodityCollectedEvent(CommodityCollectedEvent @event) { - var cargo = GetCargoWithEDName(@event.commodityDefinition?.edname) ?? new Cargo(@event.commodityDefinition?.edname); + var cargo = GetCargoWithEDName( @event.commodityDefinition?.edname ) ?? + new Cargo( @event.commodityDefinition?.edname ); if ( @event.missionid != null ) { cargo.AddDetailedQty( (long)@event.missionid, 1 ); @@ -287,14 +288,13 @@ private void handleCommodityEjectedEvent(CommodityEjectedEvent @event) private void _handleCommodityEjectedEvent(CommodityEjectedEvent @event) { var cargo = GetCargoWithEDName(@event.commodityDefinition?.edname); - if ( cargo == null ) { return; } if ( @event.missionid != null ) { - cargo.RemoveDetailedQty( (long)@event.missionid, @event.amount ); + cargo?.RemoveDetailedQty( (long)@event.missionid, @event.amount ); } else { - cargo.RemoveDetailedQty( CargoType.legal, @event.amount ); + cargo?.RemoveDetailedQty( CargoType.legal, @event.amount ); } TryRemoveCargo( cargo ); } @@ -311,7 +311,8 @@ private void handleCommodityPurchasedEvent(CommodityPurchasedEvent @event) private void _handleCommodityPurchasedEvent(CommodityPurchasedEvent @event) { - var cargo = GetCargoWithEDName(@event.commodityDefinition?.edname) ?? new Cargo(@event.commodityDefinition?.edname); + var cargo = GetCargoWithEDName( @event.commodityDefinition?.edname ) ?? + new Cargo( @event.commodityDefinition?.edname ); cargo.AddDetailedQty( CargoType.legal, @event.amount, @event.price ); AddOrUpdateCargo( cargo ); } @@ -328,7 +329,8 @@ private void handleCommodityRefinedEvent(CommodityRefinedEvent @event) private void _handleCommodityRefinedEvent(CommodityRefinedEvent @event) { - var cargo = GetCargoWithEDName(@event.commodityDefinition?.edname); + var cargo = GetCargoWithEDName( @event.commodityDefinition?.edname ) ?? + new Cargo( @event.commodityDefinition?.edname ); cargo.AddDetailedQty( CargoType.legal, 1, 0 ); AddOrUpdateCargo( cargo ); } @@ -621,6 +623,7 @@ private void _RemoveCargoWithEDName(string edname) } } + [CanBeNull] public Cargo GetCargoWithEDName(string edname) { if (edname == null)