1111import java .util .concurrent .ExecutorService ;
1212import java .util .concurrent .Executors ;
1313import java .util .concurrent .atomic .AtomicInteger ;
14- import java .util .stream .Collectors ;
15- import java .util .stream .Stream ;
1614
1715import org .mcphackers .mcp .plugin .MCPPlugin ;
1816import org .mcphackers .mcp .plugin .MCPPlugin .MCPEvent ;
1917import org .mcphackers .mcp .plugin .MCPPlugin .TaskEvent ;
2018import org .mcphackers .mcp .tasks .Task ;
2119import org .mcphackers .mcp .tasks .Task .Side ;
2220import org .mcphackers .mcp .tools .ClassUtils ;
21+ import org .mcphackers .mcp .tools .FileUtil ;
22+ import org .mcphackers .mcp .tools .Util ;
2323import org .mcphackers .mcp .tools .VersionsParser ;
2424
2525public abstract class MCP {
@@ -28,8 +28,13 @@ public abstract class MCP {
2828 private static final Map <String , MCPPlugin > plugins = new HashMap <>();
2929
3030 static {
31+ Update .attemptToDeleteUpdateJar ();
3132 loadPlugins ();
3233 }
34+
35+ protected MCP () {
36+ triggerEvent (MCPEvent .ENV_STARTUP );
37+ }
3338
3439 public void performTask (TaskMode mode , Side side ) {
3540 performTask (mode , side , true , true );
@@ -141,12 +146,61 @@ public void setProgress(int barIndex, String progressMessage, int progress) {
141146 setProgress (barIndex , progress );
142147 setProgress (barIndex , progressMessage );
143148 }
149+
150+ public void setParameter (TaskParameter param , Object value ) throws IllegalArgumentException {
151+ getOptions ().setParameter (param , value );
152+ }
153+
154+ public void safeSetParameter (TaskParameter param , String value ) {
155+ if (value != null ) {
156+ if (param .type == Integer .class ) {
157+ try {
158+ int valueInt = Integer .parseInt (value );
159+ setParameter (param , valueInt );
160+ return ;
161+ }
162+ catch (NumberFormatException ignored ) {}
163+ catch (IllegalArgumentException e ) {}
164+ }
165+ else if (param .type == Boolean .class ) {
166+ if (value .equalsIgnoreCase ("true" ) || value .equalsIgnoreCase ("false" )) {
167+ try {
168+ boolean valueBoolean = Boolean .parseBoolean (value );
169+ setParameter (param , valueBoolean );
170+ return ;
171+ }
172+ catch (IllegalArgumentException e ) {}
173+ }
174+ }
175+ else if (param .type == String [].class ) {
176+ try {
177+ String [] values = value .split ("," );
178+ for (int i2 = 0 ; i2 < values .length ; i2 ++) {
179+ values [i2 ] = Util .convertFromEscapedString (values [i2 ]).trim ();
180+ }
181+ setParameter (param , values );
182+ return ;
183+ }
184+ catch (IllegalArgumentException e ) {}
185+ }
186+ else if (param .type == String .class ) {
187+ try {
188+ value = Util .convertFromEscapedString (value );
189+ setParameter (param , value );
190+ return ;
191+ }
192+ catch (IllegalArgumentException e ) {}
193+ }
194+ showMessage (param .desc , "Invalid value!" , Task .ERROR );
195+ }
196+ }
144197
145198 private final static void loadPlugins () {
146- if (Files .exists (Paths .get ("plugins" ))) {
199+ Path pluginsDir = Paths .get ("plugins" );
200+ if (Files .exists (pluginsDir )) {
147201 List <Path > jars = new ArrayList <>();
148- try ( Stream < Path > stream = Files . list ( Paths . get ( "plugins" )). filter ( library -> ! library . endsWith ( ".jar" )). filter ( library -> ! Files . isDirectory ( library ))) {
149- jars . addAll ( stream . collect ( Collectors . toList ()) );
202+ try {
203+ FileUtil . collectJars ( pluginsDir , jars );
150204 } catch (IOException e ) {
151205 e .printStackTrace ();
152206 }
0 commit comments