Use only Java 7 features (in order to deal with #515)
This commit is contained in:
parent
8de63b60b1
commit
eeb5297284
@ -5,30 +5,39 @@ import org.multimc.utils.ParamBucket;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public final class LauncherFactory {
|
public final class LauncherFactory {
|
||||||
|
|
||||||
private static final LauncherFactory INSTANCE = new LauncherFactory();
|
private static final LauncherFactory INSTANCE = new LauncherFactory();
|
||||||
|
|
||||||
private final Map<String, Function<ParamBucket, Launcher>> launcherRegistry = new HashMap<>();
|
private final Map<String, LauncherProvider> launcherRegistry = new HashMap<>();
|
||||||
|
|
||||||
private LauncherFactory() {
|
private LauncherFactory() {
|
||||||
launcherRegistry.put("onesix", OneSixLauncher::new);
|
launcherRegistry.put("onesix", new LauncherProvider() {
|
||||||
|
@Override
|
||||||
|
public Launcher provide(ParamBucket parameters) {
|
||||||
|
return new OneSixLauncher(parameters);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Launcher createLauncher(String name, ParamBucket parameters) {
|
public Launcher createLauncher(String name, ParamBucket parameters) {
|
||||||
Function<ParamBucket, Launcher> launcherCreator =
|
LauncherProvider launcherProvider = launcherRegistry.get(name);
|
||||||
launcherRegistry.get(name);
|
|
||||||
|
|
||||||
if (launcherCreator == null)
|
if (launcherProvider == null)
|
||||||
throw new IllegalArgumentException("Invalid launcher type: " + name);
|
throw new IllegalArgumentException("Invalid launcher type: " + name);
|
||||||
|
|
||||||
return launcherCreator.apply(parameters);
|
return launcherProvider.provide(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LauncherFactory getInstance() {
|
public static LauncherFactory getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface LauncherProvider {
|
||||||
|
|
||||||
|
Launcher provide(ParamBucket parameters);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,9 @@ public final class LegacyFrame extends Frame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
new Thread(() -> {
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30000L);
|
Thread.sleep(30000L);
|
||||||
} catch (InterruptedException localInterruptedException) {
|
} catch (InterruptedException localInterruptedException) {
|
||||||
@ -151,6 +153,7 @@ public final class LegacyFrame extends Frame {
|
|||||||
LOGGER.info("Forcing exit!");
|
LOGGER.info("Forcing exit!");
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
if (appletWrap != null) {
|
if (appletWrap != null) {
|
||||||
|
@ -58,10 +58,10 @@ public final class OneSixLauncher implements Launcher {
|
|||||||
public OneSixLauncher(ParamBucket params) {
|
public OneSixLauncher(ParamBucket params) {
|
||||||
classLoader = ClassLoader.getSystemClassLoader();
|
classLoader = ClassLoader.getSystemClassLoader();
|
||||||
|
|
||||||
mcParams = params.allSafe("param", Collections.emptyList());
|
mcParams = params.allSafe("param", Collections.<String>emptyList());
|
||||||
mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft");
|
mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft");
|
||||||
appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet");
|
appletClass = params.firstSafe("appletClass", "net.minecraft.client.MinecraftApplet");
|
||||||
traits = params.allSafe("traits", Collections.emptyList());
|
traits = params.allSafe("traits", Collections.<String>emptyList());
|
||||||
|
|
||||||
userName = params.first("userName");
|
userName = params.first("userName");
|
||||||
sessionId = params.first("sessionId");
|
sessionId = params.first("sessionId");
|
||||||
|
@ -28,8 +28,15 @@ public final class ParamBucket {
|
|||||||
private final Map<String, List<String>> paramsMap = new HashMap<>();
|
private final Map<String, List<String>> paramsMap = new HashMap<>();
|
||||||
|
|
||||||
public void add(String key, String value) {
|
public void add(String key, String value) {
|
||||||
paramsMap.computeIfAbsent(key, k -> new ArrayList<>())
|
List<String> params = paramsMap.get(key);
|
||||||
.add(value);
|
|
||||||
|
if (params == null) {
|
||||||
|
params = new ArrayList<>();
|
||||||
|
|
||||||
|
paramsMap.put(key, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
params.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> all(String key) throws ParameterNotFoundException {
|
public List<String> all(String key) throws ParameterNotFoundException {
|
||||||
|
Loading…
Reference in New Issue
Block a user