Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 9551a33

Browse files
committed
Fixed concealment appearing to always conceal the same grids. Changed /help to show dialog by default. Added /revoke command for player block enforcement. Fixed /reveal command/
1 parent 4310910 commit 9551a33

File tree

7 files changed

+226
-106
lines changed

7 files changed

+226
-106
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//5
1+
//14
22
//
33
// This code was generated by a tool. Any changes made manually will be lost
44
// the next time this code is regenerated.
55
//
66

77
using System.Reflection;
88

9-
[assembly: AssemblyFileVersion("1.13.7.5")]
10-
[assembly: AssemblyVersion("1.13.7.5")]
9+
[assembly: AssemblyFileVersion("1.13.7.14")]
10+
[assembly: AssemblyVersion("1.13.7.14")]

EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminReveal.cs

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -56,87 +56,14 @@ public override bool AllowedInConsole()
5656
public override bool HandleCommand(ulong userId, string[] words)
5757
{
5858
bool force = words.FirstOrDefault( x => x.ToLower( ) == "force" ) != null;
59-
bool now = words.Count( ) > 1 && words[1] == "now";
6059

61-
if ( force && !now )
60+
if ( force)
6261
EntityManagement.RevealAll( );
6362

6463
else
6564
{
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 )
13565
Communication.SendPrivateInformation( userId,
136-
$"Command would reveal {count} grids. Type /admin reveal force to reveal them." );
137-
138-
else
139-
Communication.SendPrivateInformation(userId, $"Command revealed {count} grids." );
66+
$"Command would reveal {EntityManagement.UnregisteredEntities.Count} grids. Type /admin reveal force to reveal them." );
14067
}
14168
return true;
14269
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
namespace EssentialsPlugin.ChatHandlers
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Security.Cryptography;
6+
using System.Text;
7+
using EssentialsPlugin.Settings;
8+
using Sandbox.Definitions;
9+
using Sandbox.Game.Entities;
10+
using Sandbox.Game.Entities.Cube;
11+
using SEModAPIInternal.API.Common;
12+
using Utility;
13+
using VRage.Game;
14+
using VRage.Game.Entity;
15+
16+
public class HandleRevoke : ChatHandlerBase
17+
{
18+
19+
public override string GetHelp()
20+
{
21+
return "Revokes ownership of blocks handled by player block enforcement. Use /revoke list to get a list of available block types.";
22+
}
23+
24+
public override string GetCommandText()
25+
{
26+
return "/revoke";
27+
}
28+
29+
public override Communication.ServerDialogItem GetHelpDialog( )
30+
{
31+
var dialogItem = new Communication.ServerDialogItem
32+
{
33+
title = "Help",
34+
header = "/revoke",
35+
buttonText = "close",
36+
content = "Revokes ownership of blocks handled by player block enforcement. |" +
37+
"Use /revoke list to get a list of block types you can revoke ownership of, " +
38+
"then use /revoke (blocktype) to revoke ownership of ALL blocks of that type. |" +
39+
"Blocks you revoke ownership of will be reduced to 1% build state and the components " +
40+
"will be left in place."
41+
};
42+
return dialogItem;
43+
}
44+
45+
public override bool IsAdminCommand()
46+
{
47+
return false;
48+
}
49+
50+
public override bool AllowedInConsole()
51+
{
52+
return false;
53+
}
54+
55+
public override bool HandleCommand( ulong userId, string[ ] words )
56+
{
57+
if (words.Length < 1)
58+
{
59+
Communication.SendPrivateInformation( userId, GetHelp() );
60+
return true;
61+
}
62+
63+
if (!PluginSettings.Instance.PlayerBlockEnforcementEnabled)
64+
{
65+
//nothing to do here
66+
Communication.SendPrivateInformation( userId, "Player block enforcement is not enabled on this server" );
67+
return true;
68+
}
69+
70+
if (words[0].ToLower() == "list")
71+
{
72+
StringBuilder message = new StringBuilder();
73+
message.Append("Available block types:|");
74+
foreach (var enf in PluginSettings.Instance.PlayerBlockEnforcementItems)
75+
{
76+
switch (enf.Mode)
77+
{
78+
case SettingsBlockEnforcementItem.EnforcementMode.Off:
79+
continue;
80+
81+
case SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId:
82+
{
83+
message.Append( $"{enf.BlockSubtypeId}|" );
84+
continue;
85+
}
86+
87+
case SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId:
88+
{
89+
message.Append( $"{enf.BlockTypeId}|" );
90+
continue;
91+
}
92+
}
93+
}
94+
message.Append( "|Use /revoke (blocktype) to revoke ownership." );
95+
Communication.DisplayDialog( userId, "Help", "/revoke", message.ToString() );
96+
return true;
97+
}
98+
99+
foreach (var enf in PluginSettings.Instance.PlayerBlockEnforcementItems)
100+
{
101+
switch (enf.Mode)
102+
{
103+
case SettingsBlockEnforcementItem.EnforcementMode.Off:
104+
continue;
105+
106+
case SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId:
107+
{
108+
if (!enf.BlockSubtypeId.Contains( words[0], StringComparison.CurrentCultureIgnoreCase ))
109+
continue;
110+
RevokeOwnership( userId, enf.BlockSubtypeId, true );
111+
return true;
112+
}
113+
114+
case SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId:
115+
{
116+
if (!enf.BlockTypeId.Contains( words[0], StringComparison.CurrentCultureIgnoreCase ))
117+
continue;
118+
RevokeOwnership( userId, enf.BlockTypeId, false );
119+
return true;
120+
}
121+
}
122+
}
123+
return true;
124+
}
125+
126+
private void RevokeOwnership( ulong steamId, string blocktype, bool isSubtype )
127+
{
128+
long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( steamId );
129+
130+
int counter = 0;
131+
132+
HashSet<MyEntity> entities = new HashSet<MyEntity>();
133+
Wrapper.GameAction( () => entities = MyEntities.GetEntities() );
134+
135+
foreach (var entity in entities)
136+
{
137+
var grid = entity as MyCubeGrid;
138+
if (grid == null)
139+
continue;
140+
141+
if (!grid.SmallOwners.Contains( playerId ))
142+
continue;
143+
144+
foreach (var block in grid.GetFatBlocks())
145+
{
146+
if (block.OwnerId != playerId)
147+
continue;
148+
149+
if (isSubtype && block.BlockDefinition.Id.SubtypeId.ToString().Contains( blocktype, StringComparison.CurrentCultureIgnoreCase ))
150+
{
151+
//set owner to nobody in block enforcement
152+
lock(PlayerBlockEnforcement.BlockOwners)
153+
if (PlayerBlockEnforcement.BlockOwners.ContainsKey( (MyTerminalBlock) block ))
154+
PlayerBlockEnforcement.BlockOwners[(MyTerminalBlock) block] = 0;
155+
156+
Wrapper.GameAction(() =>
157+
{
158+
//change owner to nobody and reduce build to 1%
159+
block.ChangeOwner(0, MyOwnershipShareModeEnum.None);
160+
block.SlimBlock.DecreaseMountLevelToDesiredRatio( 0.1f, null );
161+
} );
162+
counter++;
163+
}
164+
165+
if (!isSubtype && block.BlockDefinition.Id.TypeId.ToString().Contains(blocktype, StringComparison.CurrentCultureIgnoreCase))
166+
{
167+
lock(PlayerBlockEnforcement.BlockOwners)
168+
if (PlayerBlockEnforcement.BlockOwners.ContainsKey( (MyTerminalBlock) block ))
169+
PlayerBlockEnforcement.BlockOwners[(MyTerminalBlock) block] = 0;
170+
171+
Wrapper.GameAction(() =>
172+
{
173+
block.ChangeOwner(0, MyOwnershipShareModeEnum.None);
174+
block.SlimBlock.DecreaseMountLevelToDesiredRatio(0.1f, null);
175+
});
176+
counter++;
177+
}
178+
}
179+
}
180+
181+
Communication.SendPrivateInformation( steamId, $"Revoked ownership of {counter} {blocktype} blocks" );
182+
}
183+
}
184+
185+
}
186+

