Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKodeToad committed Oct 29, 2022
1 parent 6710abd commit cc0c920
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 103 deletions.
80 changes: 39 additions & 41 deletions libraries/launcher/net/minecraft/Launcher.java
Expand Up @@ -16,7 +16,6 @@

package net.minecraft;


import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.BorderLayout;
Expand All @@ -27,40 +26,39 @@
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 {
Expand All @@ -71,35 +69,35 @@ public Launcher(Applet applet, URL documentBase) {
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 {
Expand All @@ -109,79 +107,79 @@ public URL getCodeBase() {
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);
}

}
58 changes: 28 additions & 30 deletions libraries/launcher/org/prismlauncher/EntryPoint.java
Expand Up @@ -52,7 +52,6 @@

package org.prismlauncher;


import org.prismlauncher.exception.ParseException;
import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.launcher.LauncherFactory;
Expand All @@ -65,37 +64,37 @@
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;
Expand All @@ -104,22 +103,22 @@ private static PreLaunchAction parseLine(String inData, Parameters params) throw
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);
Expand All @@ -129,50 +128,49 @@ public ExitCode listen() {
}
} 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;
}
}

}
3 changes: 2 additions & 1 deletion libraries/launcher/org/prismlauncher/launcher/Launcher.java
Expand Up @@ -16,7 +16,8 @@

package org.prismlauncher.launcher;


public interface Launcher {

void launch() throws Throwable;

}

0 comments on commit cc0c920

Please sign in to comment.