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; package net.minecraft;
import java.applet.Applet; import java.applet.Applet;
import java.applet.AppletStub; import java.applet.AppletStub;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -27,40 +26,39 @@ import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
/** /**
* WARNING: This class is reflectively accessed by legacy Forge versions. * WARNING: This class is reflectively accessed by legacy Forge versions.
* <p> * <p>
* Changing field and method declarations without further testing is not recommended. * Changing field and method declarations without further testing is not recommended.
*/ */
public final class Launcher extends Applet implements AppletStub { public final class Launcher extends Applet implements AppletStub {
private final Map<String, String> params = new TreeMap<>(); private final Map<String, String> params = new TreeMap<>();
private Applet wrappedApplet; private Applet wrappedApplet;
private final URL documentBase; private final URL documentBase;
private boolean active = false; private boolean active = false;
public Launcher(Applet applet) { public Launcher(Applet applet) {
this(applet, null); this(applet, null);
} }
public Launcher(Applet applet, URL documentBase) { public Launcher(Applet applet, URL documentBase) {
super(); super();
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
this.add(applet, "Center"); this.add(applet, "Center");
this.wrappedApplet = applet; this.wrappedApplet = applet;
try { try {
if (documentBase != null) { if (documentBase != null) {
this.documentBase = documentBase; this.documentBase = documentBase;
} else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) { } else if (applet.getClass().getPackage().getName().startsWith("com.mojang")) {
// Special case only for Classic versions // Special case only for Classic versions
// TODO: 2022-10-27 Can this be changed to https // TODO: 2022-10-27 Can this be changed to https
this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/"); this.documentBase = new URL("http", "www.minecraft.net", 80, "/game/");
} else { } else {
@ -71,35 +69,35 @@ public final class Launcher extends Applet implements AppletStub {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public void replace(Applet applet) { public void replace(Applet applet) {
this.wrappedApplet = applet; this.wrappedApplet = applet;
applet.setStub(this); applet.setStub(this);
applet.setSize(getWidth(), getHeight()); applet.setSize(getWidth(), getHeight());
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
this.add(applet, "Center"); this.add(applet, "Center");
applet.init(); applet.init();
active = true; active = true;
applet.start(); applet.start();
validate(); validate();
} }
@Override @Override
public boolean isActive() { public boolean isActive() {
return active; return active;
} }
@Override @Override
public URL getDocumentBase() { public URL getDocumentBase() {
return documentBase; return documentBase;
} }
@Override @Override
public URL getCodeBase() { public URL getCodeBase() {
try { try {
@ -109,79 +107,79 @@ public final class Launcher extends Applet implements AppletStub {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public String getParameter(String name) { public String getParameter(String name) {
String param = params.get(name); String param = params.get(name);
if (param != null) if (param != null)
return param; return param;
try { try {
return super.getParameter(name); return super.getParameter(name);
} catch (Exception ignored) { } catch (Exception ignored) {
} }
return null; return null;
} }
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
wrappedApplet.resize(width, height); wrappedApplet.resize(width, height);
} }
@Override @Override
public void resize(Dimension d) { public void resize(Dimension d) {
wrappedApplet.resize(d); wrappedApplet.resize(d);
} }
@Override @Override
public void init() { public void init() {
if (wrappedApplet != null) if (wrappedApplet != null)
wrappedApplet.init(); wrappedApplet.init();
} }
@Override @Override
public void start() { public void start() {
wrappedApplet.start(); wrappedApplet.start();
active = true; active = true;
} }
@Override @Override
public void stop() { public void stop() {
wrappedApplet.stop(); wrappedApplet.stop();
active = false; active = false;
} }
@Override @Override
public void destroy() { public void destroy() {
wrappedApplet.destroy(); wrappedApplet.destroy();
} }
@Override @Override
public void appletResize(int width, int height) { public void appletResize(int width, int height) {
wrappedApplet.resize(width, height); wrappedApplet.resize(width, height);
} }
@Override @Override
public void setVisible(boolean visible) { public void setVisible(boolean visible) {
super.setVisible(visible); super.setVisible(visible);
wrappedApplet.setVisible(visible); wrappedApplet.setVisible(visible);
} }
@Override @Override
public void paint(Graphics paramGraphics) { public void paint(Graphics paramGraphics) {
} }
@Override @Override
public void update(Graphics paramGraphics) { public void update(Graphics paramGraphics) {
} }
public void setParameter(String name, String value) { public void setParameter(String name, String value) {
params.put(name, value); params.put(name, value);
} }
} }

View File

@ -52,7 +52,6 @@
package org.prismlauncher; package org.prismlauncher;
import org.prismlauncher.exception.ParseException; import org.prismlauncher.exception.ParseException;
import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.launcher.LauncherFactory; import org.prismlauncher.launcher.LauncherFactory;
@ -65,37 +64,37 @@ import java.nio.charset.StandardCharsets;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public final class EntryPoint { public final class EntryPoint {
private static final Logger LOGGER = Logger.getLogger("EntryPoint"); private static final Logger LOGGER = Logger.getLogger("EntryPoint");
private final Parameters params = new Parameters(); private final Parameters params = new Parameters();
public static void main(String[] args) { public static void main(String[] args) {
EntryPoint listener = new EntryPoint(); EntryPoint listener = new EntryPoint();
ExitCode exitCode = listener.listen(); ExitCode exitCode = listener.listen();
if (exitCode != ExitCode.NORMAL) { if (exitCode != ExitCode.NORMAL) {
LOGGER.warning("Exiting with " + exitCode); LOGGER.warning("Exiting with " + exitCode);
System.exit(exitCode.numericalCode); System.exit(exitCode.numericalCode);
} }
} }
private static PreLaunchAction parseLine(String inData, Parameters params) throws ParseException { private static PreLaunchAction parseLine(String inData, Parameters params) throws ParseException {
if (inData.isEmpty()) if (inData.isEmpty())
throw new ParseException("Unexpected empty string!"); throw new ParseException("Unexpected empty string!");
String first = inData; String first = inData;
String second = null; String second = null;
int splitPoint = inData.indexOf(' '); int splitPoint = inData.indexOf(' ');
if (splitPoint != -1) { if (splitPoint != -1) {
first = first.substring(0, splitPoint); first = first.substring(0, splitPoint);
second = inData.substring(splitPoint + 1); second = inData.substring(splitPoint + 1);
} }
switch (first) { switch (first) {
case "launch": case "launch":
return PreLaunchAction.LAUNCH; return PreLaunchAction.LAUNCH;
@ -104,22 +103,22 @@ public final class EntryPoint {
default: default:
if (second == null || second.isEmpty()) if (second == null || second.isEmpty())
throw new ParseException("Error while parsing:" + inData); throw new ParseException("Error while parsing:" + inData);
params.add(first, second); params.add(first, second);
return PreLaunchAction.PROCEED; return PreLaunchAction.PROCEED;
} }
} }
public ExitCode listen() { public ExitCode listen() {
PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED; PreLaunchAction preLaunchAction = PreLaunchAction.PROCEED;
try (BufferedReader reader = new BufferedReader(new InputStreamReader( try (BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in, System.in,
StandardCharsets.UTF_8 StandardCharsets.UTF_8
))) { ))) {
String line; String line;
while (preLaunchAction == PreLaunchAction.PROCEED) { while (preLaunchAction == PreLaunchAction.PROCEED) {
if ((line = reader.readLine()) != null) { if ((line = reader.readLine()) != null) {
preLaunchAction = parseLine(line, this.params); preLaunchAction = parseLine(line, this.params);
@ -129,50 +128,49 @@ public final class EntryPoint {
} }
} catch (IOException | ParseException e) { } catch (IOException | ParseException e) {
LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e); LOGGER.log(Level.SEVERE, "Launcher abort due to exception:", e);
return ExitCode.ERROR; return ExitCode.ERROR;
} }
// Main loop // Main loop
if (preLaunchAction == PreLaunchAction.ABORT) { if (preLaunchAction == PreLaunchAction.ABORT) {
LOGGER.info("Launch aborted by the launcher."); LOGGER.info("Launch aborted by the launcher.");
return ExitCode.ERROR; return ExitCode.ERROR;
} }
try { try {
Launcher launcher = LauncherFactory.createLauncher(params); Launcher launcher = LauncherFactory.createLauncher(params);
launcher.launch(); launcher.launch();
return ExitCode.NORMAL; return ExitCode.NORMAL;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
LOGGER.log(Level.SEVERE, "Wrong argument.", e); LOGGER.log(Level.SEVERE, "Wrong argument.", e);
return ExitCode.ERROR; return ExitCode.ERROR;
} catch (Throwable e) { } catch (Throwable e) {
LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e); LOGGER.log(Level.SEVERE, "Exception caught from launcher.", e);
return ExitCode.ERROR; return ExitCode.ERROR;
} }
} }
private enum PreLaunchAction { private enum PreLaunchAction {
PROCEED, PROCEED,
LAUNCH, LAUNCH,
ABORT ABORT
} }
private enum ExitCode { private enum ExitCode {
NORMAL(0), NORMAL(0),
ERROR(1); ERROR(1);
private final int numericalCode; private final int numericalCode;
ExitCode(int numericalCode) { ExitCode(int numericalCode) {
this.numericalCode = numericalCode; this.numericalCode = numericalCode;
} }
} }
} }

View File

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

View File

@ -35,7 +35,6 @@
package org.prismlauncher.launcher; package org.prismlauncher.launcher;
import org.prismlauncher.launcher.impl.LegacyLauncher; import org.prismlauncher.launcher.impl.LegacyLauncher;
import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.launcher.impl.StandardLauncher;
import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.Parameters;
@ -43,10 +42,10 @@ import org.prismlauncher.utils.Parameters;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public final class LauncherFactory { public final class LauncherFactory {
private static final Map<String, LauncherProvider> launcherRegistry = new HashMap<>(); private static final Map<String, LauncherProvider> launcherRegistry = new HashMap<>();
static { static {
launcherRegistry.put("standard", new LauncherProvider() { launcherRegistry.put("standard", new LauncherProvider() {
@Override @Override
@ -63,15 +62,15 @@ public final class LauncherFactory {
} }
private LauncherFactory() { private LauncherFactory() {
} }
public static Launcher createLauncher(Parameters parameters) { public static Launcher createLauncher(Parameters parameters) {
String name = parameters.getString("launcher"); String name = parameters.getString("launcher");
LauncherProvider launcherProvider = launcherRegistry.get(name); LauncherProvider launcherProvider = launcherRegistry.get(name);
if (launcherProvider == null) if (launcherProvider == null)
throw new IllegalArgumentException("Invalid launcher type: " + name); throw new IllegalArgumentException("Invalid launcher type: " + name);
return launcherProvider.provide(parameters); return launcherProvider.provide(parameters);
} }
} }

View File

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

View File

@ -15,7 +15,6 @@
package org.prismlauncher.launcher.impl; package org.prismlauncher.launcher.impl;
import org.prismlauncher.exception.ParseException; import org.prismlauncher.exception.ParseException;
import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.Parameters;
@ -26,9 +25,8 @@ import java.lang.invoke.MethodType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class AbstractLauncher implements Launcher { public abstract class AbstractLauncher implements Launcher {
private static final int DEFAULT_WINDOW_WIDTH = 854; private static final int DEFAULT_WINDOW_WIDTH = 854;
private static final int DEFAULT_WINDOW_HEIGHT = 480; 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 String serverAddress, serverPort;
protected final ClassLoader classLoader; protected final ClassLoader classLoader;
protected AbstractLauncher(Parameters params) { protected AbstractLauncher(Parameters params) {
classLoader = ClassLoader.getSystemClassLoader(); classLoader = ClassLoader.getSystemClassLoader();
mcParams = params.getList("param", new ArrayList<String>()); mcParams = params.getList("param", new ArrayList<String>());
mainClass = params.getString("mainClass", "net.minecraft.client.Minecraft"); mainClass = params.getString("mainClass", "net.minecraft.client.Minecraft");
serverAddress = params.getString("serverAddress", null); serverAddress = params.getString("serverAddress", null);
serverPort = params.getString("serverPort", null); serverPort = params.getString("serverPort", null);
String windowParams = params.getString("windowParams", null); String windowParams = params.getString("windowParams", null);
if ("max".equals(windowParams) || windowParams == null) { if ("max".equals(windowParams) || windowParams == null) {
maximize = windowParams != null; maximize = windowParams != null;
width = DEFAULT_WINDOW_WIDTH; width = DEFAULT_WINDOW_WIDTH;
height = DEFAULT_WINDOW_HEIGHT; height = DEFAULT_WINDOW_HEIGHT;
} else { } else {
@ -82,7 +80,7 @@ public abstract class AbstractLauncher implements Launcher {
protected Class<?> loadMain() throws ClassNotFoundException { protected Class<?> loadMain() throws ClassNotFoundException {
return classLoader.loadClass(mainClass); return classLoader.loadClass(mainClass);
} }
protected void loadAndInvokeMain() throws Throwable { protected void loadAndInvokeMain() throws Throwable {
invokeMain(loadMain()); invokeMain(loadMain());
} }

View File

@ -15,7 +15,6 @@
package org.prismlauncher.launcher.impl; package org.prismlauncher.launcher.impl;
import org.prismlauncher.applet.LegacyFrame; import org.prismlauncher.applet.LegacyFrame;
import org.prismlauncher.utils.LegacyUtils; import org.prismlauncher.utils.LegacyUtils;
import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.Parameters;
@ -45,15 +44,15 @@ public final class LegacyLauncher extends AbstractLauncher {
public LegacyLauncher(Parameters params) { public LegacyLauncher(Parameters params) {
super(params); super(params);
user = params.getString("userName"); user = params.getString("userName");
session = params.getString("sessionId"); session = params.getString("sessionId");
title = params.getString("windowTitle", "Minecraft"); title = params.getString("windowTitle", "Minecraft");
appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet"); appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet");
List<String> traits = params.getList("traits", Collections.<String>emptyList()); List<String> traits = params.getList("traits", Collections.<String>emptyList());
noApplet = traits.contains("noapplet"); noApplet = traits.contains("noapplet");
cwd = System.getProperty("user.dir"); cwd = System.getProperty("user.dir");
} }

View File

@ -16,17 +16,15 @@
package org.prismlauncher.utils; package org.prismlauncher.utils;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
public final class LegacyUtils { public final class LegacyUtils {
private LegacyUtils() { private LegacyUtils() {
} }
/** /**
* Finds a field that looks like a Minecraft base folder in a supplied class * 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 // Has to be File
if (field.getType() != File.class) if (field.getType() != File.class)
continue; continue;
// And Private Static. // And Private Static.
if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers()))
continue; continue;
return field; return field;
} }
return null; return null;
} }
} }