Skip to content

Commit 281f71d

Browse files
feat: allow for optional "set" before code in command
1 parent 18b587c commit 281f71d

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

src/AutoCode.cs

+38-10
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ private class Commands
818818
public string PickCode = "pick";
819819
public string RandomCode = "random";
820820
public string RemoveCode = "remove";
821+
public string SetCode = "set";
821822
public string QuietMode = "quiet";
822823

823824
public Commands(AutoCode plugin)
@@ -941,25 +942,43 @@ private void HandleUse(BasePlayer player, string label, string[] args)
941942
plugin.data.Inst.playerSettings.Add(player.userID, new Data.Structure.PlayerSettings());
942943
}
943944

944-
string operation = args[0].ToLower();
945+
int nextArg = 0;
946+
int argsRemainingCount = args.Length;
947+
948+
string operation = args[nextArg++].ToLower();
949+
argsRemainingCount--;
950+
945951
bool guest = false;
946952

947953
if (operation == Guest)
948954
{
949-
if (args.Length < 2)
955+
if (argsRemainingCount < 1)
950956
{
951957
SyntaxError(player, label, args);
952958
return;
953959
}
954960

955961
guest = true;
956-
operation = args[1].ToLower();
962+
operation = args[nextArg++].ToLower();
963+
argsRemainingCount--;
964+
}
965+
966+
if (operation == SetCode)
967+
{
968+
if (argsRemainingCount < 1)
969+
{
970+
SyntaxError(player, label, args);
971+
return;
972+
}
973+
974+
operation = args[nextArg++].ToLower();
975+
argsRemainingCount--;
957976
}
958977

959978
// Pick code.
960979
if (operation == PickCode)
961980
{
962-
if ((guest && args.Length > 2) || (!guest && args.Length > 1))
981+
if (argsRemainingCount > 0)
963982
{
964983
plugin.Message(
965984
player,
@@ -980,7 +999,7 @@ private void HandleUse(BasePlayer player, string label, string[] args)
980999
SyntaxError(player, label, args);
9811000
return;
9821001
}
983-
if (args.Length > 1)
1002+
if (argsRemainingCount > 0)
9841003
{
9851004
plugin.Message(
9861005
player,
@@ -996,7 +1015,7 @@ private void HandleUse(BasePlayer player, string label, string[] args)
9961015
// Remove?
9971016
if (operation == RemoveCode)
9981017
{
999-
if ((guest && args.Length > 2) || (!guest && args.Length > 1))
1018+
if (argsRemainingCount > 0)
10001019
{
10011020
plugin.Message(
10021021
player,
@@ -1012,7 +1031,7 @@ private void HandleUse(BasePlayer player, string label, string[] args)
10121031
// Use random code?
10131032
if (operation == RandomCode)
10141033
{
1015-
if ((guest && args.Length > 2) || (!guest && args.Length > 1))
1034+
if (argsRemainingCount > 0)
10161035
{
10171036
plugin.Message(
10181037
player,
@@ -1035,7 +1054,7 @@ private void HandleUse(BasePlayer player, string label, string[] args)
10351054
// Use given code?
10361055
if (plugin.IsValidCode(operation))
10371056
{
1038-
if ((guest && args.Length > 2) || (!guest && args.Length > 1))
1057+
if (argsRemainingCount > 0)
10391058
{
10401059
plugin.Message(
10411060
player,
@@ -1121,13 +1140,22 @@ public string GetHelp(BasePlayer player, string label)
11211140
private string GetUsage(string label)
11221141
{
11231142
return string.Format(
1124-
"/{0} <{1}>",
1143+
"{0} <{1}>",
11251144
label,
11261145
string.Join("|", new string[] {
11271146
string.Format(
11281147
"[{0}] <{1}>",
11291148
Guest,
1130-
string.Join("|", new string[] { "1234", PickCode, RandomCode, RemoveCode })
1149+
string.Join("|", new string[] {
1150+
string.Format(
1151+
"[{0}] {1}",
1152+
SetCode,
1153+
"1234"
1154+
),
1155+
PickCode,
1156+
RandomCode,
1157+
RemoveCode
1158+
})
11311159
),
11321160
QuietMode
11331161
})

0 commit comments

Comments
 (0)