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:
TheKodeToad 2022-11-03 16:40:23 +00:00
parent afe088dba1
commit 8ce78dcc54
11 changed files with 40 additions and 59 deletions

View File

@ -72,12 +72,12 @@ import java.util.TreeMap;
*/ */
public final class Launcher extends Applet implements AppletStub { public final class Launcher extends Applet implements AppletStub {
private static final long serialVersionUID = 1L;
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) {
@ -85,11 +85,11 @@ public final class Launcher extends Applet implements AppletStub {
} }
public Launcher(Applet applet, URL documentBase) { public Launcher(Applet applet, URL documentBase) {
this.setLayout(new BorderLayout()); setLayout(new BorderLayout());
this.add(applet, "Center"); this.add(applet, "Center");
this.wrappedApplet = applet; wrappedApplet = applet;
try { try {
if (documentBase != null) { if (documentBase != null) {
@ -109,12 +109,12 @@ public final class Launcher extends Applet implements AppletStub {
} }
public void replace(Applet applet) { public void replace(Applet applet) {
this.wrappedApplet = applet; wrappedApplet = applet;
applet.setStub(this); applet.setStub(this);
applet.setSize(getWidth(), getHeight()); applet.setSize(getWidth(), getHeight());
this.setLayout(new BorderLayout()); setLayout(new BorderLayout());
this.add(applet, "Center"); this.add(applet, "Center");
applet.init(); applet.init();

View File

@ -55,7 +55,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;
@ -69,7 +68,6 @@ 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");
@ -92,11 +90,11 @@ public final class EntryPoint {
throw new ParseException("Unexpected empty string! You should not pass empty newlines to stdin."); 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; return PreLaunchAction.LAUNCH;
} else if ("abort".equalsIgnoreCase(input)) { else if ("abort".equalsIgnoreCase(input))
return PreLaunchAction.ABORT; return PreLaunchAction.ABORT;
} else { else {
String[] pair = StringUtils.splitStringPair(' ', input); String[] pair = StringUtils.splitStringPair(' ', input);
if (pair == null) if (pair == null)
throw new ParseException(String.format( throw new ParseException(String.format(
@ -119,11 +117,10 @@ public final class EntryPoint {
while (preLaunchAction == PreLaunchAction.PROCEED) { while (preLaunchAction == PreLaunchAction.PROCEED) {
//noinspection NestedAssignment //noinspection NestedAssignment
if ((line = reader.readLine()) != null) { if ((line = reader.readLine()) != null)
preLaunchAction = parseLine(line, parameters); preLaunchAction = parseLine(line, parameters);
} else { else
preLaunchAction = PreLaunchAction.ABORT; preLaunchAction = PreLaunchAction.ABORT;
}
} }
} 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);
@ -165,7 +162,6 @@ public final class EntryPoint {
ABORT ABORT
} }
private enum ExitCode { private enum ExitCode {
NORMAL(0), NORMAL(0),
ABORT(1), ABORT(1),

View File

@ -5,6 +5,8 @@
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com> * Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 Samisafool <thenerdiestguy@gmail.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -38,10 +40,10 @@
package org.prismlauncher.exception; package org.prismlauncher.exception;
@SuppressWarnings("serial")
public final class ParameterNotFoundException extends IllegalArgumentException { public final class ParameterNotFoundException extends IllegalArgumentException {
private static final long serialVersionUID = 1L;
public ParameterNotFoundException(String message, Throwable cause) { public ParameterNotFoundException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }
@ -55,7 +57,6 @@ public final class ParameterNotFoundException extends IllegalArgumentException {
} }
public ParameterNotFoundException() { public ParameterNotFoundException() {
super();
} }
public static ParameterNotFoundException forParameterName(String parameterName) { public static ParameterNotFoundException forParameterName(String parameterName) {

View File

@ -5,6 +5,8 @@
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com> * Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 Samisafool <thenerdiestguy@gmail.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -38,10 +40,10 @@
package org.prismlauncher.exception; package org.prismlauncher.exception;
@SuppressWarnings({ "serial", "unused" })
public final class ParseException extends IllegalArgumentException { public final class ParseException extends IllegalArgumentException {
private static final long serialVersionUID = 1L;
public ParseException(String message) { public ParseException(String message) {
super(message); super(message);
} }
@ -65,4 +67,5 @@ public final class ParseException extends IllegalArgumentException {
public static ParseException forInputString(String inputString, Throwable cause) { public static ParseException forInputString(String inputString, Throwable cause) {
return new ParseException(String.format("Could not parse input string '%s'", inputString), cause); return new ParseException(String.format("Could not parse input string '%s'", inputString), cause);
} }
} }

View File

@ -40,13 +40,12 @@
package org.prismlauncher.launcher; package org.prismlauncher.launcher;
import org.prismlauncher.launcher.impl.StandardLauncher; import org.prismlauncher.launcher.impl.StandardLauncher;
import org.prismlauncher.launcher.impl.legacy.LegacyLauncher; import org.prismlauncher.launcher.impl.legacy.LegacyLauncher;
import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.Parameters;
public final class LauncherFactory { public final class LauncherFactory {
private LauncherFactory() { private LauncherFactory() {
} }
@ -78,4 +77,5 @@ public final class LauncherFactory {
return launcherProvider; return launcherProvider;
} }
} }
} }

View File

@ -56,7 +56,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;
@ -66,26 +65,18 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
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;
// parameters, separated from ParamBucket // parameters, separated from ParamBucket
protected final List<String> mcParams; protected final List<String> mcParams;
// secondary parameters // secondary parameters
protected final int width; protected final int width, height;
protected final int height;
protected final boolean maximize; protected final boolean maximize;
protected final String serverAddress, serverPort;
protected final String serverAddress;
protected final String serverPort;
protected final String mainClassName; protected final String mainClassName;
@ -118,4 +109,5 @@ public abstract class AbstractLauncher implements Launcher {
this.height = DEFAULT_WINDOW_HEIGHT; this.height = DEFAULT_WINDOW_HEIGHT;
} }
} }
} }

View File

@ -55,7 +55,6 @@
package org.prismlauncher.launcher.impl; package org.prismlauncher.launcher.impl;
import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.LauncherProvider;
import org.prismlauncher.utils.Parameters; import org.prismlauncher.utils.Parameters;
@ -66,10 +65,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
public final class StandardLauncher extends AbstractLauncher { 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) { public StandardLauncher(Parameters params) {
super(params); super(params);
@ -105,16 +103,15 @@ public final class StandardLauncher extends AbstractLauncher {
LOGGER.info("Launching minecraft using the main class entrypoint"); 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])); method.invokeExact((Object[]) launchParameters.toArray(new String[0]));
} }
private static class StandardLauncherProvider implements LauncherProvider { private static class StandardLauncherProvider implements LauncherProvider {
@Override @Override
public Launcher provide(Parameters parameters) { public Launcher provide(Parameters parameters) {
return new StandardLauncher(parameters); return new StandardLauncher(parameters);
} }
} }
} }

View File

@ -57,7 +57,6 @@
package org.prismlauncher.launcher.impl.legacy; package org.prismlauncher.launcher.impl.legacy;
import net.minecraft.Launcher; import net.minecraft.Launcher;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -77,7 +76,7 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; 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"); private static final Logger LOGGER = Logger.getLogger("LegacyFrame");
@ -163,7 +162,7 @@ public final class LegacyFrame extends Frame {
setResizable(true); setResizable(true);
if (maximize) if (maximize)
this.setExtendedState(MAXIMIZED_BOTH); setExtendedState(MAXIMIZED_BOTH);
validate(); validate();

View File

@ -56,7 +56,6 @@
package org.prismlauncher.launcher.impl.legacy; package org.prismlauncher.launcher.impl.legacy;
import org.prismlauncher.launcher.Launcher; import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.launcher.LauncherProvider; import org.prismlauncher.launcher.LauncherProvider;
import org.prismlauncher.launcher.impl.AbstractLauncher; import org.prismlauncher.launcher.impl.AbstractLauncher;
@ -71,7 +70,6 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* Used to launch old versions that support applets. * 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 static final Logger LOGGER = Logger.getLogger("LegacyLauncher");
private final String user, session; private final String user, session;
private final String title; private final String title;
private final String appletClass; private final String appletClass;
private final boolean usesApplet; private final boolean usesApplet;
private final String cwd; private final String cwd;
public LegacyLauncher(Parameters params) { public LegacyLauncher(Parameters params) {
@ -100,7 +94,6 @@ public final class LegacyLauncher extends AbstractLauncher {
List<String> traits = params.getList("traits", Collections.<String>emptyList()); List<String> traits = params.getList("traits", Collections.<String>emptyList());
usesApplet = !traits.contains("noapplet"); usesApplet = !traits.contains("noapplet");
//noinspection AccessOfSystemProperties
cwd = System.getProperty("user.dir"); cwd = System.getProperty("user.dir");
} }
@ -113,9 +106,9 @@ public final class LegacyLauncher extends AbstractLauncher {
Class<?> main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName); Class<?> main = ClassLoader.getSystemClassLoader().loadClass(this.mainClassName);
Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main); Field gameDirField = ReflectionUtils.getMinecraftGameDirField(main);
if (gameDirField == null) { if (gameDirField == null)
LOGGER.warning("Could not find Minecraft path field"); LOGGER.warning("Could not find Minecraft path field");
} else { else {
gameDirField.setAccessible(true); gameDirField.setAccessible(true);
gameDirField.set(null /* field is static, so instance is null */, new File(cwd)); 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 { private static class LegacyLauncherProvider implements LauncherProvider {
@Override @Override
public Launcher provide(Parameters parameters) { public Launcher provide(Parameters parameters) {
return new LegacyLauncher(parameters); return new LegacyLauncher(parameters);
} }
} }
} }

View File

@ -49,8 +49,8 @@ import java.lang.reflect.Modifier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public final class ReflectionUtils { public final class ReflectionUtils {
private static final Logger LOGGER = Logger.getLogger("ReflectionUtils"); private static final Logger LOGGER = Logger.getLogger("ReflectionUtils");
private ReflectionUtils() { private ReflectionUtils() {
@ -160,10 +160,9 @@ public final class ReflectionUtils {
* @throws NoSuchMethodException If no method matching the correct signature can be found * @throws NoSuchMethodException If no method matching the correct signature can be found
* @throws IllegalAccessException If method handles cannot access the entrypoint * @throws IllegalAccessException If method handles cannot access the entrypoint
*/ */
public static MethodHandle findMainEntrypoint(String entrypointClassName) throws public static MethodHandle findMainMethod(String entrypointClassName)
ClassNotFoundException, throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException {
NoSuchMethodException,
IllegalAccessException {
return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName)); return findMainEntrypoint(ClassLoader.getSystemClassLoader().loadClass(entrypointClassName));
} }
} }

View File

@ -36,8 +36,8 @@
package org.prismlauncher.utils; package org.prismlauncher.utils;
public final class StringUtils { public final class StringUtils {
private StringUtils() { private StringUtils() {
} }
@ -46,6 +46,7 @@ public final class StringUtils {
if (splitPoint == -1) if (splitPoint == -1)
return null; return null;
return new String[]{ input.substring(0, splitPoint), input.substring(splitPoint + 1) }; return new String[] { input.substring(0, splitPoint), input.substring(splitPoint + 1) };
} }
} }