11using CommandSystem ;
22using JetBrains . Annotations ;
3+ using LabApi . Features . Permissions ;
34using RemoteAdmin ;
45using SER . Code . Helpers . Exceptions ;
56using SER . Code . Helpers . Extensions ;
@@ -73,6 +74,13 @@ public class CustomCommandFlag : Flag
7374 "The description of the command." ,
7475 AddDescription ,
7576 false
77+ ) ,
78+ new (
79+ "neededRank" ,
80+ "The required remote admin rank in order to have access to this command. " +
81+ "You can provide multiple ranks, and if the player has any of the listed ranks, they will be able to use the command." ,
82+ AddNeededRank ,
83+ false
7684 )
7785 ] ;
7886
@@ -160,6 +168,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
160168 public string Description { get ; set ; } = "" ;
161169 public ConsoleType ConsoleTypes { get ; set ; } = ConsoleType . Server ;
162170 public string [ ] Usage { get ; set ; } = [ ] ;
171+ public string [ ] NeededRanks { get ; set ; } = [ ] ;
163172 public string GetHelp ( ArraySegment < string > arguments )
164173 {
165174 return $ "Description: { Description } \n " +
@@ -173,6 +182,15 @@ public string GetHelp(ArraySegment<string> arguments)
173182
174183 public static Result RunAttachedScript ( CustomCommand requestingCommand , ScriptExecutor sender , string [ ] args )
175184 {
185+ if ( requestingCommand . NeededRanks . Any ( ) && sender is IPlayerExecutor { Player : { } player } )
186+ {
187+ if ( player . UserGroup is not { } group || requestingCommand . NeededRanks . All ( rank => group . Name != rank ) )
188+ {
189+ return "This command is reserved for players with a rank: " +
190+ $ "{ requestingCommand . NeededRanks . JoinStrings ( ", " ) } ";
191+ }
192+ }
193+
176194 if ( ! ScriptCommands . TryGetValue ( requestingCommand , out var flag ) )
177195 {
178196 return "The script that was supposed to handle this command was not found." ;
@@ -264,4 +282,10 @@ private Result AddDescription(string[] args)
264282 Command . Description = args . JoinStrings ( " " ) ;
265283 return true ;
266284 }
285+
286+ private Result AddNeededRank ( string [ ] args )
287+ {
288+ Command . NeededRanks = args ;
289+ return true ;
290+ }
267291}
0 commit comments