Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit de6c0e8

Browse files
committed
Player block enforcement crash fix
1 parent ec11327 commit de6c0e8

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

EssentialsPlugin/Utility/PlayerBlockEnforcement.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
54
using System.Threading.Tasks;
5+
using System.Threading;
6+
using Sandbox.Game.Entities;
7+
using Sandbox.Game.Entities.Cube;
8+
using Sandbox.Game.World;
9+
using Sandbox.ModAPI;
10+
using EssentialsPlugin.Settings;
11+
using SEModAPIInternal.API.Common;
12+
using VRage.Game;
13+
using VRage.Game.Entity;
14+
using VRageMath;
615

716
namespace EssentialsPlugin.Utility
817
{
9-
using System.Net;
10-
using System.Threading;
11-
using Sandbox.Definitions;
12-
using Sandbox.Game.Entities;
13-
using Sandbox.Game.Entities.Cube;
14-
using Sandbox.Game.World;
15-
using Settings;
16-
using SEModAPIInternal.API.Common;
17-
using VRage.Game;
18-
using VRage.Game.Entity;
19-
using VRage.Game.ModAPI;
20-
using VRageMath;
21-
2218
public static class PlayerBlockEnforcement
2319
{
2420
private static bool _init;
@@ -85,7 +81,7 @@ private static void InitGrid( MyCubeGrid grid )
8581
if (fatBlock.OwnerId == 0)
8682
{
8783
if (fatBlock.CubeGrid.BigOwners.Count > 0 && PluginSettings.Instance.PlayerBlockEnforcementChangeOwner)
88-
Wrapper.GameAction(() => fatBlock.ChangeBlockOwnerRequest(fatBlock.CubeGrid.BigOwners.First(), MyOwnershipShareModeEnum.Faction));
84+
MyAPIGateway.Utilities.InvokeOnGameThread(() => fatBlock.ChangeBlockOwnerRequest(fatBlock.CubeGrid.BigOwners.First(), MyOwnershipShareModeEnum.Faction));
8985
else if (PluginSettings.Instance.PlayerBlockEnforcementChangeOwner)
9086
ChangeOwnershipToNearestPlayer(fatBlock);
9187
}
@@ -111,7 +107,7 @@ private static void InitGrid( MyCubeGrid grid )
111107
if (fatBlock.OwnerId == 0)
112108
{
113109
if (fatBlock.CubeGrid.BigOwners.Count > 0 && PluginSettings.Instance.PlayerBlockEnforcementChangeOwner)
114-
Wrapper.GameAction(() => fatBlock.ChangeBlockOwnerRequest(fatBlock.CubeGrid.BigOwners.First(), MyOwnershipShareModeEnum.Faction));
110+
MyAPIGateway.Utilities.InvokeOnGameThread(() => fatBlock.ChangeBlockOwnerRequest(fatBlock.CubeGrid.BigOwners.First(), MyOwnershipShareModeEnum.Faction));
115111
else if (PluginSettings.Instance.PlayerBlockEnforcementChangeOwner)
116112
ChangeOwnershipToNearestPlayer(fatBlock);
117113
}
@@ -147,7 +143,7 @@ private static void ChangeOwnershipToNearestPlayer( MyTerminalBlock block )
147143

148144
if ( nearest == null )
149145
return;
150-
block.ChangeBlockOwnerRequest( nearest.Identity.IdentityId, MyOwnershipShareModeEnum.Faction );
146+
MyAPIGateway.Utilities.InvokeOnGameThread(()=>block.ChangeBlockOwnerRequest( nearest.Identity.IdentityId, MyOwnershipShareModeEnum.Faction ));
151147
} );
152148
}
153149

@@ -443,12 +439,12 @@ private static void FatBlock_OwnershipChanged(MyTerminalBlock block)
443439
lock ( BlockOwners )
444440
{
445441
if ( BlockOwners.ContainsKey( block ) )
446-
Wrapper.GameAction( () => block.ChangeBlockOwnerRequest( BlockOwners[block], MyOwnershipShareModeEnum.Faction ) );
442+
MyAPIGateway.Utilities.InvokeOnGameThread( () => block.ChangeBlockOwnerRequest( BlockOwners[block], MyOwnershipShareModeEnum.Faction ) );
447443
else if ( PluginSettings.Instance.PlayerBlockEnforcementChangeOwner )
448444
{
449445
ChangeOwnershipToNearestPlayer( block );
450446
if ( block.OwnerId == 0 && block.CubeGrid.BigOwners.Count > 0 )
451-
block.ChangeBlockOwnerRequest( block.CubeGrid.BigOwners[0], MyOwnershipShareModeEnum.Faction );
447+
MyAPIGateway.Utilities.InvokeOnGameThread(()=>block.ChangeBlockOwnerRequest( block.CubeGrid.BigOwners[0], MyOwnershipShareModeEnum.Faction ));
452448

453449
if ( block.OwnerId != 0 )
454450
BlockOwners[block] = block.OwnerId;

0 commit comments

Comments
 (0)