Fix formatting

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2022-10-29 09:47:09 +01:00
parent e5622ce824
commit e86fbc697f
8 changed files with 94 additions and 103 deletions

View File

@ -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.
* <p>
* Changing field and method declarations without further testing is not recommended.
*/
public final class Launcher extends Applet implements AppletStub {
private final Map<String, String> 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);
}
}

View File

@ -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;
}
}
}

View File

@ -16,7 +16,8 @@
package org.prismlauncher.launcher;
public interface Launcher {
void launch() throws Throwable;
}

View File

@ -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);
}
}

View File

@ -35,10 +35,10 @@
package org.prismlauncher.launcher;
import org.prismlauncher.utils.Parameters;
public interface LauncherProvider {
Launcher provide(Parameters parameters);
}

View File

@ -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());
}

View File

@ -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");
}

View File

@ -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;
}
}