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

Commit f64ce54

Browse files
committed
Fixes /admin speed, fixes ALL /admin move commands. Fixes /admin scan grids ownedby:"Space Pirates". /admin speed now uses the time argument
1 parent e48ab6d commit f64ce54

File tree

12 files changed

+304
-267
lines changed

12 files changed

+304
-267
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//152
1+
//179
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.6.152")]
10-
[assembly: AssemblyVersion("1.13.6.152")]
9+
[assembly: AssemblyFileVersion("1.13.6.179")]
10+
[assembly: AssemblyVersion("1.13.6.179")]

EssentialsPlugin/ChatHandlers/Admin/HandleAdminSpeed.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using SEModAPIInternal.API.Entity.Sector.SectorObject;
1212
using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid;
1313
using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock;
14+
using VRage.Game.ModAPI;
1415
using VRage.ModAPI;
1516
public class HandleAdminSpeed : ChatHandlerBase
1617
{
@@ -42,8 +43,7 @@ public override bool AllowedInConsole( )
4243
{
4344
return true;
4445
}
45-
46-
// /admin ownership change name gridId
46+
4747
public override bool HandleCommand( ulong userId, string[ ] words )
4848
{
4949
if ( words.Length < 2 )
@@ -56,14 +56,15 @@ public override bool HandleCommand( ulong userId, string[ ] words )
5656
ulong steamId = PlayerMap.Instance.GetSteamIdFromPlayerName( name, true );
5757
if ( steamId == 0 )
5858
{
59-
Communication.SendPrivateInformation( userId, string.Format( "Couldn't find player with name '{1}'", words[0] ) );
59+
Communication.SendPrivateInformation( userId, $"Couldn't find player with name '{words[0]}'" );
6060
return true;
6161
}
62+
6263
long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId( steamId ).First( );
6364
IMyEntity player;
6465
if ( !MyAPIGateway.Entities.TryGetEntityById( PlayerMap.Instance.GetPlayerEntityId( steamId ), out player ) )
6566
{
66-
Communication.SendPrivateInformation( userId, string.Format( "Couldn't find player with name '{1}'", words[0] ) );
67+
Communication.SendPrivateInformation( userId, $"Couldn't find player with name '{words[0]}'" );
6768
return true;
6869
}
6970

@@ -74,19 +75,21 @@ public override bool HandleCommand( ulong userId, string[ ] words )
7475
return true;
7576
}
7677

77-
int setTime=0;
78+
int setMinutes = int.MaxValue;
7879
if ( words.Length > 2 )
7980
{
80-
if ( !int.TryParse( words[2], out setTime ) )
81+
if ( !int.TryParse( words[2], out setMinutes ) )
8182
{
8283
Communication.SendPrivateInformation( userId, GetHelp( ) );
8384
return true;
8485
}
8586
}
86-
byte[ ] data = Encoding.UTF8.GetBytes( MyAPIGateway.Utilities.SerializeToXML<float>( setSpeed ) );
87-
Communication.SendDataMessage( steamId, Communication.DataMessageType.MaxSpeed, data );
88-
//ProcessSpeed.SpeedPlayers.Add( new Tuple<IMyPlayer, double, int>( (IMyPlayer)player, setSpeed, setTime) );
89-
Communication.SendPrivateInformation( userId, string.Format( "Set maximum speed of player {0} to {1}m/s.", words[0], setSpeed ) );
87+
DateTime setTime = DateTime.Now + TimeSpan.FromMinutes( setMinutes );
88+
// byte[ ] data = Encoding.UTF8.GetBytes( MyAPIGateway.Utilities.SerializeToXML<float>( setSpeed ) );
89+
// Communication.SendDataMessage( steamId, Communication.DataMessageType.MaxSpeed, data );
90+
lock(ProcessSpeed.SpeedPlayers)
91+
{ ProcessSpeed.SpeedPlayers[playerId] = new Tuple< float, DateTime>( setSpeed, setTime);}
92+
Communication.SendPrivateInformation( userId, $"Set maximum speed of player {words[0]} to {setSpeed}m/s{( setMinutes == int.MaxValue ? "." : $" for {setMinutes} minutes." )}" );
9093
return true;
9194
}
9295
}

