@ -52,7 +52,6 @@
|
||||
|
||||
package org.prismlauncher;
|
||||
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.launcher.LauncherFactory;
|
||||
@ -65,37 +64,37 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public final class EntryPoint {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("EntryPoint");
|
||||
|
||||
|
||||
private final Parameters params = new Parameters();
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
EntryPoint listener = new EntryPoint();
|
||||
|
||||
|
||||
ExitCode exitCode = listener.listen();
|
||||
|
||||
|
||||
if (exitCode != ExitCode.NORMAL) {
|
||||
LOGGER.warning("Exiting with " + exitCode);
|
||||
|
||||
|
||||
System.exit(exitCode.numericalCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static PreLaunchAction parseLine(String inData, Parameters params) throws ParseException {
|
||||
if (inData.isEmpty())
|
||||
throw new ParseException("Unexpected empty string!");
|
||||
|
||||
|
||||
String first = inData;
|
||||
String second = null;
|
||||
int splitPoint = inData.indexOf(' ');
|
||||
|
||||
|
||||
if (splitPoint != -1) {
|
||||
first = first.substring(0, splitPoint);
|
||||
second = inData.substring(splitPoint + 1);
|
||||
}
|
||||
|
||||
|
||||
switch (first) {
|
||||
case "launch":
|
||||
return PreLaunchAction.LAUNCH;
|
||||
@ -104,22 +103,22 @@ public final class EntryPoint {
|
||||
default:
|
||||
if (second == null || second.isEmpty())
|
||||
throw new ParseException("Error while parsing:" + inData);
|
||||
|
||||
|
||||
params.add(first, second);
|
||||
|
||||
|
||||
return PreLaunchAction.PROCEED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ExitCode listen() {
|
||||
PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED;
|
||||
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
System.in,
|
||||
StandardCharsets.UTF_8
|
||||
))) {
|
||||
String line;
|
||||
|
||||
|
||||
while (preLaunchAction == PreLaunchAction.PROCEED) {
|
||||
if ((line = reader.readLine()) != null) {
|
||||
preLaunchAction = parseLine(line, this.params);
|
||||
@ -129,50 +128,49 @@ public final class EntryPoint {
|
||||
}
|
||||
} catch (IOException | ParseException e) {
|
||||
LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e);
|
||||
|
||||
|
||||
return ExitCode.ERROR;
|
||||
}
|
||||
|
||||
|
||||
// Main loop
|
||||
if (preLaunchAction == PreLaunchAction.ABORT) {
|
||||
LOGGER.info("Launch aborted by the launcher.");
|
||||
|
||||
|
||||
return ExitCode.ERROR;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Launcher launcher = LauncherFactory.createLauncher(params);
|
||||
|
||||
|
||||
launcher.launch();
|
||||
|
||||
|
||||
return ExitCode.NORMAL;
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.log(Level.SEVERE, "Wrong argument.", e);
|
||||
|
||||
|
||||
return ExitCode.ERROR;
|
||||
} catch (Throwable e) {
|
||||
LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
|
||||
|
||||
|
||||
return ExitCode.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum PreLaunchAction {
|
||||
PROCEED,
|
||||
LAUNCH,
|
||||
ABORT
|
||||
}
|
||||
|
||||
|
||||
|
||||
private enum ExitCode {
|
||||
NORMAL(0),
|
||||
ERROR(1);
|
||||
|
||||
|
||||
private final int numericalCode;
|
||||
|
||||
|
||||
ExitCode(int numericalCode) {
|
||||
this.numericalCode = numericalCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
package org.prismlauncher.launcher;
|
||||
|
||||
|
||||
public interface Launcher {
|
||||
|
||||
void launch() throws Throwable;
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,6 @@
|
||||
|
||||
package org.prismlauncher.launcher;
|
||||
|
||||
|
||||
import org.prismlauncher.launcher.impl.LegacyLauncher;
|
||||
import org.prismlauncher.launcher.impl.StandardLauncher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
@ -43,10 +42,10 @@ import org.prismlauncher.utils.Parameters;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public final class LauncherFactory {
|
||||
|
||||
private static final Map<String, LauncherProvider> launcherRegistry = new HashMap<>();
|
||||
|
||||
|
||||
static {
|
||||
launcherRegistry.put("standard", new LauncherProvider() {
|
||||
@Override
|
||||
@ -63,15 +62,15 @@ public final class LauncherFactory {
|
||||
}
|
||||
private LauncherFactory() {
|
||||
}
|
||||
|
||||
|
||||
public static Launcher createLauncher(Parameters parameters) {
|
||||
String name = parameters.getString("launcher");
|
||||
|
||||
|
||||
LauncherProvider launcherProvider = launcherRegistry.get(name);
|
||||
|
||||
|
||||
if (launcherProvider == null)
|
||||
throw new IllegalArgumentException("Invalid launcher type: " + name);
|
||||
|
||||
|
||||
return launcherProvider.provide(parameters);
|
||||
}
|
||||
}
|
||||
|
@ -35,10 +35,10 @@
|
||||
|
||||
package org.prismlauncher.launcher;
|
||||
|
||||
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
|
||||
|
||||
public interface LauncherProvider {
|
||||
|
||||
Launcher provide(Parameters parameters);
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl;
|
||||
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
@ -26,9 +25,8 @@ import java.lang.invoke.MethodType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public abstract class AbstractLauncher implements Launcher {
|
||||
|
||||
|
||||
private static final int DEFAULT_WINDOW_WIDTH = 854;
|
||||
private static final int DEFAULT_WINDOW_HEIGHT = 480;
|
||||
|
||||
@ -44,21 +42,21 @@ public abstract class AbstractLauncher implements Launcher {
|
||||
protected final String serverAddress, serverPort;
|
||||
|
||||
protected final ClassLoader classLoader;
|
||||
|
||||
|
||||
protected AbstractLauncher(Parameters params) {
|
||||
classLoader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
|
||||
mcParams = params.getList("param", new ArrayList<String>());
|
||||
mainClass = params.getString("mainClass", "net.minecraft.client.Minecraft");
|
||||
|
||||
|
||||
serverAddress = params.getString("serverAddress", null);
|
||||
serverPort = params.getString("serverPort", null);
|
||||
|
||||
|
||||
String windowParams = params.getString("windowParams", null);
|
||||
|
||||
|
||||
if ("max".equals(windowParams) || windowParams == null) {
|
||||
maximize = windowParams != null;
|
||||
|
||||
|
||||
width = DEFAULT_WINDOW_WIDTH;
|
||||
height = DEFAULT_WINDOW_HEIGHT;
|
||||
} else {
|
||||
@ -82,7 +80,7 @@ public abstract class AbstractLauncher implements Launcher {
|
||||
protected Class<?> loadMain() throws ClassNotFoundException {
|
||||
return classLoader.loadClass(mainClass);
|
||||
}
|
||||
|
||||
|
||||
protected void loadAndInvokeMain() throws Throwable {
|
||||
invokeMain(loadMain());
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl;
|
||||
|
||||
|
||||
import org.prismlauncher.applet.LegacyFrame;
|
||||
import org.prismlauncher.utils.LegacyUtils;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
@ -45,15 +44,15 @@ public final class LegacyLauncher extends AbstractLauncher {
|
||||
|
||||
public LegacyLauncher(Parameters params) {
|
||||
super(params);
|
||||
|
||||
|
||||
user = params.getString("userName");
|
||||
session = params.getString("sessionId");
|
||||
title = params.getString("windowTitle", "Minecraft");
|
||||
appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet");
|
||||
|
||||
|
||||
List<String> traits = params.getList("traits", Collections.<String>emptyList());
|
||||
noApplet = traits.contains("noapplet");
|
||||
|
||||
|
||||
cwd = System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
|
@ -16,17 +16,15 @@
|
||||
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
|
||||
public final class LegacyUtils {
|
||||
|
||||
|
||||
private LegacyUtils() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds a field that looks like a Minecraft base folder in a supplied class
|
||||
*
|
||||
@ -39,16 +37,16 @@ public final class LegacyUtils {
|
||||
// Has to be File
|
||||
if (field.getType() != File.class)
|
||||
continue;
|
||||
|
||||
|
||||
// And Private Static.
|
||||
if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers()))
|
||||
continue;
|
||||
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user