Add -uuid flag as an alternative to -server quicklaunch arg

This commit is contained in:
Shadowrs
2018-08-28 14:35:51 +01:00
parent 82f3224c36
commit 812e2daa3b
5 changed files with 28 additions and 6 deletions
+3
View File
@@ -135,6 +135,9 @@ public final class Landing {
case "-no_validation":
Core.disableValidation();
break;
case "-uuid":
Core.quickLaunchByUuid = Integer.parseInt(args[++i]);
break;
}
}
}
+2 -1
View File
@@ -28,7 +28,8 @@ import java.security.NoSuchAlgorithmException;
@SuppressWarnings("Duplicates")
public class Core {
private static boolean debug;
public static int quickLaunchByUuid; // used like -server, but denoted by an Int rather than the server name
private static boolean debug; // in debug mode, we will print more detailed error messages.
private static boolean verbose;
private static boolean dump;
private static boolean loadLocal; //Loads both local and public scripts/servers
@@ -9,6 +9,7 @@ public class ServerDescription implements Comparable<ServerDescription> {
private String serverName;
private String author;
private double revision;
public int uuid;
public ServerDescription(final String serverName, final String author,
final double revision) {
@@ -86,17 +86,24 @@ public class LocalServers extends ServerParser {
if ((bank = object.get("bank")) != null) {
bankTabs = (int) bank;
}
String uuidStr = (String) object.get("uuid"); // optional
JSONObject locations = (JSONObject) object.get("locations");
String server = (String) locations.get("server");
String provider = (String) locations.get("provider");
String hooks = (String) locations.get("hooks");
Core.verbose("[Local server]: " + name);
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(server, hooks, name, clientClass, bankTabs);
ServerDescription desc = new ServerDescription(name,
author, version);
ServerDescription desc = new ServerDescription(name, author, version);
if (uuidStr != null && uuidStr.length() > 0) {
desc.uuid = Integer.parseInt(uuidStr);
}
SERVER_CACHE.put(desc, new LocalPublicServerExecuter(name, serverProviderInfo, server, provider));
} catch (IOException | ParseException e) {
e.printStackTrace();
@@ -1,5 +1,6 @@
package org.parabot.core.ui;
import org.parabot.core.Core;
import org.parabot.core.desc.ServerDescription;
import org.parabot.core.parsers.servers.ServerParser;
import org.parabot.core.ui.components.ServerComponent;
@@ -23,7 +24,7 @@ public class ServerSelector extends JPanel {
public ServerSelector() {
Queue<ServerComponent> widgets = getServers();
if (initServer != null) {
if (initServer != null || Core.quickLaunchByUuid > 0) {
if (runServer(widgets)) {
initServer = null;
return;
@@ -67,7 +68,7 @@ public class ServerSelector extends JPanel {
}
/**
* This method is called when -server argument is given
* This method is called when -server argument is given, or -uuid arg is given.
*
* @param widgets
*/
@@ -75,7 +76,16 @@ public class ServerSelector extends JPanel {
if (widgets == null || widgets.isEmpty()) {
return false;
}
final String serverName = initServer.toLowerCase();
if (Core.quickLaunchByUuid > 0) { // match the pre-requested server config uuid to quick-launch
for (ServerComponent widget : widgets) {
if (widget.desc.uuid == Core.quickLaunchByUuid) {
Environment.load(widget.desc);
return true;
}
}
}
final String serverName = initServer.toLowerCase(); // match the pre-requested server name to quick-launch
for (ServerComponent widget : widgets) {
if (widget.desc.getServerName().toLowerCase().equals(serverName)) {
Environment.load(widget.desc);