@@ -13,21 +13,52 @@ namespace Essentials
1313 [ Category ( "delete" ) ]
1414 public class DeleteModule : CommandModule
1515 {
16+ [ Command ( "grids notype" , "Delete all grids that don't have a block of the given type" ) ]
17+ [ Permission ( MyPromoteLevel . SpaceMaster ) ]
18+ public void DeleteByType ( string type , bool scanOnly = true )
19+ {
20+ var count = 0 ;
21+ foreach ( var grid in MyEntities . GetEntities ( ) . OfType < MyCubeGrid > ( ) )
22+ {
23+ if ( ShouldRemove ( grid ) )
24+ {
25+ if ( ! scanOnly )
26+ grid . Close ( ) ;
27+ count ++ ;
28+ }
29+ }
30+
31+ Context . Respond ( $ "{ ( scanOnly ? "Found" : "Deleted" ) } { count } grids missing the block subtype '{ type } '.") ;
32+
33+ bool ShouldRemove ( MyCubeGrid grid )
34+ {
35+ foreach ( var block in grid . GetBlocks ( ) )
36+ {
37+ var id = block . BlockDefinition . Id . TypeId . ToString ( ) ;
38+ if ( string . Compare ( id , type , StringComparison . InvariantCultureIgnoreCase ) == 0 )
39+ return false ;
40+ }
41+
42+ return true ;
43+ }
44+ }
45+
1646 [ Command ( "grids nosubtype" , "Delete all grids that don't have a block of the given subtype." ) ]
1747 [ Permission ( MyPromoteLevel . SpaceMaster ) ]
18- public void DeleteBySubtype ( string subtype )
48+ public void DeleteBySubtype ( string subtype , bool scanOnly = true )
1949 {
2050 var count = 0 ;
2151 foreach ( var grid in MyEntities . GetEntities ( ) . OfType < MyCubeGrid > ( ) )
2252 {
2353 if ( ShouldRemove ( grid ) )
2454 {
25- grid . Close ( ) ;
55+ if ( ! scanOnly )
56+ grid . Close ( ) ;
2657 count ++ ;
2758 }
2859 }
2960
30- Context . Respond ( $ "Deleted { count } grids missing the block subtype '{ subtype } '.") ;
61+ Context . Respond ( $ "{ ( scanOnly ? "Found" : " Deleted" ) } { count } grids missing the block subtype '{ subtype } '.") ;
3162
3263 bool ShouldRemove ( MyCubeGrid grid )
3364 {
@@ -44,7 +75,7 @@ bool ShouldRemove(MyCubeGrid grid)
4475
4576 [ Command ( "grids ownedby" , "Delete grids that the given player owns the majority of." ) ]
4677 [ Permission ( MyPromoteLevel . SpaceMaster ) ]
47- public void DeleteByOwner ( string name )
78+ public void DeleteByOwner ( string name , bool scanOnly = true )
4879 {
4980 var player = Utilities . GetPlayerByNameOrId ( name ) ;
5081 if ( player == null )
@@ -62,42 +93,44 @@ public void DeleteByOwner(string name)
6293 count ++ ;
6394 }
6495 }
65-
66- Context . Respond ( $ "Deleted { count } grids owned by '{ name } .'") ;
96+
97+ Context . Respond ( $ "{ ( scanOnly ? "Found" : " Deleted" ) } { count } grids owned by '{ name } .'") ;
6798 }
6899
69100 [ Command ( "grids blockslessthan" , "Delete grids with fewer than X blocks." ) ]
70101 [ Permission ( MyPromoteLevel . SpaceMaster ) ]
71- public void DeleteBlocksLessThan ( int minBlocks )
102+ public void DeleteBlocksLessThan ( int minBlocks , bool scanOnly = true )
72103 {
73104 var count = 0 ;
74105 foreach ( var grid in MyEntities . GetEntities ( ) . OfType < MyCubeGrid > ( ) )
75106 {
76107 if ( grid . BlocksCount < minBlocks )
77108 {
78- grid . Close ( ) ;
109+ if ( ! scanOnly )
110+ grid . Close ( ) ;
79111 count ++ ;
80112 }
81113 }
82114
83- Context . Respond ( $ "Deleted { count } grids with less than { minBlocks } blocks.") ;
115+ Context . Respond ( $ "{ ( scanOnly ? "Found" : " Deleted" ) } { count } grids with less than { minBlocks } blocks.") ;
84116 }
85117
86118 [ Command ( "grids blocksgreaterthan" , "Delete grids with greater than X blocks." ) ]
87119 [ Permission ( MyPromoteLevel . SpaceMaster ) ]
88- public void DeleteBlocksGreaterThan ( int maxBlocks )
120+ public void DeleteBlocksGreaterThan ( int maxBlocks , bool scanOnly = true )
89121 {
90122 var count = 0 ;
91123 foreach ( var grid in MyEntities . GetEntities ( ) . OfType < MyCubeGrid > ( ) )
92124 {
93125 if ( grid . BlocksCount > maxBlocks )
94126 {
95- grid . Close ( ) ;
127+ if ( ! scanOnly )
128+ grid . Close ( ) ;
96129 count ++ ;
97130 }
98131 }
99132
100- Context . Respond ( $ "Deleted { count } grids with greater than { maxBlocks } blocks.") ;
133+ Context . Respond ( $ "{ ( scanOnly ? "Found" : " Deleted" ) } { count } grids with greater than { maxBlocks } blocks.") ;
101134 }
102135
103136 [ Command ( "floating" , "Delete all floating objects." ) ]
0 commit comments