Skip to content

Commit f8cecaf

Browse files
authored
Improved QoL of /back and /warp (SubnauticaNitrox#1181)
* command type cleanup & improved new commands * minor * review changes
1 parent 9f8e5e3 commit f8cecaf

12 files changed

Lines changed: 51 additions & 51 deletions

File tree

NitroxModel/DataStructures/GameLogic/NitroxVector3.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static NitroxVector3 Cross(NitroxVector3 vector1, NitroxVector3 vector2)
8181

8282
public override string ToString()
8383
{
84-
return "[Vector3 - {" + X + ", " + Y + ", " + Z + "}]";
84+
return $"[{X}, {Y}, {Z}]";
8585
}
8686
}
8787
}

NitroxServer/Communication/Packets/Processors/PlayerDeathEventProcessor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NitroxModel.Packets;
1+
using NitroxModel.DataStructures.GameLogic;
2+
using NitroxModel.Packets;
23
using NitroxModel.Server;
34
using NitroxServer.Communication.Packets.Processors.Abstract;
45
using NitroxServer.GameLogic;
@@ -26,6 +27,12 @@ public override void Process(PlayerDeathEvent packet, Player player)
2627
}
2728

2829
player.LastStoredPosition = packet.DeathPosition;
30+
31+
if (player.Permissions > Perms.MODERATOR)
32+
{
33+
player.SendPacket(new ChatMessage(ChatMessage.SERVER_ID, "You can use /back to go to your death location"));
34+
}
35+
2936
playerManager.SendPacketToOtherPlayers(packet, player);
3037
}
3138
}

