11namespace EssentialsPlugin . ChatHandlers . AdminConceal
22{
3+ using System . Collections . Generic ;
34 using System . Linq ;
45 using EntityManagers ;
56 using EssentialsPlugin . Utility ;
7+ using Sandbox . Common . ObjectBuilders ;
8+ using Sandbox . Engine . Multiplayer ;
9+ using Sandbox . Game . Entities ;
10+ using Sandbox . Game . Replication ;
11+ using Sandbox . ModAPI ;
12+ using SEModAPIInternal . API . Common ;
13+ using SEModAPIInternal . API . Entity ;
14+ using VRage . Game ;
15+ using VRage . Game . Entity ;
16+ using VRage . Game . ModAPI ;
17+ using VRage . ModAPI ;
18+ using VRage . ObjectBuilders ;
19+ using VRageMath ;
620
721 public class HandleAdminReveal : ChatHandlerBase
822 {
@@ -18,15 +32,14 @@ public override string GetCommandText()
1832
1933 public override Communication . ServerDialogItem GetHelpDialog ( )
2034 {
21- Communication . ServerDialogItem DialogItem = new Communication . ServerDialogItem
22- {
23- title = "Help" ,
24- header = "Admin Reveal" ,
25- content = " This command allows you to reveal concealed grids.|" +
26- "Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" +
27- "This command will run when concealment is disabled, and respects the update time setting." ,
28- buttonText = "close"
29- } ;
35+ Communication . ServerDialogItem DialogItem = new Communication . ServerDialogItem ( ) ;
36+ DialogItem . title = "Help" ;
37+ DialogItem . header = "Admin Reveal" ;
38+ DialogItem . content =
39+ " This command allows you to reveal concealed grids.|" +
40+ "Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" +
41+ "This command will run when concealment is disabled, and respects the update time setting." ;
42+ DialogItem . buttonText = "close" ;
3043 return DialogItem ;
3144 }
3245
@@ -43,14 +56,87 @@ public override bool AllowedInConsole()
4356 public override bool HandleCommand ( ulong userId , string [ ] words )
4457 {
4558 bool force = words . FirstOrDefault ( x => x . ToLower ( ) == "force" ) != null ;
59+ bool now = words . Count ( ) > 1 && words [ 1 ] == "now" ;
4660
47- if ( force )
61+ if ( force && ! now )
4862 EntityManagement . RevealAll ( ) ;
4963
5064 else
5165 {
66+ HashSet < IMyEntity > entities = new HashSet < IMyEntity > ( ) ;
67+ Wrapper . GameAction ( ( ) => MyAPIGateway . Entities . GetEntities ( entities ) ) ;
68+
69+ List < MyObjectBuilder_EntityBase > addList = new List < MyObjectBuilder_EntityBase > ( ) ;
70+ int count = 0 ;
71+
72+ if ( ! now )
73+ {
74+ Wrapper . GameAction ( ( ) =>
75+ {
76+ foreach ( IMyEntity entity in entities )
77+ {
78+ if ( entity . InScene )
79+ continue ;
80+
81+ if ( ! ( entity is IMyCubeGrid ) )
82+ continue ;
83+
84+ //if ( now )
85+ // EntityManagement.RevealEntity( new KeyValuePair<IMyEntity, string>( entity, "Immediate force reveal" ) );
86+
87+ count ++ ;
88+ }
89+ } ) ;
90+ }
91+
92+ if ( now )
93+ {
94+ Wrapper . GameAction ( ( ) =>
95+ {
96+ foreach ( IMyEntity entity in entities )
97+ {
98+ if ( entity . InScene )
99+ continue ;
100+
101+ if ( ! ( entity is MyCubeGrid ) )
102+ continue ;
103+
104+ count ++ ;
105+
106+ MyCubeGrid grid = ( MyCubeGrid ) entity ;
107+ MyObjectBuilder_EntityBase builder = grid . GetObjectBuilder ( ) ;
108+
109+ long ownerId = 0 ;
110+ string ownerName = "" ;
111+ if ( grid . BigOwners . Count > 0 )
112+ {
113+ ownerId = grid . BigOwners . First ( ) ;
114+ ownerName = PlayerMap . Instance . GetPlayerItemFromPlayerId ( ownerId ) . Name ;
115+ }
116+
117+
118+ entity . PersistentFlags = ( MyPersistentEntityFlags2 . InScene | MyPersistentEntityFlags2 . CastShadows ) ;
119+ MyAPIGateway . Entities . RemapObjectBuilder ( builder ) ;
120+
121+ //Log.Info("Conceal", string.Format("Force Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, builder.EntityId));
122+ Log . Info ( "Revealing" ) ;
123+ IMyEntity newEntity = MyAPIGateway . Entities . CreateFromObjectBuilder ( builder ) ;
124+ entity . InScene = true ;
125+ entity . OnAddedToScene ( entity ) ;
126+ entity . Close ( ) ;
127+ MyAPIGateway . Entities . AddEntity ( newEntity ) ;
128+ MyMultiplayer . ReplicateImmediatelly ( MyExternalReplicable . FindByObject ( newEntity ) ) ;
129+ entity . Stop ( ) ;
130+ }
131+ } ) ;
132+ }
133+
134+ if ( ! now )
52135 Communication . SendPrivateInformation ( userId ,
53- $ "Command would reveal { EntityManagement . RemovedGrids . Count } grids. Type /admin reveal force to reveal them." ) ;
136+ $ "Command would reveal { count } grids. Type /admin reveal force to reveal them." ) ;
137+
138+ else
139+ Communication . SendPrivateInformation ( userId , $ "Command revealed { count } grids." ) ;
54140 }
55141 return true ;
56142 }
0 commit comments