More minor fixes

This commit is contained in:
icelimetea 2022-05-03 03:19:26 +01:00
parent 860a7af679
commit 9a87ae575e
8 changed files with 47 additions and 64 deletions

View File

@ -14,7 +14,7 @@ set(SRC
org/multimc/applet/LegacyFrame.java org/multimc/applet/LegacyFrame.java
org/multimc/exception/ParameterNotFoundException.java org/multimc/exception/ParameterNotFoundException.java
org/multimc/exception/ParseException.java org/multimc/exception/ParseException.java
org/multimc/utils/ParamBucket.java org/multimc/utils/Parameters.java
org/multimc/utils/Utils.java org/multimc/utils/Utils.java
net/minecraft/Launcher.java net/minecraft/Launcher.java
) )

View File

@ -24,22 +24,20 @@ import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
public 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 final Applet wrappedApplet;
private boolean active = false; private boolean active = false;
private Applet wrappedApplet; public Launcher(Applet applet) {
private URL documentBase;
public Launcher(Applet applet, URL documentBase) {
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
this.add(applet, "Center"); this.add(applet, "Center");
this.wrappedApplet = applet; this.wrappedApplet = applet;
this.documentBase = documentBase;
} }
public void setParameter(String name, String value) public void setParameter(String name, String value)
@ -47,21 +45,6 @@ public class Launcher extends Applet implements AppletStub {
params.put(name, value); params.put(name, value);
} }
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 @Override
public String getParameter(String name) { public String getParameter(String name) {
String param = params.get(name); String param = params.get(name);
@ -135,9 +118,8 @@ public class Launcher extends Applet implements AppletStub {
public URL getDocumentBase() { public URL getDocumentBase() {
try { try {
// Special case only for Classic versions // Special case only for Classic versions
if (wrappedApplet.getClass().getCanonicalName().startsWith("com.mojang")) { if (wrappedApplet.getClass().getCanonicalName().startsWith("com.mojang"))
return new URL("http", "www.minecraft.net", 80, "/game/", null); return new URL("http", "www.minecraft.net", 80, "/game/");
}
return new URL("http://www.minecraft.net/game/"); return new URL("http://www.minecraft.net/game/");
} catch (MalformedURLException e) { } catch (MalformedURLException e) {

View File

@ -15,7 +15,7 @@ package org.multimc;/*
*/ */
import org.multimc.exception.ParseException; import org.multimc.exception.ParseException;
import org.multimc.utils.ParamBucket; import org.multimc.utils.Parameters;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -28,7 +28,7 @@ public final class EntryPoint {
private static final Logger LOGGER = Logger.getLogger("EntryPoint"); private static final Logger LOGGER = Logger.getLogger("EntryPoint");
private final ParamBucket params = new ParamBucket(); private final Parameters params = new Parameters();
private String launcherType; private String launcherType;

View File

@ -1,7 +1,7 @@
package org.multimc; package org.multimc;
import org.multimc.impl.OneSixLauncher; import org.multimc.impl.OneSixLauncher;
import org.multimc.utils.ParamBucket; import org.multimc.utils.Parameters;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -15,13 +15,13 @@ public final class LauncherFactory {
private LauncherFactory() { private LauncherFactory() {
launcherRegistry.put("onesix", new LauncherProvider() { launcherRegistry.put("onesix", new LauncherProvider() {
@Override @Override
public Launcher provide(ParamBucket parameters) { public Launcher provide(Parameters parameters) {
return new OneSixLauncher(parameters); return new OneSixLauncher(parameters);
} }
}); });
} }
public Launcher createLauncher(String name, ParamBucket parameters) { public Launcher createLauncher(String name, Parameters parameters) {
LauncherProvider launcherProvider = launcherRegistry.get(name); LauncherProvider launcherProvider = launcherRegistry.get(name);
if (launcherProvider == null) if (launcherProvider == null)
@ -36,7 +36,7 @@ public final class LauncherFactory {
public interface LauncherProvider { public interface LauncherProvider {
Launcher provide(ParamBucket parameters); Launcher provide(Parameters parameters);
} }

View File

@ -23,8 +23,6 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -38,11 +36,15 @@ public final class LegacyFrame extends Frame {
private static final Logger LOGGER = Logger.getLogger("LegacyFrame"); private static final Logger LOGGER = Logger.getLogger("LegacyFrame");
private Launcher appletWrap; private final Launcher appletWrap;
public LegacyFrame(String title) { public LegacyFrame(String title, Applet mcApplet) {
super(title); super(title);
appletWrap = new Launcher(mcApplet);
mcApplet.setStub(appletWrap);
try { try {
setIconImage(ImageIO.read(new File("icon.png"))); setIconImage(ImageIO.read(new File("icon.png")));
} catch (IOException e) { } catch (IOException e) {
@ -53,7 +55,6 @@ public final class LegacyFrame extends Frame {
} }
public void start ( public void start (
Applet mcApplet,
String user, String user,
String session, String session,
int winSizeW, int winSizeW,
@ -62,14 +63,14 @@ public final class LegacyFrame extends Frame {
String serverAddress, String serverAddress,
String serverPort String serverPort
) { ) {
try {
appletWrap = new Launcher(mcApplet, new URL("http://www.minecraft.net/game"));
} catch (MalformedURLException ignored) {}
// Implements support for launching in to multiplayer on classic servers using a mpticket // Implements support for launching in to multiplayer on classic servers using a mpticket
// file generated by an external program and stored in the instance's root folder. // file generated by an external program and stored in the instance's root folder.
Path mpticketFile = Paths.get(System.getProperty("user.dir") + "/../mpticket");
Path mpticketFileCorrupt = Paths.get(System.getProperty("user.dir") + "/../mpticket.corrupt"); Path mpticketFile =
Paths.get(System.getProperty("user.dir"), "..", "mpticket");
Path mpticketFileCorrupt =
Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt");
if (Files.exists(mpticketFile)) { if (Files.exists(mpticketFile)) {
try (Scanner fileScanner = new Scanner( try (Scanner fileScanner = new Scanner(
@ -115,8 +116,6 @@ public final class LegacyFrame extends Frame {
appletWrap.setParameter("demo", "false"); appletWrap.setParameter("demo", "false");
appletWrap.setParameter("fullscreen", "false"); appletWrap.setParameter("fullscreen", "false");
mcApplet.setStub(appletWrap);
add(appletWrap); add(appletWrap);
appletWrap.setPreferredSize(new Dimension(winSizeW, winSizeH)); appletWrap.setPreferredSize(new Dimension(winSizeW, winSizeH));

View File

@ -18,10 +18,6 @@ package org.multimc.exception;
public final class ParseException extends IllegalArgumentException { public final class ParseException extends IllegalArgumentException {
public ParseException() {
super();
}
public ParseException(String message) { public ParseException(String message) {
super(message); super(message);
} }

View File

@ -17,7 +17,7 @@ package org.multimc.impl;
import org.multimc.Launcher; import org.multimc.Launcher;
import org.multimc.applet.LegacyFrame; import org.multimc.applet.LegacyFrame;
import org.multimc.utils.ParamBucket; import org.multimc.utils.Parameters;
import org.multimc.utils.Utils; import org.multimc.utils.Utils;
import java.applet.Applet; import java.applet.Applet;
@ -55,7 +55,7 @@ public final class OneSixLauncher implements Launcher {
private final ClassLoader classLoader; private final ClassLoader classLoader;
public OneSixLauncher(ParamBucket params) { public OneSixLauncher(Parameters params) {
classLoader = ClassLoader.getSystemClassLoader(); classLoader = ClassLoader.getSystemClassLoader();
mcParams = params.allSafe("param", Collections.<String>emptyList()); mcParams = params.allSafe("param", Collections.<String>emptyList());
@ -72,8 +72,9 @@ public final class OneSixLauncher implements Launcher {
cwd = System.getProperty("user.dir"); cwd = System.getProperty("user.dir");
String windowParams = params.firstSafe("windowParams", "854x480"); String windowParams = params.firstSafe("windowParams", null);
if (windowParams != null) {
String[] dimStrings = windowParams.split("x"); String[] dimStrings = windowParams.split("x");
if (windowParams.equalsIgnoreCase("max")) { if (windowParams.equalsIgnoreCase("max")) {
@ -89,6 +90,12 @@ public final class OneSixLauncher implements Launcher {
} else { } else {
throw new IllegalArgumentException("Unexpected window size parameter value: " + windowParams); throw new IllegalArgumentException("Unexpected window size parameter value: " + windowParams);
} }
} else {
maximize = false;
winSizeW = DEFAULT_WINDOW_WIDTH;
winSizeH = DEFAULT_WINDOW_HEIGHT;
}
} }
private void invokeMain(Class<?> mainClass) throws Exception { private void invokeMain(Class<?> mainClass) throws Exception {
@ -121,10 +128,9 @@ public final class OneSixLauncher implements Launcher {
Applet mcApplet = (Applet) mcAppletClass.getConstructor().newInstance(); Applet mcApplet = (Applet) mcAppletClass.getConstructor().newInstance();
LegacyFrame mcWindow = new LegacyFrame(windowTitle); LegacyFrame mcWindow = new LegacyFrame(windowTitle, mcApplet);
mcWindow.start( mcWindow.start(
mcApplet,
userName, userName,
sessionId, sessionId,
winSizeW, winSizeW,

View File

@ -23,7 +23,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public final class ParamBucket { public final class Parameters {
private final Map<String, List<String>> paramsMap = new HashMap<>(); private final Map<String, List<String>> paramsMap = new HashMap<>();