EssentialsPlugin/ChatHandlers/AdminMove/HandleAdminMoveAreaToPosition.cs

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -73,59 +73,26 @@ public override bool HandleCommand(ulong userId, string[] words)
7373
Vector3D difference = startPosition - movePosition;
7474
float radius = float.Parse(words[6]);
7575

76-
Communication.SendPrivateInformation(userId, string.Format("Moving all grids in a radius of {0} near {1} to {2}", radius, General.Vector3DToString(startPosition), General.Vector3DToString(movePosition)));
77-
78-
List<MyObjectBuilder_CubeGrid> gridsToMove = new List<MyObjectBuilder_CubeGrid>();
76+
Communication.SendPrivateInformation(userId, $"Moving all grids in a radius of {radius} near {startPosition} to {movePosition}" );
77+
7978
BoundingSphereD sphere = new BoundingSphereD(startPosition, radius);
8079
List<IMyEntity> entitiesToMove = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
80+
int moveCount = 0;
81+
foreach ( IMyEntity entity in entitiesToMove )
82+
{
83+
if ( !( entity is IMyCubeGrid ) )
84+
continue;
8185

82-
// Wrapper.GameAction(() =>
83-
// {
84-
foreach (IMyEntity entity in entitiesToMove)
85-
{
86-
if (!(entity is IMyCubeGrid))
87-
continue;
88-
89-
Communication.SendPrivateInformation(userId, string.Format("Moving '{0}' from {1} to {2}", entity.DisplayName, General.Vector3DToString(entity.GetPosition()), General.Vector3DToString(entity.GetPosition() + difference)));
90-
91-
gridsToMove.Add((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder());
92-
//MyAPIGateway.Entities.RemoveEntity(entity);
93-
CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity);
94-
gridEntity.Dispose();
95-
}
96-
// });
97-
98-
Log.Info("Entities Removed ... pausing");
99-
Thread.Sleep(5000);
100-
Log.Info("Removing entities from closed entities");
101-
102-
Wrapper.GameAction(() =>
103-
{
104-
foreach(IMyEntity entity in entitiesToMove)
105-
{
106-
if (!(entity is IMyCubeGrid))
107-
continue;
108-
109-
Log.Info(string.Format("Removing '{0}' for move", entity.DisplayName));
110-
MyAPIGateway.Entities.RemoveFromClosedEntities(entity);
111-
}
112-
});
86+
Vector3D target = entity.GetPosition( ) + difference;
11387

114-
Thread.Sleep(10000);
88+
Communication.SendPrivateInformation( userId, $"Moving '{entity.DisplayName}' from {entity.GetPosition( )} to {target}" );
11589

116-
Wrapper.GameAction(() =>
117-
{
118-
foreach(MyObjectBuilder_CubeGrid grid in gridsToMove)
119-
{
120-
grid.PositionAndOrientation = new MyPositionAndOrientation(grid.PositionAndOrientation.Value.Position + difference, grid.PositionAndOrientation.Value.Forward, grid.PositionAndOrientation.Value.Up);
121-
//Log.Info(string.Format("Adding '{0}' for move", grid.DisplayName));
122-
Communication.SendPrivateInformation(userId, string.Format("Adding grid '{0}' back to world.", grid.DisplayName));
123-
SectorObjectManager.Instance.AddEntity(new CubeGridEntity(grid));
124-
Thread.Sleep(1000);
125-
}
126-
});
90+
//position can be set directly on the server
91+
Wrapper.GameAction( ( ) => entity.SetPosition( target ) );
92+
moveCount++;
93+
}
12794

128-
Communication.SendPrivateInformation(userId, string.Format("Moved {0} grids", gridsToMove.Count));
95+
Communication.SendPrivateInformation(userId, $"Moved {moveCount} grids" );
12996

13097
return true;
13198
}

