Skip to content

Commit

Permalink
Fix Rollbar# 26371
Browse files Browse the repository at this point in the history
Null protect `GetCargoWithEDName()`
  • Loading branch information
Tkael committed Aug 10, 2024
1 parent a98cfbb commit 0ca3b68
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions CargoMonitor/CargoMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand Down Expand Up @@ -621,6 +623,7 @@ private void _RemoveCargoWithEDName(string edname)
}
}

[CanBeNull]
public Cargo GetCargoWithEDName(string edname)
{
if (edname == null)
Expand Down

0 comments on commit 0ca3b68

Please sign in to comment.