EssentialsPlugin/EntityManagers/EntityManagement.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void CheckAndConcealEntities( )
5757
foreach ( GridGroup group in GridGroup.GetAllGroups( GridLinkTypeEnum.Logical ) )
5858
{
5959
//we're using grid groups so that multi-part pirate ships don't lose pieces
60-
if(PluginSettings.Instance.DynamicConcealPirates)
60+
if(!PluginSettings.Instance.DynamicConcealPirates)
6161
{
6262
if ( group.Parent.GetOwner() == "Space Pirates" )
6363
{
@@ -71,6 +71,9 @@ public static void CheckAndConcealEntities( )
7171
if ( grid.Physics == null ) //projection
7272
continue;
7373

74+
if ( UnregisteredEntities.Contains( grid ) )
75+
continue;
76+
7477
if ( grid.GridSizeEnum != MyCubeSize.Small )
7578
{
7679
if ( grid.IsStatic && !PluginSettings.Instance.ConcealIncludeStations )
@@ -566,7 +569,9 @@ static public void RevealAll( )
566569

567570
_checkReveal = true;
568571

569-
foreach ( var entity in UnregisteredEntities )
572+
CheckAndRevealEntitiesObsolete();
573+
574+
foreach ( var entity in UnregisteredEntities.ToArray() )
570575
{
571576
if (PluginSettings.Instance.DynamicShowMessages)
572577
Essentials.Log.Info("Revealed - Id: {0} -> Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}",
@@ -609,8 +614,8 @@ private static void UnregisterHierarchy( MyEntity entity )
609614
if ( entity.Hierarchy == null )
610615
return;
611616

612-
if ( UnregisteredEntities.Contains( entity ) )
613-
return;
617+
//if ( UnregisteredEntities.Contains( entity ) )
618+
// return;
614619

615620
foreach ( var child in entity.Hierarchy.Children )
616621
{

EssentialsPlugin/Essentials.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ private void DoInit( string path )
12921292
new HandleFaction( ),
12931293
new HandleFactionF( ),
12941294
new HandleMotd( ),
1295+
new HandleRevoke( ),
12951296

12961297
//Tickets
12971298
new HandleTicketAdd( ),
@@ -1501,12 +1502,12 @@ public void HandleChatMessage( ulong steamId, string message )
15011502
if (commandParts[0].ToLower() == "/help")
15021503
{
15031504
//user wants some help
1504-
if (commandParts.Count > 1 && commandParts[1].ToLower() == "dialog")
1505-
HandleHelpDialog(remoteUserId, commandParts);
1505+
if (commandParts.Count > 1 && commandParts[1].ToLower() == "chat")
1506+
HandleHelpCommand(remoteUserId, commandParts);
15061507
//do we want help in a dialog window?
15071508

15081509
else
1509-
HandleHelpCommand(remoteUserId, commandParts);
1510+
HandleHelpDialog(remoteUserId, commandParts);
15101511

15111512
return;
15121513
}

EssentialsPlugin/EssentialsPlugin.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<Compile Include="ChatHandlers\Admin\HandleAdminIdentityCleanup.cs" />
8484
<Compile Include="ChatHandlers\Admin\HandleAdminSpawnCargo.cs" />
8585
<Compile Include="ChatHandlers\Admin\HandleAdminVersion.cs" />
86+
<Compile Include="ChatHandlers\HandleRevoke.cs" />
8687
<Compile Include="ChatHandlers\HandleLastSeen.cs" />
8788
<Compile Include="ChatHandlers\Settings\HandleSettingsEnableBlockEnforcement.cs" />
8889
<Compile Include="ChatHandlers\Settings\HandleSettingsGetBlockEnforcement.cs" />

0 commit comments

Comments
 (0)