Refactor some parts of NewLaunch (part 2)
This commit is contained in:
34
libraries/launcher/org/multimc/LauncherFactory.java
Normal file
34
libraries/launcher/org/multimc/LauncherFactory.java
Normal file
@ -0,0 +1,34 @@
|
||||
package org.multimc;
|
||||
|
||||
import org.multimc.impl.OneSixLauncher;
|
||||
import org.multimc.utils.ParamBucket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class LauncherFactory {
|
||||
|
||||
private static final LauncherFactory INSTANCE = new LauncherFactory();
|
||||
|
||||
private final Map<String, Function<ParamBucket, Launcher>> launcherRegistry = new HashMap<>();
|
||||
|
||||
private LauncherFactory() {
|
||||
launcherRegistry.put("onesix", OneSixLauncher::new);
|
||||
}
|
||||
|
||||
public Launcher createLauncher(String name, ParamBucket parameters) {
|
||||
Function<ParamBucket, Launcher> launcherCreator =
|
||||
launcherRegistry.get(name);
|
||||
|
||||
if (launcherCreator == null)
|
||||
throw new IllegalArgumentException("Invalid launcher type: " + name);
|
||||
|
||||
return launcherCreator.apply(parameters);
|
||||
}
|
||||
|
||||
public static LauncherFactory getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user