diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java
index 8928dbbe..77050d90 100644
--- a/libraries/launcher/net/minecraft/Launcher.java
+++ b/libraries/launcher/net/minecraft/Launcher.java
@@ -16,7 +16,6 @@
package net.minecraft;
-
import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.BorderLayout;
@@ -27,40 +26,39 @@ import java.net.URL;
import java.util.Map;
import java.util.TreeMap;
-
/**
* WARNING: This class is reflectively accessed by legacy Forge versions.
*
* Changing field and method declarations without further testing is not recommended.
*/
public final class Launcher extends Applet implements AppletStub {
-
+
private final Map params = new TreeMap<>();
-
+
private Applet wrappedApplet;
-
+
private final URL documentBase;
-
+
private boolean active = false;
-
+
public Launcher(Applet applet) {
this(applet, null);
}
-
+
public Launcher(Applet applet, URL documentBase) {
super();
this.setLayout(new BorderLayout());
-
+
this.add(applet, "Center");
-
+
this.wrappedApplet = applet;
-
+
try {
if (documentBase != null) {
this.documentBase = documentBase;
} else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) {
// Special case only for Classic versions
-
+
// TODO: 2022-10-27 Can this be changed to https
this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/");
} else {
@@ -71,35 +69,35 @@ public final class Launcher extends Applet implements AppletStub {
throw new RuntimeException(e);
}
}
-
+
public void replace(Applet applet) {
this.wrappedApplet = applet;
-
+
applet.setStub(this);
applet.setSize(getWidth(), getHeight());
-
+
this.setLayout(new BorderLayout());
this.add(applet, "Center");
-
+
applet.init();
-
+
active = true;
-
+
applet.start();
-
+
validate();
}
-
+
@Override
public boolean isActive() {
return active;
}
-
+
@Override
public URL getDocumentBase() {
return documentBase;
}
-
+
@Override
public URL getCodeBase() {
try {
@@ -109,79 +107,79 @@ public final class Launcher extends Applet implements AppletStub {
throw new RuntimeException(e);
}
}
-
+
@Override
public String getParameter(String name) {
String param = params.get(name);
-
+
if (param != null)
return param;
-
+
try {
return super.getParameter(name);
} catch (Exception ignored) {
}
-
+
return null;
}
-
+
@Override
public void resize(int width, int height) {
wrappedApplet.resize(width, height);
}
-
+
@Override
public void resize(Dimension d) {
wrappedApplet.resize(d);
}
-
+
@Override
public void init() {
if (wrappedApplet != null)
wrappedApplet.init();
}
-
+
@Override
public void start() {
wrappedApplet.start();
-
+
active = true;
}
-
+
@Override
public void stop() {
wrappedApplet.stop();
-
+
active = false;
}
-
+
@Override
public void destroy() {
wrappedApplet.destroy();
}
-
+
@Override
public void appletResize(int width, int height) {
wrappedApplet.resize(width, height);
}
-
+
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
-
+
wrappedApplet.setVisible(visible);
}
-
+
@Override
public void paint(Graphics paramGraphics) {
}
-
+
@Override
public void update(Graphics paramGraphics) {
}
-
+
public void setParameter(String name, String value) {
params.put(name, value);
}
-
+
}
diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java
index b1464f59..cb68b8fd 100644
--- a/libraries/launcher/org/prismlauncher/EntryPoint.java
+++ b/libraries/launcher/org/prismlauncher/EntryPoint.java
@@ -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;
}
}
-
+
}
diff --git a/libraries/launcher/org/prismlauncher/launcher/Launcher.java b/libraries/launcher/org/prismlauncher/launcher/Launcher.java
index 1cea255c..6f5c17b8 100644
--- a/libraries/launcher/org/prismlauncher/launcher/Launcher.java
+++ b/libraries/launcher/org/prismlauncher/launcher/Launcher.java
@@ -16,7 +16,8 @@
package org.prismlauncher.launcher;
-
public interface Launcher {
+
void launch() throws Throwable;
+
}
diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java
index 6c601171..761a4595 100644
--- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java
+++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java
@@ -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 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);
}
}
diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java
index b6d1caab..9b453c7b 100644
--- a/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java
+++ b/libraries/launcher/org/prismlauncher/launcher/LauncherProvider.java
@@ -35,10 +35,10 @@
package org.prismlauncher.launcher;
-
import org.prismlauncher.utils.Parameters;
-
public interface LauncherProvider {
+
Launcher provide(Parameters parameters);
+
}
diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java
index 637c5da7..5aab40ff 100644
--- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java
+++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java
@@ -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());
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());
}
diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java
index 181156c6..57e29605 100644
--- a/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java
+++ b/libraries/launcher/org/prismlauncher/launcher/impl/LegacyLauncher.java
@@ -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 traits = params.getList("traits", Collections.emptyList());
noApplet = traits.contains("noapplet");
-
+
cwd = System.getProperty("user.dir");
}
diff --git a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java
index 7607d731..ca648012 100644
--- a/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java
+++ b/libraries/launcher/org/prismlauncher/utils/LegacyUtils.java
@@ -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;
}
-
+
}