Always use this for consistency
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
d90eff64d0
commit
50d40257fe
@ -113,28 +113,28 @@ public final class Launcher extends Applet implements AppletStub {
|
|||||||
wrappedApplet = applet;
|
wrappedApplet = applet;
|
||||||
|
|
||||||
applet.setStub(this);
|
applet.setStub(this);
|
||||||
applet.setSize(getWidth(), getHeight());
|
applet.setSize(this.getWidth(), this.getHeight());
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
this.add(applet, "Center");
|
this.add(applet, "Center");
|
||||||
|
|
||||||
applet.init();
|
applet.init();
|
||||||
|
|
||||||
active = true;
|
this.active = true;
|
||||||
|
|
||||||
applet.start();
|
applet.start();
|
||||||
|
|
||||||
validate();
|
this.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return this.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getDocumentBase() {
|
public URL getDocumentBase() {
|
||||||
return documentBase;
|
return this.documentBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -149,7 +149,7 @@ public final class Launcher extends Applet implements AppletStub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParameter(String name) {
|
public String getParameter(String name) {
|
||||||
String param = params.get(name);
|
String param = this.params.get(name);
|
||||||
|
|
||||||
if (param != null)
|
if (param != null)
|
||||||
return param;
|
return param;
|
||||||
@ -164,49 +164,49 @@ public final class Launcher extends Applet implements AppletStub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
wrappedApplet.resize(width, height);
|
this.wrappedApplet.resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(Dimension size) {
|
public void resize(Dimension size) {
|
||||||
wrappedApplet.resize(size);
|
this.wrappedApplet.resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
if (wrappedApplet != null)
|
if (this.wrappedApplet != null)
|
||||||
wrappedApplet.init();
|
this.wrappedApplet.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
wrappedApplet.start();
|
this.wrappedApplet.start();
|
||||||
|
|
||||||
active = true;
|
this.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
wrappedApplet.stop();
|
this.wrappedApplet.stop();
|
||||||
|
|
||||||
active = false;
|
this.active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
wrappedApplet.destroy();
|
this.wrappedApplet.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appletResize(int width, int height) {
|
public void appletResize(int width, int height) {
|
||||||
wrappedApplet.resize(width, height);
|
this.wrappedApplet.resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVisible(boolean visible) {
|
public void setVisible(boolean visible) {
|
||||||
super.setVisible(visible);
|
super.setVisible(visible);
|
||||||
|
|
||||||
wrappedApplet.setVisible(visible);
|
this.wrappedApplet.setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -218,7 +218,7 @@ public final class Launcher extends Applet implements AppletStub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setParameter(String name, String value) {
|
public void setParameter(String name, String value) {
|
||||||
params.put(name, value);
|
this.params.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,21 +75,21 @@ public final class StandardLauncher extends AbstractLauncher {
|
|||||||
// mcparams.add("--fullscreen");
|
// mcparams.add("--fullscreen");
|
||||||
|
|
||||||
if (!this.maximize) {
|
if (!this.maximize) {
|
||||||
mcParams.add("--width");
|
this.mcParams.add("--width");
|
||||||
mcParams.add(Integer.toString(width));
|
this.mcParams.add(Integer.toString(this.width));
|
||||||
mcParams.add("--height");
|
this.mcParams.add("--height");
|
||||||
mcParams.add(Integer.toString(height));
|
this.mcParams.add(Integer.toString(this.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.serverAddress != null) {
|
if (this.serverAddress != null) {
|
||||||
mcParams.add("--server");
|
this.mcParams.add("--server");
|
||||||
mcParams.add(serverAddress);
|
this.mcParams.add(this.serverAddress);
|
||||||
mcParams.add("--port");
|
this.mcParams.add("--port");
|
||||||
mcParams.add(serverPort);
|
this.mcParams.add(this.serverPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName);
|
MethodHandle method = ReflectionUtils.findMainMethod(this.mainClassName);
|
||||||
method.invokeExact(mcParams.toArray(new String[0]));
|
method.invokeExact(this.mcParams.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,17 +85,17 @@ public final class LegacyFrame extends JFrame {
|
|||||||
public LegacyFrame(String title, Applet applet) {
|
public LegacyFrame(String title, Applet applet) {
|
||||||
super(title);
|
super(title);
|
||||||
|
|
||||||
launcher = new Launcher(applet);
|
this.launcher = new Launcher(applet);
|
||||||
|
|
||||||
applet.setStub(launcher);
|
applet.setStub(this.launcher);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIconImage(ImageIO.read(new File("icon.png")));
|
this.setIconImage(ImageIO.read(new File("icon.png")));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.WARNING, "Unable to read Minecraft icon", e);
|
LOGGER.log(Level.WARNING, "Unable to read Minecraft icon", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
addWindowListener(new ForceExitHandler());
|
this.addWindowListener(new ForceExitHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(String user, String session, int width, int height, boolean maximize, String serverAddress,
|
public void start(String user, String session, int width, int height, boolean maximize, String serverAddress,
|
||||||
@ -119,9 +119,9 @@ public final class LegacyFrame extends JFrame {
|
|||||||
LOGGER.warning("Mpticket file is corrupted!");
|
LOGGER.warning("Mpticket file is corrupted!");
|
||||||
} else {
|
} else {
|
||||||
// Assumes parameters are valid and in the correct order
|
// Assumes parameters are valid and in the correct order
|
||||||
launcher.setParameter("server", lines.get(0));
|
this.launcher.setParameter("server", lines.get(0));
|
||||||
launcher.setParameter("port", lines.get(1));
|
this.launcher.setParameter("port", lines.get(1));
|
||||||
launcher.setParameter("mppass", lines.get(2));
|
this.launcher.setParameter("mppass", lines.get(2));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e);
|
LOGGER.log(Level.WARNING, "Unable to read mpticket file!", e);
|
||||||
@ -129,35 +129,35 @@ public final class LegacyFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (serverAddress != null) {
|
if (serverAddress != null) {
|
||||||
launcher.setParameter("server", serverAddress);
|
this.launcher.setParameter("server", serverAddress);
|
||||||
launcher.setParameter("port", serverPort);
|
this.launcher.setParameter("port", serverPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
launcher.setParameter("username", user);
|
this.launcher.setParameter("username", user);
|
||||||
launcher.setParameter("sessionid", session);
|
this.launcher.setParameter("sessionid", session);
|
||||||
launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work?
|
this.launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work?
|
||||||
launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work.
|
this.launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work.
|
||||||
launcher.setParameter("demo", isDemo ? "true" : "false");
|
this.launcher.setParameter("demo", isDemo ? "true" : "false");
|
||||||
launcher.setParameter("fullscreen", "false");
|
this.launcher.setParameter("fullscreen", "false");
|
||||||
|
|
||||||
add(launcher);
|
this.add(this.launcher);
|
||||||
|
|
||||||
launcher.setPreferredSize(new Dimension(width, height));
|
this.launcher.setPreferredSize(new Dimension(width, height));
|
||||||
|
|
||||||
pack();
|
this.pack();
|
||||||
|
|
||||||
setLocationRelativeTo(null);
|
this.setLocationRelativeTo(null);
|
||||||
setResizable(true);
|
this.setResizable(true);
|
||||||
|
|
||||||
if (maximize)
|
if (maximize)
|
||||||
setExtendedState(MAXIMIZED_BOTH);
|
setExtendedState(MAXIMIZED_BOTH);
|
||||||
|
|
||||||
validate();
|
this.validate();
|
||||||
|
|
||||||
launcher.init();
|
this.launcher.init();
|
||||||
launcher.start();
|
this.launcher.start();
|
||||||
|
|
||||||
setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class ForceExitHandler extends WindowAdapter {
|
private final class ForceExitHandler extends WindowAdapter {
|
||||||
@ -179,9 +179,9 @@ public final class LegacyFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
if (launcher != null) {
|
if (LegacyFrame.this.launcher != null) {
|
||||||
launcher.stop();
|
LegacyFrame.this.launcher.stop();
|
||||||
launcher.destroy();
|
LegacyFrame.this.launcher.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// old minecraft versions can hang without this >_<
|
// old minecraft versions can hang without this >_<
|
||||||
|
@ -84,15 +84,15 @@ public final class LegacyLauncher extends AbstractLauncher {
|
|||||||
public LegacyLauncher(Parameters params) {
|
public LegacyLauncher(Parameters params) {
|
||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
user = params.getString("userName");
|
this.user = params.getString("userName");
|
||||||
session = params.getString("sessionId");
|
this.session = params.getString("sessionId");
|
||||||
title = params.getString("windowTitle", "Minecraft");
|
this.title = params.getString("windowTitle", "Minecraft");
|
||||||
appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet");
|
this.appletClass = params.getString("appletClass", "net.minecraft.client.MinecraftApplet");
|
||||||
|
|
||||||
List<String> traits = params.getList("traits", Collections.<String>emptyList());
|
List<String> traits = params.getList("traits", Collections.<String>emptyList());
|
||||||
usesApplet = !traits.contains("noapplet");
|
this.usesApplet = !traits.contains("noapplet");
|
||||||
|
|
||||||
cwd = System.getProperty("user.dir");
|
this.cwd = System.getProperty("user.dir");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,14 +104,14 @@ public final class LegacyLauncher extends AbstractLauncher {
|
|||||||
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(this.cwd));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.usesApplet) {
|
if (this.usesApplet) {
|
||||||
LOGGER.info("Launching legacy minecraft using applet wrapper...");
|
LOGGER.info("Launching legacy minecraft using applet wrapper...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LegacyFrame window = new LegacyFrame(title, ReflectionUtils.createAppletClass(this.appletClass));
|
LegacyFrame window = new LegacyFrame(this.title, ReflectionUtils.createAppletClass(this.appletClass));
|
||||||
|
|
||||||
window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress,
|
window.start(this.user, this.session, this.width, this.height, this.maximize, this.serverAddress,
|
||||||
this.serverPort, this.mcParams.contains("--demo"));
|
this.serverPort, this.mcParams.contains("--demo"));
|
||||||
@ -123,7 +123,7 @@ public final class LegacyLauncher extends AbstractLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MethodHandle method = ReflectionUtils.findMainEntrypoint(main);
|
MethodHandle method = ReflectionUtils.findMainEntrypoint(main);
|
||||||
method.invokeExact(mcParams.toArray(new String[0]));
|
method.invokeExact(this.mcParams.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,19 +67,19 @@ public final class Parameters {
|
|||||||
private final Map<String, List<String>> map = new HashMap<>();
|
private final Map<String, List<String>> map = new HashMap<>();
|
||||||
|
|
||||||
public void add(String key, String value) {
|
public void add(String key, String value) {
|
||||||
List<String> params = map.get(key);
|
List<String> params = this.map.get(key);
|
||||||
|
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
params = new ArrayList<>();
|
params = new ArrayList<>();
|
||||||
|
|
||||||
map.put(key, params);
|
this.map.put(key, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
params.add(value);
|
params.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getList(String key) throws ParameterNotFoundException {
|
public List<String> getList(String key) throws ParameterNotFoundException {
|
||||||
List<String> params = map.get(key);
|
List<String> params = this.map.get(key);
|
||||||
|
|
||||||
if (params == null)
|
if (params == null)
|
||||||
throw ParameterNotFoundException.forParameterName(key);
|
throw ParameterNotFoundException.forParameterName(key);
|
||||||
@ -88,7 +88,7 @@ public final class Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getList(String key, List<String> def) {
|
public List<String> getList(String key, List<String> def) {
|
||||||
List<String> params = map.get(key);
|
List<String> params = this.map.get(key);
|
||||||
|
|
||||||
if (params == null || params.isEmpty())
|
if (params == null || params.isEmpty())
|
||||||
return def;
|
return def;
|
||||||
@ -97,7 +97,7 @@ public final class Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String key) throws ParameterNotFoundException {
|
public String getString(String key) throws ParameterNotFoundException {
|
||||||
List<String> list = getList(key);
|
List<String> list = this.getList(key);
|
||||||
|
|
||||||
if (list.isEmpty())
|
if (list.isEmpty())
|
||||||
throw ParameterNotFoundException.forParameterName(key);
|
throw ParameterNotFoundException.forParameterName(key);
|
||||||
@ -106,7 +106,7 @@ public final class Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String key, String def) {
|
public String getString(String key, String def) {
|
||||||
List<String> params = map.get(key);
|
List<String> params = this.map.get(key);
|
||||||
|
|
||||||
if (params == null || params.isEmpty())
|
if (params == null || params.isEmpty())
|
||||||
return def;
|
return def;
|
||||||
|
Loading…
Reference in New Issue
Block a user