diff --git a/EssentialsPlugin/AssemblyFileVersion.cs b/EssentialsPlugin/AssemblyFileVersion.cs index 4d37f43..9096b2d 100644 --- a/EssentialsPlugin/AssemblyFileVersion.cs +++ b/EssentialsPlugin/AssemblyFileVersion.cs @@ -1,4 +1,4 @@ -//21 +//26 // // This code was generated by a tool. Any changes made manually will be lost // the next time this code is regenerated. @@ -6,5 +6,5 @@ using System.Reflection; -[assembly: AssemblyFileVersion("1.13.7.21")] -[assembly: AssemblyVersion("1.13.7.21")] +[assembly: AssemblyFileVersion("1.13.7.26")] +[assembly: AssemblyVersion("1.13.7.26")] diff --git a/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminConceal.cs b/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminConceal.cs index 73c98a4..9d2426d 100644 --- a/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminConceal.cs +++ b/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminConceal.cs @@ -70,17 +70,17 @@ public override bool HandleCommand(ulong userId, string[] words) if (showConcealed) { - HashSet entities = new HashSet(); + HashSet entities = new HashSet(); Wrapper.GameAction(() => { - MyAPIGateway.Entities.GetEntities(entities); + entities=MyEntities.GetEntities(); }); Communication.SendPrivateInformation(userId, "==== Concealed Entities ==="); int count = 0; - foreach (MyEntity entity in EntityManagement.UnregisteredEntities) + foreach (MyEntity entity in entities) { - if (!(entity is MyCubeGrid)) + if (!EntityManagement.RemovedGrids.Contains( entity.EntityId )) continue; MyCubeGrid grid = (MyCubeGrid)entity; diff --git a/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminReveal.cs b/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminReveal.cs index 03cd103..bdef740 100644 --- a/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminReveal.cs +++ b/EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminReveal.cs @@ -1,22 +1,8 @@ namespace EssentialsPlugin.ChatHandlers.AdminConceal { - using System.Collections.Generic; using System.Linq; using EntityManagers; using EssentialsPlugin.Utility; - using Sandbox.Common.ObjectBuilders; - using Sandbox.Engine.Multiplayer; - using Sandbox.Game.Entities; - using Sandbox.Game.Replication; - using Sandbox.ModAPI; - using SEModAPIInternal.API.Common; - using SEModAPIInternal.API.Entity; - using VRage.Game; - using VRage.Game.Entity; - using VRage.Game.ModAPI; - using VRage.ModAPI; - using VRage.ObjectBuilders; - using VRageMath; public class HandleAdminReveal : ChatHandlerBase { @@ -32,14 +18,15 @@ public override string GetCommandText() public override Communication.ServerDialogItem GetHelpDialog( ) { - Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem( ); - DialogItem.title = "Help"; - DialogItem.header = "Admin Reveal"; - DialogItem.content = - " This command allows you to reveal concealed grids.|" + - "Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" + - "This command will run when concealment is disabled, and respects the update time setting."; - DialogItem.buttonText = "close"; + Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem + { + title = "Help", + header = "Admin Reveal", + content = " This command allows you to reveal concealed grids.|" + + "Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" + + "This command will run when concealment is disabled, and respects the update time setting.", + buttonText = "close" + }; return DialogItem; } @@ -63,7 +50,7 @@ public override bool HandleCommand(ulong userId, string[] words) else { Communication.SendPrivateInformation( userId, - $"Command would reveal {EntityManagement.UnregisteredEntities.Count} grids. Type /admin reveal force to reveal them." ); + $"Command would reveal {EntityManagement.RemovedGrids.Count} grids. Type /admin reveal force to reveal them." ); } return true; } diff --git a/EssentialsPlugin/EntityManagers/EntityManagement.cs b/EssentialsPlugin/EntityManagers/EntityManagement.cs index 01da7ea..6e80138 100644 --- a/EssentialsPlugin/EntityManagers/EntityManagement.cs +++ b/EssentialsPlugin/EntityManagers/EntityManagement.cs @@ -3,35 +3,35 @@ using System; using System.Collections.Generic; using System.Linq; - using System.Runtime.Remoting; using System.Threading; using EssentialsPlugin.ProcessHandlers; using EssentialsPlugin.Utility; using Sandbox.ModAPI; - using Sandbox.ModAPI.Ingame; using SEModAPIInternal.API.Common; using VRage.ModAPI; using VRage.ObjectBuilders; using VRageMath; - using IMyProductionBlock = Sandbox.ModAPI.Ingame.IMyProductionBlock; using Sandbox.Game.Entities; using Sandbox.Game.World; using Sandbox.Game.Entities.Blocks; using Sandbox.Game.Entities.Cube; + using Sandbox.ModAPI.Ingame; + using SpaceEngineers.Game.ModAPI; using SpaceEngineers.Game.ModAPI.Ingame; using VRage.Game; using VRage.Game.Entity; using VRage.Game.ModAPI; - + using IMyProductionBlock = Sandbox.ModAPI.IMyProductionBlock; + public class EntityManagement { private static volatile bool _checkReveal; private static volatile bool _checkConceal; private static bool _oldInit; - private static readonly List RemovedGrids = new List( ); + public static readonly HashSet RemovedGrids = new HashSet( ); private static readonly List Online = new List( ); - public static HashSet UnregisteredEntities = new HashSet(); + //public static HashSet UnregisteredEntities = new HashSet(); public static void CheckAndConcealEntities( ) @@ -71,7 +71,10 @@ public static void CheckAndConcealEntities( ) if ( grid.Physics == null ) //projection continue; - if ( UnregisteredEntities.Contains( grid ) ) + //if ( UnregisteredEntities.Contains( (MyEntity)grid ) ) + // continue; + + if ( RemovedGrids.Contains( grid.EntityId ) ) continue; if ( grid.GridSizeEnum != MyCubeSize.Small ) @@ -222,8 +225,8 @@ private static void ConcealEntity( MyEntity entity ) pos = 4; //else //{ - UnregisteredEntities.Add( entity ); - Wrapper.GameAction( () => UnregisterHierarchy( entity ) ); + //UnregisteredEntities.Add( entity ); + Wrapper.GameAction( () => UnregisterHierarchy( entity.GetTopMostParent( ) ) ); if ( PluginSettings.Instance.DynamicShowMessages ) Essentials.Log.Info( $"Concealed - Id: {entity.EntityId} -> Display: {entity.DisplayName} OwnerId: {ownerId} OwnerName: {ownerName}" ); @@ -311,9 +314,11 @@ public static void CheckAndRevealEntities( ) _checkReveal = true; try { - foreach ( MyEntity entity in UnregisteredEntities) + HashSet entities = new HashSet(); + MyAPIGateway.Utilities.InvokeOnGameThread( () => entities=MyEntities.GetEntities()); + foreach ( MyEntity entity in entities.ToArray()) { - if ( entity.Closed || entity.MarkedForClose ) + if ( entity.Closed || entity.MarkedForClose || !RemovedGrids.Contains( entity.EntityId )) continue; if ( !( entity is MyCubeGrid ) ) @@ -345,7 +350,7 @@ public static void CheckAndRevealEntities( ) if ( found ) { - Wrapper.GameAction( () => ReregisterHierarchy( entity ) ); + Wrapper.GameAction( () => ReregisterHierarchy( entity.GetTopMostParent( ) ) ); if (PluginSettings.Instance.DynamicShowMessages) Essentials.Log.Info("Revealed - Id: {0} -> Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", @@ -563,10 +568,6 @@ public static void RevealEntityObsolete( KeyValuePair item ) static public void RevealAll( ) { - while ( _checkReveal ) - { - } - _checkReveal = true; CheckAndRevealEntitiesObsolete(); @@ -574,13 +575,13 @@ static public void RevealAll( ) HashSet entities = new HashSet(); Wrapper.GameAction( ()=>entities = MyEntities.GetEntities() ); - foreach ( var entity in entities ) + foreach ( var entity in entities.ToArray() ) { var grid = entity as MyCubeGrid; if ( grid == null ) continue; - if (PluginSettings.Instance.DynamicShowMessages && UnregisteredEntities.Contains( entity )) + if (PluginSettings.Instance.DynamicShowMessages && RemovedGrids.Contains( entity.EntityId )) Essentials.Log.Info("Revealed - Id: {0} -> Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), @@ -588,10 +589,10 @@ static public void RevealAll( ) PlayerMap.Instance.GetPlayerNameFromPlayerId(((MyCubeGrid)entity).BigOwners.FirstOrDefault()), "Force reveal"); - Wrapper.GameAction( () => ReregisterHierarchy( entity ) ); + Wrapper.GameAction( () => ReregisterHierarchy( entity.GetTopMostParent( ) ) ); } - UnregisteredEntities.Clear(); + RemovedGrids.Clear(); _checkReveal = false; } @@ -617,55 +618,69 @@ public static void SetOnline( ulong steamId, bool online ) } } - private static void UnregisterHierarchy( MyEntity entity ) + private static void UnregisterHierarchy( MyEntity entity, bool top = true ) { if ( entity.Hierarchy == null ) return; - //if ( UnregisteredEntities.Contains( entity ) ) - // return; + if (RemovedGrids.Contains(entity.EntityId)) + return; foreach ( var child in entity.Hierarchy.Children ) { MyEntity childEntity = (MyEntity)child.Container.Entity; - UnregisterHierarchy( childEntity ); + UnregisterHierarchy( childEntity, false ); MyEntities.UnregisterForUpdate( childEntity ); - childEntity.RemoveFromGamePruningStructure(); + //childEntity.RemoveFromGamePruningStructure(); //child.Container.Entity.InScene = false; - if ( !PluginSettings.Instance.DynamicConcealPhysics ) - continue; - - if (child.Container.Entity.Physics != null) - child.Container.Entity.Physics.Enabled = false; } - UnregisteredEntities.Add( entity ); + if ( !top ) + return; + + RemovedGrids.Add( entity.EntityId ); + + MyEntities.UnregisterForUpdate( entity ); + entity.RemoveFromGamePruningStructure(); + if ( !PluginSettings.Instance.DynamicConcealPhysics ) + return; + + if ( entity.Physics != null ) + entity.Physics.Enabled = false; + } - private static void ReregisterHierarchy( MyEntity entity ) + private static void ReregisterHierarchy( MyEntity entity, bool top = true ) { if ( entity.Hierarchy == null ) return; - - foreach (var child in entity.Hierarchy.Children) + + RemovedGrids.Remove( entity.EntityId ); + + foreach ( var child in entity.Hierarchy.Children ) { MyEntity childEntity = (MyEntity)child.Container.Entity; - ReregisterHierarchy(childEntity); - MyEntities.RegisterForUpdate(childEntity); - childEntity.AddToGamePruningStructure(); + ReregisterHierarchy( childEntity, false ); + MyEntities.RegisterForUpdate( childEntity ); + //childEntity.AddToGamePruningStructure(); //child.Container.Entity.InScene = true; - if (!PluginSettings.Instance.DynamicConcealPhysics) - continue; - - if (child.Container.Entity.Physics != null) - child.Container.Entity.Physics.Enabled = true; } + if ( !top ) + return; + + MyEntities.RegisterForUpdate( entity ); + entity.AddToGamePruningStructure(); + + if ( !PluginSettings.Instance.DynamicConcealPhysics ) + return; - UnregisteredEntities.Remove( entity ); + if ( entity.Physics != null ) + entity.Physics.Enabled = true; + //UnregisteredEntities.Remove( entity ); } } } \ No newline at end of file