diff --git a/libraries/launcher/net/minecraft/Launcher.java b/libraries/launcher/net/minecraft/Launcher.java index 8dff5692..796e4829 100644 --- a/libraries/launcher/net/minecraft/Launcher.java +++ b/libraries/launcher/net/minecraft/Launcher.java @@ -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 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(); diff --git a/libraries/launcher/org/prismlauncher/EntryPoint.java b/libraries/launcher/org/prismlauncher/EntryPoint.java index 444e665f..be180d6a 100644 --- a/libraries/launcher/org/prismlauncher/EntryPoint.java +++ b/libraries/launcher/org/prismlauncher/EntryPoint.java @@ -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,11 +117,10 @@ 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), diff --git a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java index 48bf9f4c..ad973ace 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParameterNotFoundException.java @@ -5,6 +5,8 @@ * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad * * 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) { diff --git a/libraries/launcher/org/prismlauncher/exception/ParseException.java b/libraries/launcher/org/prismlauncher/exception/ParseException.java index 0d5f3c10..2fd693e7 100644 --- a/libraries/launcher/org/prismlauncher/exception/ParseException.java +++ b/libraries/launcher/org/prismlauncher/exception/ParseException.java @@ -5,6 +5,8 @@ * Copyright (C) 2022 icelimetea * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Samisafool + * Copyright (C) 2022 solonovamax + * Copyright (C) 2022 TheKodeToad * * 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); } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java index 03a76d29..4844a774 100644 --- a/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java +++ b/libraries/launcher/org/prismlauncher/launcher/LauncherFactory.java @@ -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; } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java index ac7a6223..8aec7c28 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/AbstractLauncher.java @@ -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 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; } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java index 61709bf7..a3ea2f4a 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/StandardLauncher.java @@ -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); } } + } diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java index 391aa702..96b422b2 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyFrame.java @@ -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(); diff --git a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java index 17cdeb08..71e4bc8d 100644 --- a/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java +++ b/libraries/launcher/org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java @@ -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 traits = params.getList("traits", Collections.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); } } + } diff --git a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java index b0eefec7..ad9e57fd 100644 --- a/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/ReflectionUtils.java @@ -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)); } + } diff --git a/libraries/launcher/org/prismlauncher/utils/StringUtils.java b/libraries/launcher/org/prismlauncher/utils/StringUtils.java index d470624c..a371b0cb 100644 --- a/libraries/launcher/org/prismlauncher/utils/StringUtils.java +++ b/libraries/launcher/org/prismlauncher/utils/StringUtils.java @@ -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) }; } + }