@@ -17,7 +17,9 @@ class InfectCommand : ICommandHandler
17
17
18
18
public InfectCommand ( SCP008 plugin ) => this . plugin = plugin ;
19
19
public string GetCommandDescription ( ) => "Infects / removes infection" ;
20
- public string GetUsage ( ) => "INFECT (PLAYER)" ;
20
+ public string GetUsage ( ) => "INFECT (PLAYER) [SUBCOMMAND]" ;
21
+
22
+ public string [ ] SubCommands = new string [ ] { "+ / add" , "infect+ / ++ / zero / patientzero" , "cure / remove / -" } ;
21
23
22
24
bool IsAllowed ( ICommandSender sender )
23
25
{
@@ -52,63 +54,92 @@ public string[] OnCall(ICommandSender sender, string[] args)
52
54
{
53
55
if ( IsAllowed ( sender ) )
54
56
{
55
- if ( args . Length == 0 && sender is Player p )
56
- if ( SCP008 . playersToDamage . Contains ( p . UserId ) )
57
+ if ( args . Length == 0 && sender is Player p && p != null )
58
+ try
57
59
{
58
- SCP008 . playersToDamage . Remove ( p . UserId ) ;
59
- return new string [ ] { "Cured infected " + p . Name } ;
60
+ if ( SCP008 . infected . Contains ( p . UserID ) )
61
+ {
62
+ Utility . CureInfection ( p , true ) ;
63
+ return new string [ ] { "Cured infected " + p . Name } ;
64
+ }
65
+ else
66
+ {
67
+ Utility . Infect ( p ) ;
68
+ return new string [ ] { "Infected " + p . Name } ;
69
+ }
60
70
}
61
- else
71
+ catch ( Exception e )
62
72
{
63
- SCP008 . playersToDamage . Add ( p . UserId ) ;
64
- return new string [ ] { "Infected " + p . Name } ;
73
+ return new string [ ] { "Infect command exception " + e } ;
65
74
}
66
75
else if ( args . Length > 0 )
67
76
{
68
- if ( args [ 0 ] . ToLower ( ) == "all" || args [ 0 ] == "*" )
77
+ string arg1 = ( args . Length > 1 && ! string . IsNullOrEmpty ( args [ 1 ] ) ) ? args [ 1 ] . ToLower ( ) : "" ;
78
+ List < Player > players = new List < Player > ( ) ;
79
+ switch ( args [ 0 ] . ToLower ( ) )
69
80
{
70
- int x = 0 ;
71
- foreach ( Player pl in Server . GetPlayers ( )
72
- . Where ( ply =>
73
- ply . TeamRole . Role != Smod2 . API . RoleType . SPECTATOR &&
74
- ply . TeamRole . Role != Smod2 . API . RoleType . UNASSIGNED &&
75
- ply . TeamRole . Role != Smod2 . API . RoleType . ZOMBIE ) )
76
- {
77
- string arg = ( args . Length > 1 && ! string . IsNullOrEmpty ( args [ 1 ] ) ) ? args [ 1 ] . ToLower ( ) : "" ;
78
- if ( SCP008 . playersToDamage . Contains ( pl . UserId ) && arg != "infect" )
79
- SCP008 . playersToDamage . Remove ( pl . UserId ) ;
80
- else if ( ! SCP008 . playersToDamage . Contains ( pl . UserId ) && arg != "infect" )
81
- SCP008 . playersToDamage . Add ( pl . UserId ) ;
82
- x ++ ;
83
- }
84
- return new string [ ] { "Toggled infection on " + x + " players!" } ;
81
+ case "all" :
82
+ case "*" :
83
+ players = Server . GetPlayers ( i => i . PlayerRole . Team != TeamType . SPECTATOR || i . PlayerRole . Team != TeamType . NONE ) ;
84
+ break ;
85
+ case "list" :
86
+ case "infected" :
87
+ return new string [ ] { "Infected Players:" , string . Join ( "\n " , SCP008 . InfectedPlayers . OrderBy ( s => s . Name ) . Select ( i => i . Name ) . ToList ( ) ) } ;
88
+ case "help" :
89
+ case "subcommand" :
90
+ case "subcommands" :
91
+ return new string [ ] { GetUsage ( ) , "Availabile subcommands:" + string . Join ( " ," , SubCommands ) } ;
92
+ default :
93
+ players = Server . GetPlayers ( args [ 0 ] ) ;
94
+ break ;
85
95
}
86
- else
87
- {
88
- List < Player > players = Server . GetPlayers ( args [ 0 ] ) ;
89
- Player player ;
90
- if ( players == null || players . Count == 0 ) return new string [ ] { "No players on the server called " + args [ 0 ] } ;
91
- player = players . OrderBy ( pl => pl . Name . Length ) . First ( ) ;
92
96
93
- if ( ! SCP008 . playersToDamage . Contains ( player . UserId ) )
94
- {
95
- SCP008 . playersToDamage . Add ( player . UserId ) ;
96
- return new string [ ] { "Infected " + player . Name } ;
97
- }
98
- else if ( SCP008 . playersToDamage . Contains ( player . UserId ) )
97
+ if ( players == null || players . Count == 0 )
98
+ return new string [ ] { "No players on the server called " + args [ 0 ] } ;
99
+
100
+ string ret = this . plugin . Details . id + " INFECT COMMAND ERROR" ;
101
+
102
+ foreach ( Player player in players )
103
+ switch ( arg1 . ToLower ( ) )
99
104
{
100
- SCP008 . playersToDamage . Remove ( player . UserId ) ;
101
- return new string [ ] { "Cured infected " + player . Name } ;
105
+ case "+" :
106
+ case "add" :
107
+ Utility . Infect ( player ) ;
108
+ break ;
109
+ case "++" :
110
+ case "add+" :
111
+ case "zero" :
112
+ case "patientzero" :
113
+ Utility . Infect ( player , true ) ;
114
+ return new string [ ] { $ "Made \" { player . Name } \" into Patient Zero!" } ;
115
+ case "cure" :
116
+ case "remove" :
117
+ case "-" :
118
+ SCP008 . patientZero = "" ;
119
+ Utility . CureInfection ( player ) ;
120
+ if ( players . Count == 1 )
121
+ return new string [ ] { $ "Cured \" { player . Name } \" from SCP008 infection!" } ;
122
+ ret = $ "Cured { players . Count } players from SCP008 infection!";
123
+ break ;
124
+ case "" :
125
+ default :
126
+ if ( SCP008 . infected . Contains ( player . UserID ) )
127
+ Utility . CureInfection ( player ) ;
128
+ else
129
+ Utility . Infect ( player ) ;
130
+ break ;
102
131
}
103
- else
104
- return new string [ ] { this . plugin . Details . id + " INFECT ERROR" } ;
105
- }
132
+ if ( ! string . IsNullOrEmpty ( arg1 ) )
133
+ return new string [ ] { $ "Used { arg1 } on { players . Count } players!" } ;
134
+ else
135
+ return new string [ ] { $ "Toggled infection on { players . Count } players!" } ;
106
136
}
107
137
else
108
- return new string [ ] { GetUsage ( ) } ;
138
+ return new [ ] { GetUsage ( ) } ;
109
139
}
110
140
else
111
141
return new string [ ] { "You dont have the required permission to run " + GetUsage ( ) } ;
112
142
}
113
143
}
114
144
}
145
+
0 commit comments