Skip to content

Commit 492d42f

Browse files
committed
Fix crashes and permission issues
1 parent a183bf2 commit 492d42f

6 files changed

Lines changed: 26 additions & 9 deletions

File tree

Essentials/Commands/DeleteModule.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Sandbox.Game.Entities;
77
using Torch.Commands;
8+
using Torch.Commands.Permissions;
89
using VRage.Game.ModAPI;
910

1011
namespace Essentials
@@ -13,6 +14,7 @@ namespace Essentials
1314
public class DeleteModule : CommandModule
1415
{
1516
[Command("grids nosubtype", "Delete all grids that don't have a block of the given subtype.")]
17+
[Permission(MyPromoteLevel.SpaceMaster)]
1618
public void DeleteBySubtype(string subtype)
1719
{
1820
var count = 0;
@@ -41,6 +43,7 @@ bool ShouldRemove(MyCubeGrid grid)
4143
}
4244

4345
[Command("grids ownedby", "Delete grids that the given player owns the majority of.")]
46+
[Permission(MyPromoteLevel.SpaceMaster)]
4447
public void DeleteByOwner(string name)
4548
{
4649
var player = Utilities.GetPlayerByNameOrId(name);
@@ -64,6 +67,7 @@ public void DeleteByOwner(string name)
6467
}
6568

6669
[Command("grids blockslessthan", "Delete grids with fewer than X blocks.")]
70+
[Permission(MyPromoteLevel.SpaceMaster)]
6771
public void DeleteBlocksLessThan(int minBlocks)
6872
{
6973
var count = 0;
@@ -79,6 +83,8 @@ public void DeleteBlocksLessThan(int minBlocks)
7983
Context.Respond($"Deleted {count} grids with less than {minBlocks} blocks.");
8084
}
8185

86+
[Command("grids blocksgreaterthan", "Delete grids with greater than X blocks.")]
87+
[Permission(MyPromoteLevel.SpaceMaster)]
8288
public void DeleteBlocksGreaterThan(int maxBlocks)
8389
{
8490
var count = 0;
@@ -95,6 +101,7 @@ public void DeleteBlocksGreaterThan(int maxBlocks)
95101
}
96102

97103
[Command("floating", "Delete all floating objects.")]
104+
[Permission(MyPromoteLevel.SpaceMaster)]
98105
public void DeleteFloating()
99106
{
100107
var count = 0;

Essentials/Commands/EntityModule.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ public void Delete(string entityName)
5959
[Permission(MyPromoteLevel.SpaceMaster)]
6060
public void Find(string name)
6161
{
62-
var search = name;
63-
if (string.IsNullOrEmpty(search))
62+
if (string.IsNullOrEmpty(name))
6463
return;
6564

6665
var sb = new StringBuilder("Found entities:\n");
6766
foreach (var entity in MyEntities.GetEntities())
6867
{
69-
if (entity is IMyVoxelBase voxel && voxel.StorageName.Contains(search, StringComparison.CurrentCultureIgnoreCase))
68+
if (entity is IMyVoxelBase voxel && (voxel.StorageName?.Contains(name, StringComparison.CurrentCultureIgnoreCase) ?? false))
7069
sb.AppendLine($"{voxel.StorageName} ({entity.EntityId})");
71-
else if (entity.DisplayName?.Contains(search, StringComparison.CurrentCultureIgnoreCase) ?? false)
70+
else if (entity?.DisplayName?.Contains(name, StringComparison.CurrentCultureIgnoreCase) ?? false)
7271
//This can be null??? :keen:
7372
sb.AppendLine($"{entity.DisplayName} ({entity.EntityId})");
7473
}
@@ -102,7 +101,7 @@ public void Teleport(string destination, string entityToMove = null)
102101

103102
IMyEntity targetEntity;
104103
if (string.IsNullOrEmpty(entityToMove))
105-
targetEntity = Context.Player.Controller.ControlledEntity.Entity;
104+
targetEntity = Context.Player?.Controller.ControlledEntity.Entity;
106105
else
107106
Utilities.TryGetEntityByNameOrId(entityToMove, out targetEntity);
108107

Essentials/Commands/GridModule.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public void SetOwner(string gridName, string playerName)
4444
identityId = player.IdentityId;
4545
}
4646

47+
grid.ChangeGridOwnership(identityId, MyOwnershipShareModeEnum.Faction);
48+
Context.Respond($"Transferred ownership of {grid.DisplayName} to {identityId}");
49+
50+
/*
4751
grid.GetBlocks(new List<IMySlimBlock>(), block =>
4852
{
4953
var cubeBlock = block.FatBlock as MyCubeBlock;
@@ -54,23 +58,25 @@ public void SetOwner(string gridName, string playerName)
5458
cubeBlock?.ChangeOwner(0, MyOwnershipShareModeEnum.All);
5559
cubeBlock?.ChangeOwner(identityId, ownerComp.ShareMode);
5660
return false;
57-
});
61+
});*/
5862
}
5963

6064
[Command("static large", "Makes all large grids static.")]
65+
[Permission(MyPromoteLevel.SpaceMaster)]
6166
public void StaticLarge()
6267
{
6368
foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>().Where(g => g.GridSizeEnum == MyCubeSize.Large))
6469
grid.ConvertToStatic();
6570
}
6671

