From 3c3f384178bbdcfa6f9b912e526bc3ac0c2039c9 Mon Sep 17 00:00:00 2001 From: Spcemarine Date: Mon, 29 Sep 2014 22:26:24 +0200 Subject: [PATCH 1/2] Fix for issue #126 Grids attached to grids with a beacon should no longer be deleted while performing "/delete all nobeacon" --- SEModAPIExtensions/API/ChatManager.cs | 154 ++++++++++++-------------- 1 file changed, 70 insertions(+), 84 deletions(-) diff --git a/SEModAPIExtensions/API/ChatManager.cs b/SEModAPIExtensions/API/ChatManager.cs index ec51d101..b4eab427 100644 --- a/SEModAPIExtensions/API/ChatManager.cs +++ b/SEModAPIExtensions/API/ChatManager.cs @@ -613,90 +613,76 @@ protected void Command_Delete(ChatEvent chatEvent) //All entities #region "All Entities" if (paramCount > 1 && commandParts[1].ToLower().Equals("all")) - { - //All cube grids that have no beacon or only a beacon with no name - if (commandParts[2].ToLower().Equals("nobeacon")) - { - List entities = SectorObjectManager.Instance.GetTypedInternalData(); - List entitiesToDispose = new List(); - foreach (CubeGridEntity entity in entities) - { - while (entity.CubeBlocks.Count == 0) - { - Thread.Sleep(20); - } - List blocks = entity.CubeBlocks; - if (blocks.Count > 0) - { - bool foundBeacon = false; - foreach (CubeBlockEntity cubeBlock in blocks) - { - if (cubeBlock is BeaconEntity) - { - foundBeacon = true; - break; - } - } - if (!foundBeacon) - { - entitiesToDispose.Add(entity); - } - } - } - - foreach (CubeGridEntity entity in entitiesToDispose) - { - bool isLinkedShip = false; - List blocks = entity.CubeBlocks; - foreach (CubeBlockEntity cubeBlock in blocks) - { - if (cubeBlock is MergeBlockEntity) - { - MergeBlockEntity block = (MergeBlockEntity)cubeBlock; - if (block.IsAttached) - { - if (!entitiesToDispose.Contains(block.AttachedCubeGrid)) - { - isLinkedShip = true; - break; - } - } - } - if (cubeBlock is PistonEntity) - { - PistonEntity block = (PistonEntity)cubeBlock; - CubeBlockEntity topBlock = block.TopBlock; - if (topBlock != null) - { - if (!entitiesToDispose.Contains(topBlock.Parent)) - { - isLinkedShip = true; - break; - } - } - } - if (cubeBlock is RotorEntity) - { - RotorEntity block = (RotorEntity)cubeBlock; - CubeBlockEntity topBlock = block.TopBlock; - if (topBlock != null) - { - if (!entitiesToDispose.Contains(topBlock.Parent)) - { - isLinkedShip = true; - break; - } - } - } - } - if (isLinkedShip) - continue; - - entity.Dispose(); - } - - SendPrivateChatMessage(remoteUserId, entitiesToDispose.Count.ToString() + " cube grids have been removed"); - } + { + //All cube grids that have no beacon except for those attached to a grid with a beacon + if (commandParts[2].ToLower().Equals("nobeacon")) + { + while (SectorObjectManager.Instance.GetTypedInternalData().Count == 0) + { + Thread.Sleep(20); + } + + List entities = SectorObjectManager.Instance.GetTypedInternalData(); + List entitiesToDispose = SectorObjectManager.Instance.GetTypedInternalData(); + + if (entities.Count == 0) + { + ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "No grids found. Try again later."); + return; + } + + foreach (CubeGridEntity entity in entities) + { + while (entity.CubeBlocks.Count == 0) + { + Thread.Sleep(20); + } + + List blocks = entity.CubeBlocks; + + //scan each grid for beacons + foreach (CubeBlockEntity cubeBlock in blocks) + { + if (cubeBlock is BeaconEntity) + { + entitiesToDispose.Remove(entity); + + //if the grid has a beacon remove all grids from entitiesToDispose that are attached to it + foreach (CubeBlockEntity cubeBlock1 in blocks) + { + if (cubeBlock1 is PistonEntity) + { + PistonEntity piston = (PistonEntity)cubeBlock1; + CubeBlockEntity pistonTop = piston.TopBlock; + + if (pistonTop != null) + { + entitiesToDispose.Remove(pistonTop.Parent); + } + } + else if (cubeBlock1 is RotorEntity) + { + RotorEntity rotor = (RotorEntity)cubeBlock1; + CubeBlockEntity rotorTop = rotor.TopBlock; + if (rotorTop != null) + { + entitiesToDispose.Remove(rotorTop.Parent); + } + } + } + //we dont need to scan for further beacons + break; + } + } + } + + foreach (CubeGridEntity entity in entitiesToDispose) + { + entity.Dispose(); + } + + SendPrivateChatMessage(remoteUserId, entitiesToDispose.Count.ToString() + " cube grids have been removed."); + } //All cube grids that have no power else if (commandParts[2].ToLower().Equals("nopower")) { From 8bc33d367bda01e238ac461880ca7be28bd71875 Mon Sep 17 00:00:00 2001 From: Spcemarine Date: Sat, 4 Oct 2014 00:14:13 +0200 Subject: [PATCH 2/2] Changed whitespace to tab --- SEModAPIExtensions/API/ChatManager.cs | 120 +++++++++++++------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/SEModAPIExtensions/API/ChatManager.cs b/SEModAPIExtensions/API/ChatManager.cs index b4eab427..5f086616 100644 --- a/SEModAPIExtensions/API/ChatManager.cs +++ b/SEModAPIExtensions/API/ChatManager.cs @@ -614,75 +614,75 @@ protected void Command_Delete(ChatEvent chatEvent) #region "All Entities" if (paramCount > 1 && commandParts[1].ToLower().Equals("all")) { - //All cube grids that have no beacon except for those attached to a grid with a beacon - if (commandParts[2].ToLower().Equals("nobeacon")) - { - while (SectorObjectManager.Instance.GetTypedInternalData().Count == 0) - { - Thread.Sleep(20); - } + //All cube grids that have no beacon except for those attached to a grid with a beacon + if (commandParts[2].ToLower().Equals("nobeacon")) + { + while (SectorObjectManager.Instance.GetTypedInternalData().Count == 0) + { + Thread.Sleep(20); + } - List entities = SectorObjectManager.Instance.GetTypedInternalData(); - List entitiesToDispose = SectorObjectManager.Instance.GetTypedInternalData(); + List entities = SectorObjectManager.Instance.GetTypedInternalData(); + List entitiesToDispose = SectorObjectManager.Instance.GetTypedInternalData(); - if (entities.Count == 0) - { - ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "No grids found. Try again later."); - return; - } + if (entities.Count == 0) + { + ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "No grids found. Try again later."); + return; + } - foreach (CubeGridEntity entity in entities) - { - while (entity.CubeBlocks.Count == 0) - { - Thread.Sleep(20); - } + foreach (CubeGridEntity entity in entities) + { + while (entity.CubeBlocks.Count == 0) + { + Thread.Sleep(20); + } - List blocks = entity.CubeBlocks; + List blocks = entity.CubeBlocks; - //scan each grid for beacons - foreach (CubeBlockEntity cubeBlock in blocks) - { - if (cubeBlock is BeaconEntity) - { - entitiesToDispose.Remove(entity); + //scan each grid for beacons + foreach (CubeBlockEntity cubeBlock in blocks) + { + if (cubeBlock is BeaconEntity) + { + entitiesToDispose.Remove(entity); - //if the grid has a beacon remove all grids from entitiesToDispose that are attached to it - foreach (CubeBlockEntity cubeBlock1 in blocks) - { - if (cubeBlock1 is PistonEntity) - { - PistonEntity piston = (PistonEntity)cubeBlock1; - CubeBlockEntity pistonTop = piston.TopBlock; + //if the grid has a beacon remove all grids from entitiesToDispose that are attached to it + foreach (CubeBlockEntity cubeBlock1 in blocks) + { + if (cubeBlock1 is PistonEntity) + { + PistonEntity piston = (PistonEntity)cubeBlock1; + CubeBlockEntity pistonTop = piston.TopBlock; - if (pistonTop != null) - { - entitiesToDispose.Remove(pistonTop.Parent); - } - } - else if (cubeBlock1 is RotorEntity) - { - RotorEntity rotor = (RotorEntity)cubeBlock1; - CubeBlockEntity rotorTop = rotor.TopBlock; - if (rotorTop != null) - { - entitiesToDispose.Remove(rotorTop.Parent); - } - } - } - //we dont need to scan for further beacons - break; - } - } - } + if (pistonTop != null) + { + entitiesToDispose.Remove(pistonTop.Parent); + } + } + else if (cubeBlock1 is RotorEntity) + { + RotorEntity rotor = (RotorEntity)cubeBlock1; + CubeBlockEntity rotorTop = rotor.TopBlock; + if (rotorTop != null) + { + entitiesToDispose.Remove(rotorTop.Parent); + } + } + } + //we dont need to scan for further beacons + break; + } + } + } - foreach (CubeGridEntity entity in entitiesToDispose) - { - entity.Dispose(); - } + foreach (CubeGridEntity entity in entitiesToDispose) + { + entity.Dispose(); + } - SendPrivateChatMessage(remoteUserId, entitiesToDispose.Count.ToString() + " cube grids have been removed."); - } + SendPrivateChatMessage(remoteUserId, entitiesToDispose.Count.ToString() + " cube grids have been removed."); + } //All cube grids that have no power else if (commandParts[2].ToLower().Equals("nopower")) {