More minor fixes
This commit is contained in:
parent
860a7af679
commit
9a87ae575e
@ -14,7 +14,7 @@ set(SRC
|
||||
org/multimc/applet/LegacyFrame.java
|
||||
org/multimc/exception/ParameterNotFoundException.java
|
||||
org/multimc/exception/ParseException.java
|
||||
org/multimc/utils/ParamBucket.java
|
||||
org/multimc/utils/Parameters.java
|
||||
org/multimc/utils/Utils.java
|
||||
net/minecraft/Launcher.java
|
||||
)
|
||||
|
@ -24,22 +24,20 @@ import java.net.URL;
|
||||
import java.util.Map;
|
||||
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 Applet wrappedApplet;
|
||||
|
||||
private boolean active = false;
|
||||
|
||||
private Applet wrappedApplet;
|
||||
private URL documentBase;
|
||||
|
||||
public Launcher(Applet applet, URL documentBase) {
|
||||
public Launcher(Applet applet) {
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
this.add(applet, "Center");
|
||||
|
||||
this.wrappedApplet = applet;
|
||||
this.documentBase = documentBase;
|
||||
}
|
||||
|
||||
public void setParameter(String name, String value)
|
||||
@ -47,21 +45,6 @@ public class Launcher extends Applet implements AppletStub {
|
||||
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
|
||||
public String getParameter(String name) {
|
||||
String param = params.get(name);
|
||||
@ -135,9 +118,8 @@ public class Launcher extends Applet implements AppletStub {
|
||||
public URL getDocumentBase() {
|
||||
try {
|
||||
// Special case only for Classic versions
|
||||
if (wrappedApplet.getClass().getCanonicalName().startsWith("com.mojang")) {
|
||||
return new URL("http", "www.minecraft.net", 80, "/game/", null);
|
||||
}
|
||||
if (wrappedApplet.getClass().getCanonicalName().startsWith("com.mojang"))
|
||||
return new URL("http", "www.minecraft.net", 80, "/game/");
|
||||
|
||||
return new URL("http://www.minecraft.net/game/");
|
||||
} catch (MalformedURLException e) {
|
||||
|
@ -15,7 +15,7 @@ package org.multimc;/*
|
||||
*/
|
||||
|
||||
import org.multimc.exception.ParseException;
|
||||
import org.multimc.utils.ParamBucket;
|
||||
import org.multimc.utils.Parameters;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@ -28,7 +28,7 @@ public final class EntryPoint {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger("EntryPoint");
|
||||
|
||||
private final ParamBucket params = new ParamBucket();
|
||||
private final Parameters params = new Parameters();
|
||||
|
||||
private String launcherType;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.multimc;
|
||||
|
||||
import org.multimc.impl.OneSixLauncher;
|
||||
import org.multimc.utils.ParamBucket;
|
||||
import org.multimc.utils.Parameters;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -15,13 +15,13 @@ public final class LauncherFactory {
|
||||
private LauncherFactory() {
|
||||
launcherRegistry.put("onesix", new LauncherProvider() {
|
||||
@Override
|
||||
public Launcher provide(ParamBucket parameters) {
|
||||
public Launcher provide(Parameters parameters) {
|
||||
return new OneSixLauncher(parameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Launcher createLauncher(String name, ParamBucket parameters) {
|
||||
public Launcher createLauncher(String name, Parameters parameters) {
|
||||
LauncherProvider launcherProvider = launcherRegistry.get(name);
|
||||
|
||||
if (launcherProvider == null)
|
||||
@ -36,7 +36,7 @@ public final class LauncherFactory {
|
||||
|
||||
public interface LauncherProvider {
|
||||
|
||||
Launcher provide(ParamBucket parameters);
|
||||
Launcher provide(Parameters parameters);
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,6 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -38,11 +36,15 @@ public final class LegacyFrame extends Frame {
|
||||
|
||||
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);
|
||||
|
||||
appletWrap = new Launcher(mcApplet);
|
||||
|
||||
mcApplet.setStub(appletWrap);
|
||||
|
||||
try {
|
||||
setIconImage(ImageIO.read(new File("icon.png")));
|
||||
} catch (IOException e) {
|
||||
@ -53,7 +55,6 @@ public final class LegacyFrame extends Frame {
|
||||
}
|
||||
|
||||
public void start (
|
||||
Applet mcApplet,
|
||||
String user,
|
||||
String session,
|
||||
int winSizeW,
|
||||
@ -62,14 +63,14 @@ public final class LegacyFrame extends Frame {
|
||||
String serverAddress,
|
||||
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
|
||||
// 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)) {
|
||||
try (Scanner fileScanner = new Scanner(
|
||||
@ -115,8 +116,6 @@ public final class LegacyFrame extends Frame {
|
||||
appletWrap.setParameter("demo", "false");
|
||||
appletWrap.setParameter("fullscreen", "false");
|
||||
|
||||
mcApplet.setStub(appletWrap);
|
||||
|
||||
add(appletWrap);
|
||||
|
||||
appletWrap.setPreferredSize(new Dimension(winSizeW, winSizeH));
|
||||
|
@ -18,10 +18,6 @@ package org.multimc.exception;
|
||||
|
||||
public final class ParseException extends IllegalArgumentException {
|
||||
|
||||
public ParseException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ package org.multimc.impl;
|
||||
|
||||
import org.multimc.Launcher;
|
||||
import org.multimc.applet.LegacyFrame;
|
||||
import org.multimc.utils.ParamBucket;
|
||||
import org.multimc.utils.Parameters;
|
||||
import org.multimc.utils.Utils;
|
||||
|
||||
import java.applet.Applet;
|
||||
@ -55,7 +55,7 @@ public final class OneSixLauncher implements Launcher {
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
public OneSixLauncher(ParamBucket params) {
|
||||
public OneSixLauncher(Parameters params) {
|
||||
classLoader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
mcParams = params.allSafe("param", Collections.<String>emptyList());
|
||||
@ -72,22 +72,29 @@ public final class OneSixLauncher implements Launcher {
|
||||
|
||||
cwd = System.getProperty("user.dir");
|
||||
|
||||
String windowParams = params.firstSafe("windowParams", "854x480");
|
||||
String windowParams = params.firstSafe("windowParams", null);
|
||||
|
||||
String[] dimStrings = windowParams.split("x");
|
||||
if (windowParams != null) {
|
||||
String[] dimStrings = windowParams.split("x");
|
||||
|
||||
if (windowParams.equalsIgnoreCase("max")) {
|
||||
maximize = true;
|
||||
if (windowParams.equalsIgnoreCase("max")) {
|
||||
maximize = true;
|
||||
|
||||
winSizeW = DEFAULT_WINDOW_WIDTH;
|
||||
winSizeH = DEFAULT_WINDOW_HEIGHT;
|
||||
} else if (dimStrings.length == 2) {
|
||||
maximize = false;
|
||||
|
||||
winSizeW = Integer.parseInt(dimStrings[0]);
|
||||
winSizeH = Integer.parseInt(dimStrings[1]);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected window size parameter value: " + windowParams);
|
||||
}
|
||||
} else {
|
||||
maximize = false;
|
||||
|
||||
winSizeW = DEFAULT_WINDOW_WIDTH;
|
||||
winSizeH = DEFAULT_WINDOW_HEIGHT;
|
||||
} else if (dimStrings.length == 2) {
|
||||
maximize = false;
|
||||
|
||||
winSizeW = Integer.parseInt(dimStrings[0]);
|
||||
winSizeH = Integer.parseInt(dimStrings[1]);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected window size parameter value: " + windowParams);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,10 +128,9 @@ public final class OneSixLauncher implements Launcher {
|
||||
|
||||
Applet mcApplet = (Applet) mcAppletClass.getConstructor().newInstance();
|
||||
|
||||
LegacyFrame mcWindow = new LegacyFrame(windowTitle);
|
||||
LegacyFrame mcWindow = new LegacyFrame(windowTitle, mcApplet);
|
||||
|
||||
mcWindow.start(
|
||||
mcApplet,
|
||||
userName,
|
||||
sessionId,
|
||||
winSizeW,
|
||||
|
@ -23,7 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class ParamBucket {
|
||||
public final class Parameters {
|
||||
|
||||
private final Map<String, List<String>> paramsMap = new HashMap<>();
|
||||
|
Loading…
Reference in New Issue
Block a user