diff --git a/EssentialsPlugin/AssemblyFileVersion.cs b/EssentialsPlugin/AssemblyFileVersion.cs index a03847d..70f9faf 100644 --- a/EssentialsPlugin/AssemblyFileVersion.cs +++ b/EssentialsPlugin/AssemblyFileVersion.cs @@ -1,4 +1,4 @@ -//4 +//5 // // 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.4")] -[assembly: AssemblyVersion("1.13.7.4")] +[assembly: AssemblyFileVersion("1.13.7.5")] +[assembly: AssemblyVersion("1.13.7.5")] diff --git a/EssentialsPlugin/EntityManagers/EntityManagement.cs b/EssentialsPlugin/EntityManagers/EntityManagement.cs index 370f7a5..2604c7b 100644 --- a/EssentialsPlugin/EntityManagers/EntityManagement.cs +++ b/EssentialsPlugin/EntityManagers/EntityManagement.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; + using System.Runtime.Remoting; using System.Threading; using EssentialsPlugin.ProcessHandlers; using EssentialsPlugin.Utility; @@ -42,8 +43,6 @@ public static void CheckAndConcealEntities( ) try { List players; - HashSet entities; - HashSet entitiesFiltered = new HashSet( ); try { @@ -54,39 +53,18 @@ public static void CheckAndConcealEntities( ) Essentials.Log.Error( ex, "Error getting players list. Check and Conceal failed: {0}"); return; } - - try - { - entities = MyEntities.GetEntities(); - } - catch ( Exception ex ) - { - Essentials.Log.Error( ex, "Error getting entity list, skipping check" ); - return; - } - - foreach (MyEntity entity in entities ) - { - if ( !( entity is MyCubeGrid ) ) - continue; - - if ( UnregisteredEntities.Contains( entity ) ) - continue; - - entitiesFiltered.Add( entity ); - } - var groups = GridGroup.GetGroups( entitiesFiltered, GridLinkTypeEnum.Physical ); - - foreach ( GridGroup group in groups ) + foreach ( GridGroup group in GridGroup.GetAllGroups( GridLinkTypeEnum.Logical ) ) { + //we're using grid groups so that multi-part pirate ships don't lose pieces if(PluginSettings.Instance.DynamicConcealPirates) { if ( group.Parent.GetOwner() == "Space Pirates" ) { if (PluginSettings.Instance.DynamicShowMessages) Essentials.Log.Info( $"Not concealing pirate owned grid {group.Parent.EntityId} -> {group.Parent.DisplayName}."); - continue;} + continue; + } } foreach ( MyCubeGrid grid in group.Grids ) { @@ -98,21 +76,21 @@ public static void CheckAndConcealEntities( ) if ( grid.IsStatic && !PluginSettings.Instance.ConcealIncludeStations ) continue; if ( !PluginSettings.Instance.ConcealIncludeLargeGrids ) - continue; - } + continue; + } if ( players.Any( x => Vector3D.Distance( x.GetPosition(), grid.PositionComp.GetPosition() ) < PluginSettings.Instance.DynamicConcealDistance ) ) - continue; + continue; - if ( ProcessDockingZone.ZoneCache.Any( x => Vector3D.Distance( x.GetPosition(), grid.PositionComp.GetPosition() ) < 100d ) ) - continue; + if ( ProcessDockingZone.ZoneCache.Any( x => Vector3D.Distance( x.GetPosition(), grid.PositionComp.GetPosition() ) < 100 ) ) + continue; if ( CheckConcealBlockRules( grid ) ) continue; ConcealEntity( grid ); } - } + } } catch ( Exception ex ) { @@ -137,12 +115,13 @@ private static bool CheckConcealBlockRules( MyCubeGrid grid ) var beacon = cubeBlock as IMyBeacon; if ( beacon != null) { - beaconCount++; + //beaconCount++; // Keep this return here, as 4 beacons always means true - if ( beaconCount >= 4 ) - { - return true; - } + //DON'T TELL ME WHAT TO DO + //if ( beaconCount >= 4 ) + //{ + // return true; + //} if ( !beacon.Enabled ) continue; @@ -185,21 +164,18 @@ private static bool CheckConcealBlockRules( MyCubeGrid grid ) return true; } } - - //TODO - /* + var cryo = cubeBlock as MyCryoChamber; if ( cryo?.Pilot != null ) return true; - */ var production = cubeBlock as IMyProductionBlock; - if ( production != null ) + if ( production != null && PluginSettings.Instance.DynamicConcealProduction ) { if ( !production.Enabled ) continue; - if ( production.IsProducing ) + if ( !production.IsQueueEmpty ) return true; } @@ -459,7 +435,7 @@ private static bool CheckRevealBlockRules( MyCubeGrid grid, out string reason ) if ( medical.HasPlayerAccess( playerId ) ) { - reason = $"Grid has medbay and player is factionshare - playerid: {playerId}"; + reason = $"Grid has medbay and player has access - playerid: {playerId}"; return true; } } @@ -473,50 +449,26 @@ private static bool CheckRevealBlockRules( MyCubeGrid grid, out string reason ) } var cryo = cubeBlock as MyCryoChamber; - if ( cryo != null ) - { - if ( cryo.Pilot == null ) - continue; - - if ( !cryo.IsFunctional ) - continue; - - if ( PluginSettings.Instance.DynamicConcealIncludeMedBays ) - { - lock ( Online ) - { - foreach ( ulong connectedPlayer in Online ) - { - long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( connectedPlayer ); + if ( cryo != null ) + { + if ( cryo.Pilot == null ) + continue; - if (cryo.Pilot.GetPlayerIdentityId() == playerId ) - { - reason = $"Grid has cryopod and player is inside - playerid: {playerId}"; - return true; - } + if ( !cryo.IsFunctional ) + continue; - if ( cryo.HasPlayerAccess( playerId ) ) - { - reason = $"Grid has cryopod and player can use - playerid: {playerId}"; - return true; - } - } - } - } - else - { - reason = "Grid has cryopod and conceal can not include cryopods"; - return true; - } - } + reason = $"Grid has cryopod and player is inside - player: {cryo.Pilot.DisplayName}"; + return true; + } + //don't check conceal settings for production blocks, we always want them to reveal var production = cubeBlock as MyProductionBlock; if ( production != null ) { if ( !production.Enabled ) continue; - if ( production.Queue.Any() ) + if ( !production.IsQueueEmpty ) { reason = "Grid has production facility that has a queue"; return true; @@ -657,6 +609,9 @@ private static void UnregisterHierarchy( MyEntity entity ) if ( entity.Hierarchy == null ) return; + if ( UnregisteredEntities.Contains( entity ) ) + return; + foreach ( var child in entity.Hierarchy.Children ) { MyEntity childEntity = (MyEntity)child.Container.Entity; diff --git a/EssentialsPlugin/Essentials.cs b/EssentialsPlugin/Essentials.cs index 2e2c0cd..015373c 100644 --- a/EssentialsPlugin/Essentials.cs +++ b/EssentialsPlugin/Essentials.cs @@ -712,7 +712,7 @@ public string[ ] DynamicConcealIgnoreSubTypeList [Category( "Dynamic Entity Management" )] [DisplayName( "Include MedBays" )] - [Description( "The list of subtype blocks that will make the entity manager ignore a grid. If a grid contains any of these block subtypes, it will automatically not include it when deciding whether to conceal the grid or not" )] + [Description( "If any online player has access to a working medbay on a grid, it will be ignored." )] [Browsable( true )] [ReadOnly( false )] public bool DynamicConcealIncludeMedBays @@ -721,47 +721,18 @@ public bool DynamicConcealIncludeMedBays set { PluginSettings.Instance.DynamicConcealIncludeMedBays = value; } } - /* Experiments not working yet */ - /* - [Category("Dynamic Entity Management")] - [Description("")] - [Browsable(true)] - [ReadOnly(false)] - public bool DynamicConcealServerOnly - { - get { return PluginSettings.Instance.DynamicConcealServerOnly; } - set - { - PluginSettings.Instance.DynamicConcealServerOnly = value; - } - } - [Category("Dynamic Entity Management")] - [Description("")] - [Browsable(true)] - [ReadOnly(false)] - public bool DynamicClientConcealEnabled - { - get { return PluginSettings.Instance.DynamicClientConcealEnabled; } - set - { - PluginSettings.Instance.DynamicClientConcealEnabled = value; - } - } - - [Category("Dynamic Entity Management")] - [Description("")] - [Browsable(true)] - [ReadOnly(false)] - public float DynamicClientConcealDistance - { - get { return PluginSettings.Instance.DynamicClientConcealDistance; } - set - { - PluginSettings.Instance.DynamicClientConcealDistance = value; - } - } - /**/ + [Category("Dynamic Entity Management")] + [DisplayName("Include Active Production")] + [Description("Ships with active production blocks will be concealed.")] + [Browsable(true)] + [ReadOnly(false)] + public bool DynamicConcealProduction + { + get { return PluginSettings.Instance.DynamicConcealIncludeMedBays; } + set { PluginSettings.Instance.DynamicConcealIncludeMedBays = value; } + } + [Category( "Dynamic Entity Management" )] [DisplayName( "Log Actions" )] [Description( "Enable / Disable console messages that display whether an entity is concealed or revealed. Should be off if you don't care about seeing how many entities get revealed/concealed." )] diff --git a/EssentialsPlugin/ProcessHandlers/ProcessGreeting.cs b/EssentialsPlugin/ProcessHandlers/ProcessGreeting.cs index 145ddc2..ab4bb71 100644 --- a/EssentialsPlugin/ProcessHandlers/ProcessGreeting.cs +++ b/EssentialsPlugin/ProcessHandlers/ProcessGreeting.cs @@ -51,98 +51,101 @@ public override int GetUpdateResolution() return 1001; } - public override void Handle() - { - if (PluginSettings.Instance.GreetingMessage != "") - { - if (MyAPIGateway.Players == null) - return; - - try - { - List players = new List(); - bool result = false; - - //Wrapper.GameAction(() => - //{ - try - { - MyAPIGateway.Players.GetPlayers(players); - result = true; - } - catch (Exception ex) - { - Essentials.Log.Error( ex ); - } - //}); - - if(!result) - return; - - lock (m_greetingList) - { - for (int r = m_greetingList.Count - 1; r >= 0; r--) - { - GreetingItem item = m_greetingList[r]; - if(DateTime.Now - item.Start > item.Timeout) - { - m_greetingList.RemoveAt(r); - continue; - } - IMyPlayer player = players.FirstOrDefault(x => x.SteamUserId == item.SteamId && x.Controller != null && x.Controller.ControlledEntity != null); - if (player != null) - { - m_greetingList.RemoveAt(r); - - string message; - - if (item.IsNewUser) - message = PluginSettings.Instance.GreetingNewUserMessage.Replace("%name%", player.DisplayName); - else - message = PluginSettings.Instance.GreetingMessage.Replace("%name%", player.DisplayName); - - message = message.Replace("%name%", player.DisplayName); - message = message.Replace("%players%", players.Count.ToString()); - message = message.Replace("%maxplayers%", MyAPIGateway.Session.SessionSettings.MaxPlayers.ToString()); - - string finalMessage = message; - - if(PluginSettings.Instance.GreetingPublic) - Communication.SendPublicInformation(finalMessage); - else - Communication.SendPrivateInformation(item.SteamId, finalMessage); - - if (item.IsNewUser) - { - if (PluginSettings.Instance.GreetingNewUserItem.Enabled) - { - SettingsGreetingDialogItem gItem = PluginSettings.Instance.GreetingNewUserItem; - Communication.DisplayDialog(item.SteamId, gItem.Title.Replace("%name%", player.DisplayName), gItem.Header.Replace("%name%", player.DisplayName), gItem.Contents.Replace("%name%", player.DisplayName).Replace("\r", "").Replace("\n", "|").Replace("\"", "'"), gItem.ButtonText); - } - } - else - { - if (PluginSettings.Instance.GreetingItem.Enabled) - { - SettingsGreetingDialogItem gItem = PluginSettings.Instance.GreetingItem; - Communication.DisplayDialog(item.SteamId, gItem.Title.Replace("%name%", player.DisplayName), gItem.Header.Replace("%name%", player.DisplayName), gItem.Contents.Replace("%name%", player.DisplayName).Replace("\r", "").Replace("\n", "|").Replace("\"", "'"), gItem.ButtonText); - } - } - - } - } - } - } - catch (Exception ex) - { - Essentials.Log.Error( ex ); - } - } - - base.Handle(); - } - - public override void OnPlayerJoined(ulong remoteUserId) + public override void Handle() + { + if ( !PluginSettings.Instance.GreetingEnabled ) + return; + + if ( MyAPIGateway.Players == null ) + return; + + try + { + List players = new List(); + bool result = false; + + //Wrapper.GameAction(() => + //{ + try + { + MyAPIGateway.Players.GetPlayers( players ); + result = true; + } + catch ( Exception ex ) + { + Essentials.Log.Error( ex ); + } + //}); + + if ( !result ) + return; + + lock ( m_greetingList ) + { + for ( int r = m_greetingList.Count - 1; r >= 0; r-- ) + { + GreetingItem item = m_greetingList[r]; + if ( DateTime.Now - item.Start > item.Timeout ) + { + m_greetingList.RemoveAt( r ); + continue; + } + IMyPlayer player = players.FirstOrDefault( x => x.SteamUserId == item.SteamId && x.Controller != null && x.Controller.ControlledEntity != null ); + if ( player != null ) + { + m_greetingList.RemoveAt( r ); + + if ( PluginSettings.Instance.GreetingMessage != "" ) + { + string message; + + if ( item.IsNewUser ) + message = PluginSettings.Instance.GreetingNewUserMessage.Replace( "%name%", player.DisplayName ); + else + message = PluginSettings.Instance.GreetingMessage.Replace( "%name%", player.DisplayName ); + + message = message.Replace( "%name%", player.DisplayName ); + message = message.Replace( "%players%", players.Count.ToString() ); + message = message.Replace( "%maxplayers%", MyAPIGateway.Session.SessionSettings.MaxPlayers.ToString() ); + + string finalMessage = message; + + if ( PluginSettings.Instance.GreetingPublic ) + Communication.SendPublicInformation( finalMessage ); + else + Communication.SendPrivateInformation( item.SteamId, finalMessage ); + } + + if ( item.IsNewUser ) + { + if ( PluginSettings.Instance.GreetingNewUserItem.Enabled ) + { + SettingsGreetingDialogItem gItem = PluginSettings.Instance.GreetingNewUserItem; + Communication.DisplayDialog( item.SteamId, gItem.Title.Replace( "%name%", player.DisplayName ), gItem.Header.Replace( "%name%", player.DisplayName ), gItem.Contents.Replace( "%name%", player.DisplayName ).Replace( "\r", "" ).Replace( "\n", "|" ).Replace( "\"", "'" ), gItem.ButtonText ); + } + } + else + { + if ( PluginSettings.Instance.GreetingItem.Enabled ) + { + SettingsGreetingDialogItem gItem = PluginSettings.Instance.GreetingItem; + Communication.DisplayDialog( item.SteamId, gItem.Title.Replace( "%name%", player.DisplayName ), gItem.Header.Replace( "%name%", player.DisplayName ), gItem.Contents.Replace( "%name%", player.DisplayName ).Replace( "\r", "" ).Replace( "\n", "|" ).Replace( "\"", "'" ), gItem.ButtonText ); + } + } + + } + } + } + } + catch ( Exception ex ) + { + Essentials.Log.Error( ex ); + } + + base.Handle(); + } + + public override void OnPlayerJoined(ulong remoteUserId) { GreetingItem item = new GreetingItem(); item.SteamId = remoteUserId; diff --git a/EssentialsPlugin/Settings/PluginSettings.cs b/EssentialsPlugin/Settings/PluginSettings.cs index a81a90b..3e0ba45 100644 --- a/EssentialsPlugin/Settings/PluginSettings.cs +++ b/EssentialsPlugin/Settings/PluginSettings.cs @@ -87,6 +87,7 @@ public class PluginSettings private bool _dynamicShowMessages; private bool _dynamicConcealPirates; private bool _dynamicConcealPhysics; + private bool _dynamicConcealProduction; private bool _dynamicTurretManagementEnabled; private int _dynamicTurretTargetDistance; private bool _dynamicTurretAllowExemption; @@ -633,6 +634,16 @@ public bool DynamicConcealPhysics } } + public bool DynamicConcealProduction + { + get { return _dynamicConcealProduction; } + set + { + _dynamicConcealProduction = value; + Save(); + } + } + public float DynamicConcealDistance { get { return _dynamicConcealDistance; } @@ -1058,6 +1069,7 @@ public PluginSettings() _dynamicConcealDistance = 8000; _dynamicConcealPirates = false; _dynamicConcealPhysics = false; + _dynamicConcealProduction = true; _dynamicShowMessages = false; _dynamicTurretTargetDistance = 2000; _dynamicTurretManagementEnabled = false; diff --git a/EssentialsPlugin/Utility/PlayerBlockEnforcement.cs b/EssentialsPlugin/Utility/PlayerBlockEnforcement.cs index 954499f..d8ff22f 100644 --- a/EssentialsPlugin/Utility/PlayerBlockEnforcement.cs +++ b/EssentialsPlugin/Utility/PlayerBlockEnforcement.cs @@ -7,6 +7,7 @@ namespace EssentialsPlugin.Utility { using System.Net; + using System.Threading; using Sandbox.Definitions; using Sandbox.Game.Entities; using Sandbox.Game.Entities.Cube; @@ -298,7 +299,6 @@ private static void ProcessEnforcement( MyCubeBlock newBlock = null) if ( disabledPlayers.ContainsKey( steamId ) ) { - Essentials.Log.Info("3"); if ( disabledPlayers[steamId].Contains( blockSearch ) ) { disabledPlayers[steamId].Remove( blockSearch ); @@ -416,6 +416,14 @@ private static void Grid_OnBlockAdded(MySlimBlock obj) private static void FatBlock_OwnershipChanged(MyTerminalBlock block) { + if ( block?.CubeGrid?.Physics == null || block.Closed ) + { + //idfk + Thread.Sleep( 500 ); + if ( block?.CubeGrid?.Physics == null || block.Closed ) + return; + } + Task.Run( () => { if ( block.OwnerId != 0 )