EssentialsPlugin/ChatHandlers/AdminMove/HandleAdminMoveAreaTowards.cs

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -77,55 +77,28 @@ public override bool HandleCommand(ulong userId, string[] words)
7777
movementPosition.Normalize();
7878
Vector3D finalPosition = movementPosition * distance;
7979
//finalPosition += startPosition;
80-
81-
List<MyObjectBuilder_CubeGrid> gridsToMove = new List<MyObjectBuilder_CubeGrid>();
80+
8281
BoundingSphereD sphere = new BoundingSphereD(startPosition, radius);
8382
List<IMyEntity> entitiesToMove = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
8483

85-
Communication.SendPrivateInformation(userId, string.Format("Moving all grids in a radius of {0} near {1} towards {2} by {3} meters", radius, General.Vector3DToString(startPosition), General.Vector3DToString(targetPosition), distance));
86-
87-
Wrapper.GameAction(() =>
88-
{
89-
foreach (IMyEntity entity in entitiesToMove)
90-
{
91-
if (!(entity is IMyCubeGrid))
92-
continue;
93-
94-
Communication.SendPrivateInformation(userId, string.Format("Moving '{0}' from {1} to {2}", entity.DisplayName, General.Vector3DToString(entity.GetPosition()), General.Vector3DToString(entity.GetPosition() + finalPosition)));
95-
96-
gridsToMove.Add((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder());
97-
MyAPIGateway.Entities.RemoveEntity(entity);
98-
99-
}
100-
});
101-
102-
Thread.Sleep(5000);
103-
104-
Wrapper.GameAction(() =>
105-
{
106-
foreach(IMyEntity entity in entitiesToMove)
107-
{
108-
if (!(entity is IMyCubeGrid))
109-
continue;
84+
Communication.SendPrivateInformation(userId, $"Moving all grids in a radius of {radius} near {General.Vector3DToString( startPosition )} towards {General.Vector3DToString( targetPosition )} by {distance} meters" );
85+
int moveCount = 0;
86+
foreach ( IMyEntity entity in entitiesToMove )
87+
{
88+
if ( !( entity is IMyCubeGrid ) )
89+
continue;
11090

111-
Log.Info(string.Format("Removing '{0}' for move", entity.DisplayName));
112-
MyAPIGateway.Entities.RemoveFromClosedEntities(entity);
113-
}
114-
});
91+
Vector3D target = entity.GetPosition( ) + finalPosition;
11592

116-
Thread.Sleep(10000);
93+
Communication.SendPrivateInformation( userId, $"Moving '{entity.DisplayName}' from {entity.GetPosition( )} to {target}" );
11794

118-
Wrapper.GameAction(() =>
119-
{
120-
foreach(MyObjectBuilder_CubeGrid grid in gridsToMove)
121-
{
122-
grid.PositionAndOrientation = new MyPositionAndOrientation(grid.PositionAndOrientation.Value.Position + finalPosition, grid.PositionAndOrientation.Value.Forward, grid.PositionAndOrientation.Value.Up);
123-
Communication.SendPrivateInformation(userId, string.Format("Adding '{0}' for move", grid.DisplayName));
124-
SectorObjectManager.Instance.AddEntity(new CubeGridEntity(grid));
125-
}
126-
});
95+
//position can be set directly on the server
96+
Wrapper.GameAction( ( ) => entity.SetPosition( target ) );
12797

128-
Communication.SendPrivateInformation(userId, string.Format("Finished moving {0} grids", gridsToMove.Count));
98+
moveCount++;
99+
}
100+
101+
Communication.SendPrivateInformation(userId, $"Finished moving {moveCount} grids" );
129102

130103
return true;
131104
}

EssentialsPlugin/ChatHandlers/AdminMove/HandleAdminMoveGridTo.cs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using EssentialsPlugin.Utility;
77
using Sandbox.Common.ObjectBuilders;
88
using Sandbox.Engine.Multiplayer;
9+
using Sandbox.Game.Entities;
910
using Sandbox.Game.Replication;
1011
using Sandbox.ModAPI;
1112
using SEModAPIInternal.API.Entity;
@@ -71,7 +72,7 @@ public override bool HandleCommand(ulong userId, string[] words)
7172
else
7273
targetName = string.Join(" ", words.Skip(1).ToArray());
7374