6772
[Command("list", "List all grids owned by you.")]
73+
[Permission(MyPromoteLevel.None)]
6874
public void List()
6975
{
7076
var sb = new StringBuilder("Grids:\n");
7177
foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>())
7278
{
73-
if (grid.BigOwners.Contains(Context.Player.IdentityId))
79+
if (grid.BigOwners.Contains(Context.Player?.IdentityId ?? 0))
7480
sb.AppendLine($"{grid.DisplayName}: {grid.PositionComp.GetPosition().ToString("N")}");
7581
}
7682
Context.Respond(sb.ToString());

Essentials/Commands/PlayerModule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Essentials
1313
public class PlayerModule : CommandModule
1414
{
1515
[Command("w", "Send a private message to another player.")]
16+
[Permission(MyPromoteLevel.None)]
1617
public void Whisper(string playerName)
1718
{
1819
if (Context.Args.Count < 1)
@@ -32,7 +33,7 @@ public void Whisper(string playerName)
3233
return;
3334
}
3435

35-
Context.Torch.Multiplayer.SendMessage(message, Context.Player.DisplayName, player.IdentityId, MyFontEnum.Red);
36+
Context.Torch.Multiplayer.SendMessage(message, Context.Player?.DisplayName ?? "Server", player.IdentityId, MyFontEnum.Red);
3637
}
3738

3839
[Command("kick", "Kick a player from the game.")]

Essentials/Commands/WorldModule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
using Sandbox.Game.Entities;
77
using Sandbox.Game.World;
88
using Torch.Commands;
9+
using Torch.Commands.Permissions;
10+
using VRage.Game.ModAPI;
911

1012
namespace Essentials.Commands
1113
{
1214
public class WorldModule : CommandModule
1315
{
1416
[Command("identity clean", "Remove identities that have not logged on in X days.")]
17+
[Permission(MyPromoteLevel.SpaceMaster)]
1518
public void CleanIdentities(int days)
1619
{
1720
var idents = MySession.Static.Players.GetAllIdentities().ToList();
@@ -24,6 +27,7 @@ public void CleanIdentities(int days)
2427
}
2528

2629
[Command("identity purge", "Remove identities AND the grids they own if they have not logged on in X days.")]
30+
[Permission(MyPromoteLevel.SpaceMaster)]
2731
public void PurgeIdentities(int days)
2832
{
2933
var grids = MyEntities.GetEntities().OfType<MyCubeGrid>().ToList();

Essentials/EssentialsPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Essentials
1212
{
13-
[Plugin("Essentials", "1.0", "cbfdd6ab-4cda-4544-a201-f73efa3d46c0")]
13+
[Plugin("Essentials", "1.1", "cbfdd6ab-4cda-4544-a201-f73efa3d46c0")]
1414
public class EssentialsPlugin : TorchPluginBase, IWpfPlugin
1515
{
1616
private EssentialsControl _control;

0 commit comments

Comments
 (0)