1+ using SER . Code . ArgumentSystem . Arguments ;
2+ using SER . Code . ArgumentSystem . BaseArguments ;
3+ using SER . Code . Helpers . Exceptions ;
4+ using SER . Code . Helpers . Extensions ;
5+ using SER . Code . MethodSystem . BaseMethods ;
6+ using SER . Code . MethodSystem . MethodDescriptors ;
7+ using SER . Code . TokenSystem . Tokens . ExpressionTokens ;
8+ using SER . Code . ValueSystem ;
9+
10+ namespace SER . Code . MethodSystem . Methods . PlayerVariableMethods ;
11+
12+ [ UsedImplicitly ]
13+ public class ShowMethod : ReturningMethod < TextValue > , ICanError
14+ {
15+ public override string Description => "Formats provided players into a nice text representation." ;
16+
17+ public string [ ] ErrorReasons =>
18+ [
19+ "Provided property returned a value which cannot be displayed using text."
20+ ] ;
21+
22+ public override Argument [ ] ExpectedArguments { get ; } =
23+ [
24+ new PlayersArgument ( "players" ) ,
25+ new EnumArgument < PlayerExpressionToken . PlayerProperty > ( "property" )
26+ {
27+ DefaultValue = new ( PlayerExpressionToken . PlayerProperty . Name , "name" ) ,
28+ Description = "The property which will be displayed."
29+ }
30+ ] ;
31+
32+ public override void Execute ( )
33+ {
34+ var players = Args . GetPlayers ( "players" ) ;
35+ var property = Args . GetEnum < PlayerExpressionToken . PlayerProperty > ( "property" ) ;
36+
37+ if ( ! PlayerExpressionToken . PropertyInfoMap . TryGetValue ( property , out var propInfo ) ||
38+ propInfo is not { ReturnType : var type , Handler : var handler } ||
39+ typeof ( LiteralValue ) . IsAssignableFrom ( type ) )
40+ {
41+ throw new ScriptRuntimeError ( this , ErrorReasons [ 0 ] ) ;
42+ }
43+
44+ ReturnValue = players
45+ . Select ( handler )
46+ . OfType < LiteralValue > ( )
47+ . Select ( lv => lv . StringRep )
48+ . JoinStrings ( ", " ) ;
49+ }
50+ }
0 commit comments