74-
Communication.SendPrivateInformation(userId, string.Format("Moving {0} to within {1}m of {2}. This may take about 20 seconds.", sourceName, distance, targetName));
75+
Communication.SendPrivateInformation(userId, $"Moving {sourceName} to within {distance}m of {targetName}." );
7576

7677
Vector3D position;
7778
MyEntity entity = (MyEntity)Player.FindControlledEntity( targetName );
@@ -80,49 +81,33 @@ public override bool HandleCommand(ulong userId, string[] words)
8081
entity = CubeGrids.Find( targetName );
8182
if ( entity == null )
8283
{
83-
Communication.SendPrivateInformation( userId, string.Format( "Can not find user or grid with the name: {0}", targetName ) );
84+
Communication.SendPrivateInformation( userId, $"Can not find user or grid with the name: {targetName}" );
8485
return true;
8586
}
8687
position = entity.PositionComp.GetPosition();
8788
}
8889
else
8990
position = entity.PositionComp.GetPosition();
9091

91-
Vector3D startPosition = MathUtility.RandomPositionFromPoint((Vector3)position, distance);
9292
MyEntity gridToMove = CubeGrids.Find( sourceName );
9393
if (gridToMove == null)
9494
{
95-
Communication.SendPrivateInformation(userId, string.Format("Unable to find: {0}", sourceName));
95+
Communication.SendPrivateInformation(userId, $"Unable to find: {sourceName}" );
9696
return true;
9797
}
98-
99-
Communication.MoveMessage( 0, "normal", startPosition.X, startPosition.Y, startPosition.Z, gridToMove.EntityId );
100-
101-
//Wrapper.GameAction( ( ) =>
102-
//{
103-
// gridToMove.GetTopMostParent( ).SetPosition( startPosition );
104-
// Log.Info( string.Format( "Moving '{0}' from {1} to {2}", gridToMove.DisplayName, gridToMove.GetPosition( ), startPosition ) );
105-
// MyMultiplayer.ReplicateImmediatelly( MyExternalReplicable.FindByObject( gridToMove.GetTopMostParent() ) );
106-
//} );
107-
/*
108-
Thread.Sleep(5000);
109-
110-
Wrapper.GameAction(() =>
111-
{
112-
MyAPIGateway.Entities.RemoveFromClosedEntities(entity);
113-
Log.Info(string.Format("Removing '{0}' for move", entity.DisplayName));
114-
});
98+
Vector3D? testPos = null;
11599

116-
Thread.Sleep(10000);
100+
Wrapper.GameAction(() => testPos = MyEntities.FindFreePlace(position, (float)gridToMove.PositionComp.WorldAABB.Extents.Max( ) + distance));
117101

118-
Wrapper.GameAction(() =>
119-
{
120-
gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(startPosition, gridBuilder.PositionAndOrientation.Value.Forward, gridBuilder.PositionAndOrientation.Value.Up);
121-
Log.Info(string.Format("Adding '{0}' for move", gridBuilder.DisplayName));
122-
SectorObjectManager.Instance.AddEntity(new CubeGridEntity(gridBuilder));
123-
});*/
124-
125-
Communication.SendPrivateInformation(userId, string.Format("Moved {0} to within {1}m of {2}", sourceName, (int)Math.Round(Vector3D.Distance(startPosition, position)), targetName));
102+
if (testPos == null)
103+
{
104+
Communication.SendPrivateInformation(userId, $"Could not find valid location to move: {sourceName}. Try increasing distance.");
105+
return true;
106+
}
107+
108+
Wrapper.GameAction( ()=>gridToMove.PositionComp.SetPosition( testPos.Value ) );
109+
110+
Communication.SendPrivateInformation(userId, $"Moved {sourceName} to within {(int)Math.Round( Vector3D.Distance(testPos.Value, position ) )}m of {targetName}" );
126111
return true;
127112
}
128113
}

0 commit comments

Comments
 (0)