NitroxServer/ConsoleCommands/Abstract/CallArgs.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace NitroxServer.ConsoleCommands.Abstract
55
{
66
public abstract partial class Command
77
{
8-
public class CallArgs
8+
public sealed class CallArgs
99
{
1010
public Command Command { get; }
1111
public string[] Args { get; }
@@ -25,11 +25,6 @@ public bool IsValid(int index)
2525
return index < Args.Length && index >= 0 && Args.Length != 0;
2626
}
2727

28-
public string Get(int index)
29-
{
30-
return Get<string>(index);
31-
}
32-
3328
public string GetTillEnd(int startIndex = 0)
3429
{
3530
// TODO: Proper argument capture/parse instead of this argument join hack
@@ -41,6 +36,12 @@ public string GetTillEnd(int startIndex = 0)
4136
return string.Empty;
4237
}
4338

39+
public string Get(int index)
40+
{
41+
return Get<string>(index);
42+
}
43+
44+
//TODO: Remove ability to use indexes and use an internal counter instead
4445
public T Get<T>(int index)
4546
{
4647
IParameter<object> param = Command.Parameters[index];

NitroxServer/ConsoleCommands/Abstract/Type/TypeBoolean.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
43
using NitroxModel.Helper;
54

65
namespace NitroxServer.ConsoleCommands.Abstract.Type
76
{
87
public class TypeBoolean : Parameter<bool?>, IParameter<object>
98
{
10-
private static readonly IList<string> noValues = new List<string>
9+
private static readonly string[] noValues = new string[]
1110
{
1211
bool.FalseString,
1312
"no",
1413
"off"
1514
};
1615

17-
private static readonly IList<string> yesValues = new List<string>
16+
private static readonly string[] yesValues = new string[]
1817
{
1918
bool.TrueString,
2019
"yes",
@@ -31,7 +30,6 @@ public override bool IsValid(string arg)
3130
public override bool? Read(string arg)
3231
{
3332
Validate.IsTrue(IsValid(arg), "Invalid boolean value received");
34-
3533
return yesValues.Contains(arg, StringComparer.OrdinalIgnoreCase);
3634
}
3735

NitroxServer/ConsoleCommands/Abstract/Type/TypeEnum.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace NitroxServer.ConsoleCommands.Abstract.Type
55
{
6-
public class TypeEnum<T> : Parameter<object> where T : struct
6+
public class TypeEnum<T> : Parameter<object> where T : struct, Enum
77
{
88
public TypeEnum(string name, bool required) : base(name, required)
99
{
@@ -12,16 +12,12 @@ public TypeEnum(string name, bool required) : base(name, required)
1212

1313
public override bool IsValid(string arg)
1414
{
15-
T result;
16-
return Enum.TryParse(arg, true, out result);
15+
return Enum.TryParse(arg, true, out T result);
1716
}
1817

1918
public override object Read(string arg)
2019
{
21-
T value;
22-
23-
Validate.IsTrue(Enum.TryParse(arg, true, out value), "Unknown value received");
24-
20+
Validate.IsTrue(Enum.TryParse(arg, true, out T value), "Unknown value received");
2521
return value;
2622
}
2723
}

NitroxServer/ConsoleCommands/Abstract/Type/TypeFloat.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ public TypeFloat(string name, bool isRequired) : base(name, isRequired) { }
88

99
public override bool IsValid(string arg)
1010
{
11-
float value;
12-
return float.TryParse(arg, out value);
11+
return float.TryParse(arg, out float value);
1312
}
1413

1514
public override float? Read(string arg)
1615
{
17-
float value;
18-
19-
Validate.IsTrue(float.TryParse(arg, out value), "Invalid decimal number received");
20-
16+
Validate.IsTrue(float.TryParse(arg, out float value), "Invalid decimal number received");
2117
return value;
2218
}
2319

NitroxServer/ConsoleCommands/Abstract/Type/TypeInt.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ public TypeInt(string name, bool isRequired) : base(name, isRequired) { }
88

99
public override bool IsValid(string arg)
1010
{
11-
int value;
12-
return int.TryParse(arg, out value);
11+
return int.TryParse(arg, out int value);
1312
}
1413

1514
public override int? Read(string arg)
1615
{
17-
int value;
18-
19-
Validate.IsTrue(int.TryParse(arg, out value), "Invalid integer received");
20-
16+
Validate.IsTrue(int.TryParse(arg, out int value), "Invalid integer received");
2117
return value;
2218
}
2319

NitroxServer/ConsoleCommands/Abstract/Type/TypePlayer.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ public TypePlayer(string name, bool required) : base(name, required)
1515

1616
public override bool IsValid(string arg)
1717
{
18-
Player player;
19-
return playerManager.TryGetPlayerByName(arg, out player);
18+
return playerManager.TryGetPlayerByName(arg, out Player player);
2019
}
2120

2221
public override Player Read(string arg)
2322
{
24-
Player player;
25-
Validate.IsTrue(playerManager.TryGetPlayerByName(arg, out player), "Player not found");
23+
Validate.IsTrue(playerManager.TryGetPlayerByName(arg, out Player player), "Player not found");
2624
return player;
2725
}
2826
}

NitroxServer/ConsoleCommands/BackCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using NitroxModel.DataStructures.GameLogic;
22
using NitroxModel.Helper;
3-
using NitroxModel.Logger;
43
using NitroxServer.ConsoleCommands.Abstract;
54

65
namespace NitroxServer.ConsoleCommands
@@ -23,7 +22,7 @@ protected override void Execute(CallArgs args)
2322
}
2423

2524
player.Teleport(player.LastStoredPosition.Value);
26-
SendMessage(args.Sender, $"Teleported back {player.LastStoredPosition.Value}");
25+
SendMessage(args.Sender, $"Teleported back to {player.LastStoredPosition.Value}");
2726
}
2827
}
2928
}

NitroxServer/ConsoleCommands/BroadcastCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ namespace NitroxServer.ConsoleCommands
77
{
88
internal class BroadcastCommand : Command
99
{
10-
private readonly PlayerManager playerManager;
11-
12-
public BroadcastCommand(PlayerManager playerManager) : base("broadcast", Perms.ADMIN, "Broadcasts a message on the server", true)
10+
public BroadcastCommand() : base("broadcast", Perms.ADMIN, "Broadcasts a message on the server", true)
1311
{
14-
this.playerManager = playerManager;
1512
AddAlias("say");
1613
AddParameter(new TypeString("message", true));
1714
}

0 commit comments

Comments
 (0)