Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command to delete grids that fail an IsWorking check for a specified block. #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Essentials/Commands/CleanupModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ public void Delete()
Log.Info($"Cleanup deleted {count} grids matching conditions {string.Join(", ", Context.Args)}");
}

[Command("delete offtype", "Deletes grids with specified blocks toggled off.")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a separate command tho?

I personally prefer it to keep it as !cleanup list or !cleanup delete

Instead you could have added a new condition you can see how for example HasType is implemented in line 385

As it is implemented now I have not the ability to just "list" which grids would be affected. And since I cannot see what would be affected I cannot check if my filter is correct or I for example need to exclude something with other conditions.

public void OffType(string type)
{
var count = 0;
foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>().Where(x => x.Projector == null))
{
foreach (var block in grid.GetFatBlocks().OfType<IMyFunctionalBlock>())
{
var blockType = block.BlockDefinition.TypeId.ToString().Substring(16);
if (block != null && string.Compare(type, blockType, StringComparison.InvariantCultureIgnoreCase) == 0)
{
if (block.IsWorking == false)
{
Log.Info($"Deleting grid: {grid.EntityId}: {grid.DisplayName}");
EjectPilots(grid);
grid.Close();
count++;
}
}
}
}
Context.Respond($"grid delete {count} with off blocks of type {type}.");
}

[Command("delete floatingobjects", "deletes floating objects")]
public void FlObjDelete()
{
Expand Down Expand Up @@ -331,7 +355,7 @@ public bool OwnedBy(MyCubeGrid grid, string str)
return grid.BigOwners.Count > 0 &&
MySession.Static.Factions.IsNpcFaction(grid.BigOwners.FirstOrDefault());
}


if (string.Compare(str, "pirates", StringComparison.InvariantCultureIgnoreCase) == 0)
{
Expand All @@ -356,7 +380,7 @@ public bool OwnedBy(MyCubeGrid grid, string str)

return grid.BigOwners.Contains(identityId);
}


[Condition("hastype", "notype", "Finds grids containing blocks of the given type.")]
public bool BlockType(MyCubeGrid grid, string str)
Expand Down