Use only Java 7 features (in order to deal with #515)

This commit is contained in:
icelimetea 2022-05-03 00:25:26 +01:00
parent 8de63b60b1
commit eeb5297284
4 changed files with 39 additions and 20 deletions

View File

@ -5,30 +5,39 @@ 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 final Map<String, LauncherProvider> launcherRegistry = new HashMap<>();
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) {
Function<ParamBucket, Launcher> launcherCreator =
launcherRegistry.get(name);
LauncherProvider launcherProvider = launcherRegistry.get(name);
if (launcherCreator == null)
if (launcherProvider == null)
throw new IllegalArgumentException("Invalid launcher type: " + name);
return launcherCreator.apply(parameters);
return launcherProvider.provide(parameters);
}
public static LauncherFactory getInstance() {
return INSTANCE;
}
public interface LauncherProvider {
Launcher provide(ParamBucket parameters);
}
}

View File

@ -141,16 +141,19 @@ public final class LegacyFrame extends Frame {
@Override
public void windowClosing(WindowEvent e) {
new Thread(() -> {
try {
Thread.sleep(30000L);
} catch (InterruptedException localInterruptedException) {
localInterruptedException.printStackTrace();
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(30000L);
} catch (InterruptedException localInterruptedException) {
localInterruptedException.printStackTrace();
}
LOGGER.info("Forcing exit!");
System.exit(0);
}
LOGGER.info("Forcing exit!");
System.exit(0);
}).start();
if (appletWrap != null) {

View File

@ -58,10 +58,10 @@ public final class OneSixLauncher implements Launcher {
public OneSixLauncher(ParamBucket params) {
classLoader = ClassLoader.getSystemClassLoader();
mcParams = params.allSafe("param", Collections.emptyList());
mcParams = params.allSafe("param", Collections.<String>emptyList());
mainClass = params.firstSafe("mainClass", "net.minecraft.client.Minecraft");
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");
sessionId = params.first("sessionId");

View File

@ -28,8 +28,15 @@ public final class ParamBucket {
private final Map<String, List<String>> paramsMap = new HashMap<>();
public void add(String key, String value) {
paramsMap.computeIfAbsent(key, k -> new ArrayList<>())
.add(value);
List<String> params = paramsMap.get(key);
if (params == null) {
params = new ArrayList<>();
paramsMap.put(key, params);
}
params.add(value);
}
public List<String> all(String key) throws ParameterNotFoundException {