Skip to content

Commit 28d643a

Browse files
add -- invalidRankMessage flag argument to CustomCommand
1 parent 50b2cf8 commit 28d643a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Code/FlagSystem/Flags/CustomCommandFlag.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ public class CustomCommandFlag : Flag
8484
AddNeededRank,
8585
false
8686
),
87+
new(
88+
"invalidRankMessage",
89+
"Defines a message for when the sender does not have the needed rank (defined in 'neededRank' argument).",
90+
AddInvalidRankMessage,
91+
false
92+
),
8793
new(
8894
"cooldown",
8995
"The time the player has to wait before being able to use the command again.",
@@ -192,6 +198,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
192198
public ConsoleType ConsoleTypes { get; set; } = ConsoleType.Server;
193199
public string[] Usage { get; set; } = [];
194200
public string[] NeededRanks { get; set; } = [];
201+
public string? InvalidRankMessage { get; set; } = null;
195202
public TimeSpan PlayerCooldown { get; set; } = TimeSpan.Zero;
196203
public Dictionary<Player, DateTime> NextEligableDateForPlayer { get; } = [];
197204
public string GetHelp(ArraySegment<string> arguments)
@@ -272,11 +279,16 @@ public static Result RunAttachedScript(CustomCommand cmd, ScriptExecutor sender,
272279
{
273280
if (plr.UserGroup is not { } group || cmd.NeededRanks.All(rank => group.Name != rank))
274281
{
282+
if (cmd.InvalidRankMessage is not null)
283+
{
284+
return cmd.InvalidRankMessage;
285+
}
286+
275287
return "This command is reserved for players with a rank: " +
276288
$"{cmd.NeededRanks.Select(r => $"'{r}'").JoinStrings(" or ")}";
277289
}
278290
}
279-
291+
280292
if (cmd.PlayerCooldown <= TimeSpan.Zero)
281293
{
282294
return null;
@@ -336,6 +348,12 @@ private Result AddNeededRank(string[] args)
336348
Command.NeededRanks = args;
337349
return true;
338350
}
351+
352+
private Result AddInvalidRankMessage(string[] args)
353+
{
354+
Command.InvalidRankMessage = args.JoinStrings(" ");
355+
return true;
356+
}
339357

340358
private Result AddCooldown(string[] args)
341359
{

0 commit comments

Comments
 (0)