@@ -13,7 +13,7 @@ public sealed class BasicAdmin : BasePlugin, IPluginConfig<BasicAdminConfig>
1313{
1414 public override string ModuleName => "BasicAdmin" ;
1515 public override string ModuleAuthor => "livevilog" ;
16- public override string ModuleVersion => "1.0 .0" ;
16+ public override string ModuleVersion => "1.2 .0" ;
1717
1818 public BasicAdminConfig Config { get ; set ; } = new ( ) ;
1919
@@ -74,11 +74,8 @@ public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo info)
7474 [ RequiresPermissions ( "@css/kick" ) ]
7575 public void OnKickCommand ( CCSPlayerController ? caller , CommandInfo info )
7676 {
77- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
78- {
79- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
77+ if ( ! GetTarget ( info , out var player ) )
8078 return ;
81- }
8279
8380 var reason = info . GetArg ( 2 ) ;
8481
@@ -87,17 +84,14 @@ public void OnKickCommand(CCSPlayerController? caller, CommandInfo info)
8784 if ( ! Config . HideActivity )
8885 Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } kicked { player . PlayerName } .") ) ;
8986 }
90-
87+
9188 [ ConsoleCommand ( "css_slay" , "Slay a player." ) ]
9289 [ CommandHelper ( 1 , "<#userid or name>" ) ]
9390 [ RequiresPermissions ( "@css/slay" ) ]
9491 public void OnSlayCommand ( CCSPlayerController ? caller , CommandInfo info )
9592 {
96- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
97- {
98- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
93+ if ( ! GetTarget ( info , out var player ) )
9994 return ;
100- }
10195
10296 player ! . Pawn . Value . CommitSuicide ( false , true ) ;
10397
@@ -110,28 +104,25 @@ public void OnSlayCommand(CCSPlayerController? caller, CommandInfo info)
110104 [ RequiresPermissions ( "@css/cvar" ) ]
111105 public void OnGiveCommand ( CCSPlayerController ? caller , CommandInfo info )
112106 {
113- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
114- {
115- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
107+ if ( ! GetTarget ( info , out var player ) )
116108 return ;
117- }
109+
110+ var range = info . GetArg ( 0 ) . Length + info . GetArg ( 1 ) . Length + 2 ;
111+ var item = info . GetCommandString [ range ..] ;
118112
119- player ! . GiveNamedItem ( info . GetArg ( 2 ) ) ;
113+ player ! . GiveNamedItem ( item ) ;
120114
121115 if ( ! Config . HideActivity )
122- Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } gave { player . PlayerName } { ChatColors . Lime } { info . GetArg ( 2 ) } { ChatColors . Default } .") ) ;
116+ Server . PrintToChatAll ( FormatAdminMessage ( $ "{ caller ! . PlayerName } gave { player . PlayerName } { ChatColors . Lime } { item } { ChatColors . Default } .") ) ;
123117 }
124118
125119 [ ConsoleCommand ( "css_swap" , "Swap a player." ) ]
126120 [ CommandHelper ( 1 , "<#userid or name>" ) ]
127121 [ RequiresPermissions ( "@css/kick" ) ]
128122 public void OnSwapCommand ( CCSPlayerController ? caller , CommandInfo info )
129123 {
130- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
131- {
132- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
124+ if ( ! GetTarget ( info , out var player ) )
133125 return ;
134- }
135126
136127 if ( ( int ) CsTeam . Spectator == player ! . TeamNum )
137128 {
@@ -152,11 +143,8 @@ public void OnSwapCommand(CCSPlayerController? caller, CommandInfo info)
152143 [ RequiresPermissions ( "@css/kick" ) ]
153144 public void OnSpecCommand ( CCSPlayerController ? caller , CommandInfo info )
154145 {
155- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
156- {
157- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
146+ if ( ! GetTarget ( info , out var player ) )
158147 return ;
159- }
160148
161149 player ! . ChangeTeam ( CsTeam . Spectator ) ;
162150
@@ -194,13 +182,10 @@ public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo info)
194182 [ RequiresPermissions ( "@css/chat" ) ]
195183 public void OnAdminPrivateSayCommand ( CCSPlayerController ? caller , CommandInfo info )
196184 {
197- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
198- {
199- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
185+ if ( ! GetTarget ( info , out var player ) )
200186 return ;
201- }
202187
203- var range = info . GetArg ( 1 ) . Length + info . GetArg ( 2 ) . Length + 3 ;
188+ var range = info . GetArg ( 0 ) . Length + info . GetArg ( 1 ) . Length + 2 ;
204189 var message = info . GetCommandString [ range ..] ;
205190
206191 info . ReplyToCommand ( FormatAdminMessage ( $ "({ player ! . PlayerName } ) { message } ") ) ;
@@ -260,13 +245,10 @@ public void OnRestartGameCommand(CCSPlayerController? caller, CommandInfo info)
260245 [ RequiresPermissions ( "@css/ban" ) ]
261246 public void OnBuryCommand ( CCSPlayerController ? caller , CommandInfo info )
262247 {
263- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) || player ! . Pawn . Value . LifeState != ( int ) LifeState_t . LIFE_ALIVE )
264- {
265- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
248+ if ( ! GetTarget ( info , out var player ) )
266249 return ;
267- }
268250
269- var newPos = new Vector ( player . Pawn . Value . AbsOrigin ! . X , player . Pawn . Value . AbsOrigin . Y ,
251+ var newPos = new Vector ( player ! . Pawn . Value . AbsOrigin ! . X , player . Pawn . Value . AbsOrigin . Y ,
270252 player . Pawn . Value . AbsOrigin . Z - 10f ) ;
271253
272254 player . Pawn . Value . Teleport ( newPos , player . AbsRotation ! , player . AbsVelocity ) ;
@@ -280,11 +262,8 @@ public void OnBuryCommand(CCSPlayerController? caller, CommandInfo info)
280262 [ RequiresPermissions ( "@css/ban" ) ]
281263 public void OnUnburyCommand ( CCSPlayerController ? caller , CommandInfo info )
282264 {
283- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
284- {
285- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found or is not buried.") ) ;
265+ if ( ! GetTarget ( info , out var player ) )
286266 return ;
287- }
288267
289268 var newPos = new Vector ( player ! . Pawn . Value . AbsOrigin ! . X , player . Pawn . Value . AbsOrigin . Y ,
290269 player . Pawn . Value . AbsOrigin ! . Z + 15f ) ;
@@ -300,11 +279,8 @@ public void OnUnburyCommand(CCSPlayerController? caller, CommandInfo info)
300279 [ RequiresPermissions ( "@css/ban" ) ]
301280 public void OnDisarmCommand ( CCSPlayerController ? caller , CommandInfo info )
302281 {
303- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) )
304- {
305- info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
282+ if ( ! GetTarget ( info , out var player ) )
306283 return ;
307- }
308284
309285 player ! . RemoveWeapons ( ) ;
310286
@@ -317,7 +293,7 @@ public void OnDisarmCommand(CCSPlayerController? caller, CommandInfo info)
317293 [ RequiresPermissions ( "@css/slay" ) ]
318294 public void OnHealthCommand ( CCSPlayerController ? caller , CommandInfo info )
319295 {
320- if ( ! ServerUtils . GetTarget ( info . GetArg ( 1 ) , out var player ) || ! int . TryParse ( info . GetArg ( 2 ) , out var health ) )
296+ if ( ! GetTarget ( info , out var player ) || ! int . TryParse ( info . GetArg ( 2 ) , out var health ) )
321297 {
322298 info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found or is not buried.") ) ;
323299 return ;
@@ -366,6 +342,23 @@ public void OnCvarCommand(CCSPlayerController? caller, CommandInfo info)
366342 //
367343 // player!.PlayerPawn.Value.LifeState = (int) LifeState_t.LIFE_ALIVE;;
368344 // }
345+
346+ private static bool GetTarget ( CommandInfo info , out CCSPlayerController ? player )
347+ {
348+ var matches = ServerUtils . GetTarget ( info . GetArg ( 1 ) , out player ) ;
349+
350+ switch ( matches )
351+ {
352+ case TargetResult . None :
353+ info . ReplyToCommand ( FormatMessage ( $ "Target { info . GetArg ( 1 ) } not found.") ) ;
354+ return false ;
355+ case TargetResult . Multiple :
356+ info . ReplyToCommand ( FormatMessage ( $ "Multiple targets found for \" { info . GetArg ( 1 ) } \" .") ) ;
357+ return false ;
358+ }
359+
360+ return true ;
361+ }
369362
370363 private static string FormatMessage ( string message ) => $ " { ChatColors . Lime } [BasicAdmin]{ ChatColors . Default } { message } ";
371364 private string FormatAdminMessage ( string message ) => $ " { Config . AdminTag } { message } ";
0 commit comments