Try to improve consistency
- Makes code formatting more consistent with the C++ codebase. Probably removes some trailing whitespace. Maybe it would be best to commit an Eclipse or IntelliJ code format preferences file? - Removes obscure suppressions. I personally think it's better to only suppress warnings that javac complains about. Suppressing a lot of non-standardised warnings (many of them turned off by default even in IntelliJ) just creates needless clutter. - Fixes some trivial warnings instead of suppressing them. serialVersionUID is sort of stupid, but I'd rather mentally ignore it or just fix it if it's really that annoying. Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
afe088dba1
commit
8ce78dcc54
@ -72,12 +72,12 @@ import java.util.TreeMap;
|
||||
*/
|
||||
public final class Launcher extends Applet implements AppletStub {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Map<String, String> params = new TreeMap<>();
|
||||
|
||||
private Applet wrappedApplet;
|
||||
|
||||
private final URL documentBase;
|
||||
|
||||
private boolean active = false;
|
||||
|
||||
public Launcher(Applet applet) {
|
||||
@ -85,11 +85,11 @@ public final class Launcher extends Applet implements AppletStub {
|
||||
}
|
||||
|
||||
public Launcher(Applet applet, URL documentBase) {
|
||||
this.setLayout(new BorderLayout());
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
this.add(applet, "Center");
|
||||
|
||||
this.wrappedApplet = applet;
|
||||
wrappedApplet = applet;
|
||||
|
||||
try {
|
||||
if (documentBase != null) {
|
||||
@ -109,12 +109,12 @@ public final class Launcher extends Applet implements AppletStub {
|
||||
}
|
||||
|
||||
public void replace(Applet applet) {
|
||||
this.wrappedApplet = applet;
|
||||
wrappedApplet = applet;
|
||||
|
||||
applet.setStub(this);
|
||||
applet.setSize(getWidth(), getHeight());
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
setLayout(new BorderLayout());
|
||||
this.add(applet, "Center");
|
||||
|
||||
applet.init();
|
||||
|
@ -55,7 +55,6 @@
|
||||
|
||||
package org.prismlauncher;
|
||||
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.launcher.LauncherFactory;
|
||||
@ -69,7 +68,6 @@ 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");
|
||||
|
||||
@ -92,11 +90,11 @@ public final class EntryPoint {
|
||||
throw new ParseException("Unexpected empty string! You should not pass empty newlines to stdin.");
|
||||
|
||||
|
||||
if ("launch".equalsIgnoreCase(input)) {
|
||||
if ("launch".equalsIgnoreCase(input))
|
||||
return PreLaunchAction.LAUNCH;
|
||||
} else if ("abort".equalsIgnoreCase(input)) {
|
||||
else if ("abort".equalsIgnoreCase(input))
|
||||
return PreLaunchAction.ABORT;
|
||||
} else {
|
||||
else {
|
||||
String[] pair = StringUtils.splitStringPair(' ', input);
|
||||
if (pair == null)
|
||||
throw new ParseException(String.format(
|
||||
@ -119,12 +117,11 @@ public final class EntryPoint {
|
||||
|
||||
while (preLaunchAction == PreLaunchAction.PROCEED) {
|
||||
//noinspection NestedAssignment
|
||||
if ((line = reader.readLine()) != null) {
|
||||
if ((line = reader.readLine()) != null)
|
||||
preLaunchAction = parseLine(line, parameters);
|
||||
} else {
|
||||
else
|
||||
preLaunchAction = PreLaunchAction.ABORT;
|
||||
}
|
||||
}
|
||||
} catch (IOException | ParseException e) {
|
||||
LOGGER.log(Level.SEVERE, "Launcher abort due to exception", e);
|
||||
|
||||
@ -165,7 +162,6 @@ public final class EntryPoint {
|
||||
ABORT
|
||||
}
|
||||
|
||||
|
||||
private enum ExitCode {
|
||||
NORMAL(0),
|
||||
ABORT(1),
|
||||
|
@ -5,6 +5,8 @@
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (C) 2022 Samisafool <thenerdiestguy@gmail.com>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -38,10 +40,10 @@
|
||||
|
||||
package org.prismlauncher.exception;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public final class ParameterNotFoundException extends IllegalArgumentException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ParameterNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
@ -55,7 +57,6 @@ public final class ParameterNotFoundException extends IllegalArgumentException {
|
||||
}
|
||||
|
||||
public ParameterNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static ParameterNotFoundException forParameterName(String parameterName) {
|
||||
|
@ -5,6 +5,8 @@
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (C) 2022 Samisafool <thenerdiestguy@gmail.com>
|
||||
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -38,10 +40,10 @@
|
||||
|
||||
package org.prismlauncher.exception;
|
||||
|
||||
|
||||
@SuppressWarnings({ "serial", "unused" })
|
||||
public final class ParseException extends IllegalArgumentException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
@ -65,4 +67,5 @@ public final class ParseException extends IllegalArgumentException {
|
||||
public static ParseException forInputString(String inputString, Throwable cause) {
|
||||
return new ParseException(String.format("Could not parse input string '%s'", inputString), cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,13 +40,12 @@
|
||||
|
||||
package org.prismlauncher.launcher;
|
||||
|
||||
|
||||
import org.prismlauncher.launcher.impl.StandardLauncher;
|
||||
import org.prismlauncher.launcher.impl.legacy.LegacyLauncher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
|
||||
|
||||
public final class LauncherFactory {
|
||||
|
||||
private LauncherFactory() {
|
||||
}
|
||||
|
||||
@ -78,4 +77,5 @@ public final class LauncherFactory {
|
||||
return launcherProvider;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,7 +56,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl;
|
||||
|
||||
|
||||
import org.prismlauncher.exception.ParseException;
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
@ -66,26 +65,18 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
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;
|
||||
|
||||
// parameters, separated from ParamBucket
|
||||
protected final List<String> mcParams;
|
||||
|
||||
// secondary parameters
|
||||
protected final int width;
|
||||
|
||||
protected final int height;
|
||||
|
||||
protected final int width, height;
|
||||
protected final boolean maximize;
|
||||
|
||||
protected final String serverAddress;
|
||||
|
||||
protected final String serverPort;
|
||||
protected final String serverAddress, serverPort;
|
||||
|
||||
protected final String mainClassName;
|
||||
|
||||
@ -118,4 +109,5 @@ public abstract class AbstractLauncher implements Launcher {
|
||||
this.height = DEFAULT_WINDOW_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl;
|
||||
|
||||
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.launcher.LauncherProvider;
|
||||
import org.prismlauncher.utils.Parameters;
|
||||
@ -66,10 +65,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public final class StandardLauncher extends AbstractLauncher {
|
||||
private static final Logger LOGGER = Logger.getLogger("LegacyLauncher");
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("LegacyLauncher");
|
||||
|
||||
public StandardLauncher(Parameters params) {
|
||||
super(params);
|
||||
@ -105,16 +103,15 @@ public final class StandardLauncher extends AbstractLauncher {
|
||||
|
||||
LOGGER.info("Launching minecraft using the main class entrypoint");
|
||||
|
||||
MethodHandle method = ReflectionUtils.findMainEntrypoint(this.mainClassName);
|
||||
|
||||
MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName);
|
||||
method.invokeExact((Object[]) launchParameters.toArray(new String[0]));
|
||||
}
|
||||
|
||||
|
||||
private static class StandardLauncherProvider implements LauncherProvider {
|
||||
@Override
|
||||
public Launcher provide(Parameters parameters) {
|
||||
return new StandardLauncher(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl.legacy;
|
||||
|
||||
|
||||
import net.minecraft.Launcher;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@ -77,7 +76,7 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class LegacyFrame extends Frame {
|
||||
public final class LegacyFrame extends Frame /* TODO consider JFrame */ {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("LegacyFrame");
|
||||
|
||||
@ -163,7 +162,7 @@ public final class LegacyFrame extends Frame {
|
||||
setResizable(true);
|
||||
|
||||
if (maximize)
|
||||
this.setExtendedState(MAXIMIZED_BOTH);
|
||||
setExtendedState(MAXIMIZED_BOTH);
|
||||
|
||||
validate();
|
||||
|
||||
|
@ -56,7 +56,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl.legacy;
|
||||
|
||||
|
||||
import org.prismlauncher.launcher.Launcher;
|
||||
import org.prismlauncher.launcher.LauncherProvider;
|
||||
import org.prismlauncher.launcher.impl.AbstractLauncher;
|
||||
@ -71,7 +70,6 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Used to launch old versions that support applets.
|
||||
*/
|
||||
@ -80,13 +78,9 @@ public final class LegacyLauncher extends AbstractLauncher {
|
||||
private static final Logger LOGGER = Logger.getLogger("LegacyLauncher");
|
||||
|
||||
private final String user, session;
|
||||
|
||||
private final String title;
|
||||
|
||||
private final String appletClass;
|
||||
|
||||
private final boolean usesApplet;
|
||||
|
||||
private final String cwd;
|
||||
|
||||
public LegacyLauncher(Parameters params) {
|
||||
@ -100,7 +94,6 @@ public final class LegacyLauncher extends AbstractLauncher {
|
||||
List<String> traits = params.getList("traits", Collections.<String>emptyList());
|
||||
usesApplet = !traits.contains("noapplet");
|
||||
|
||||
//noinspection AccessOfSystemProperties
|
||||
cwd = System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
@ -113,9 +106,9 @@ public final class LegacyLauncher extends AbstractLauncher {
|
||||
Class<?> main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName);
|
||||
Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main);
|
||||
|
||||
if (gameDirField == null) {
|
||||
if (gameDirField == null)
|
||||
LOGGER.warning("Could not find Minecraft path field");
|
||||
} else {
|
||||
else {
|
||||
gameDirField.setAccessible(true);
|
||||
gameDirField.set(null /* field is static, so instance is null */, new File(cwd));
|
||||
}
|
||||
@ -144,11 +137,11 @@ public final class LegacyLauncher extends AbstractLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class LegacyLauncherProvider implements LauncherProvider {
|
||||
@Override
|
||||
public Launcher provide(Parameters parameters) {
|
||||
return new LegacyLauncher(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public final class ReflectionUtils {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("ReflectionUtils");
|
||||
|
||||
private ReflectionUtils() {
|
||||
@ -160,10 +160,9 @@ public final class ReflectionUtils {
|
||||
* @throws NoSuchMethodException If no method matching the correct signature can be found
|
||||
* @throws IllegalAccessException If method handles cannot access the entrypoint
|
||||
*/
|
||||
public static MethodHandle findMainEntrypoint(String entrypointClassName) throws
|
||||
ClassNotFoundException,
|
||||
NoSuchMethodException,
|
||||
IllegalAccessException {
|
||||
public static MethodHandle findMainMethod(String entrypointClassName)
|
||||
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException {
|
||||
return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,8 +36,8 @@
|
||||
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {
|
||||
}
|
||||
|
||||
@ -46,6 +46,7 @@ public final class StringUtils {
|
||||
if (splitPoint == -1)
|
||||
return null;
|
||||
|
||||
return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) };
|
||||
return new String[] { input.substring(0, splitPoint), input.substring(splitPoint + 1) };
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user