Merge branch 'development' into feature/override-randoms

This commit is contained in:
Jak
2018-09-12 12:21:33 +01:00
committed by GitHub
5 changed files with 44 additions and 10 deletions
+3
View File
@@ -135,6 +135,9 @@ public final class Landing {
case "-no_validation": case "-no_validation":
Core.disableValidation(); Core.disableValidation();
break; break;
case "-uuid":
Core.setQuickLaunchByUuid(Integer.parseInt(args[++i]));
break;
} }
} }
} }
+10 -1
View File
@@ -28,7 +28,8 @@ import java.security.NoSuchAlgorithmException;
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public class Core { public class Core {
private static boolean debug; private static int quickLaunchByUuid = -1; // 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 verbose;
private static boolean dump; private static boolean dump;
private static boolean loadLocal; //Loads both local and public scripts/servers private static boolean loadLocal; //Loads both local and public scripts/servers
@@ -46,6 +47,14 @@ public class Core {
return validate; return validate;
} }
public static int getQuickLaunchByUuid() {
return quickLaunchByUuid;
}
public static void setQuickLaunchByUuid(int quickLaunchByUuid) {
Core.quickLaunchByUuid = quickLaunchByUuid;
}
/** /**
* Enabled loadLocal mode * Enabled loadLocal mode
* *
@@ -9,6 +9,7 @@ public class ServerDescription implements Comparable<ServerDescription> {
private String serverName; private String serverName;
private String author; private String author;
private double revision; private double revision;
public int uuid;
public ServerDescription(final String serverName, final String author, public ServerDescription(final String serverName, final String author,
final double revision) { final double revision) {
@@ -86,21 +86,28 @@ public class LocalServers extends ServerParser {
if ((bank = object.get("bank")) != null) { if ((bank = object.get("bank")) != null) {
bankTabs = (int) bank; bankTabs = (int) bank;
} }
String uuidStr = (String) object.get("uuid"); // optional
JSONObject locations = (JSONObject) object.get("locations"); JSONObject locations = (JSONObject) object.get("locations");
String server = (String) locations.get("server"); String server = (String) locations.get("server");
String provider = (String) locations.get("provider"); String provider = (String) locations.get("provider");
String hooks = (String) locations.get("hooks"); String hooks = (String) locations.get("hooks");
String randoms = (String) locations.get("randoms"); String randoms = (String) locations.get("randoms");
if (randoms == null) { if (randoms == null) {
randoms = Configuration.GET_RANDOMS + (Configuration.BOT_VERSION.isNightly() ? Configuration.NIGHTLY_APPEND : ""); randoms = Configuration.GET_RANDOMS + (Configuration.BOT_VERSION.isNightly() ? Configuration.NIGHTLY_APPEND : "");
} }
Core.verbose("[LocalServers]: Parsed server: " + name); Core.verbose("[LocalServers]: Parsed server: " + name);
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(server, hooks, name, clientClass, bankTabs, randoms); ServerProviderInfo serverProviderInfo = new ServerProviderInfo(server, hooks, name, clientClass, bankTabs, randoms);
ServerDescription desc = new ServerDescription(name, ServerDescription desc = new ServerDescription(name, author, version);
author, version); if (uuidStr != null && uuidStr.length() > 0) {
desc.uuid = Integer.parseInt(uuidStr);
}
SERVER_CACHE.put(desc, new LocalPublicServerExecuter(name, serverProviderInfo, server, provider)); SERVER_CACHE.put(desc, new LocalPublicServerExecuter(name, serverProviderInfo, server, provider));
} catch (IOException | ParseException e) { } catch (IOException | ParseException e) {
e.printStackTrace(); e.printStackTrace();
@@ -1,5 +1,6 @@
package org.parabot.core.ui; package org.parabot.core.ui;
import org.parabot.core.Core;
import org.parabot.core.desc.ServerDescription; import org.parabot.core.desc.ServerDescription;
import org.parabot.core.parsers.servers.ServerParser; import org.parabot.core.parsers.servers.ServerParser;
import org.parabot.core.ui.components.ServerComponent; import org.parabot.core.ui.components.ServerComponent;
@@ -23,7 +24,7 @@ public class ServerSelector extends JPanel {
public ServerSelector() { public ServerSelector() {
Queue<ServerComponent> widgets = getServers(); Queue<ServerComponent> widgets = getServers();
if (initServer != null) { if (initServer != null || Core.getQuickLaunchByUuid() > -1) {
if (runServer(widgets)) { if (runServer(widgets)) {
initServer = null; initServer = null;
return; 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 * @param widgets
*/ */
@@ -75,12 +76,25 @@ public class ServerSelector extends JPanel {
if (widgets == null || widgets.isEmpty()) { if (widgets == null || widgets.isEmpty()) {
return false; return false;
} }
final String serverName = initServer.toLowerCase(); if (Core.getQuickLaunchByUuid() > -1) { // match the pre-requested server config uuid to quick-launch
for (ServerComponent widget : widgets) { for (ServerComponent widget : widgets) {
if (widget.desc.getServerName().toLowerCase().equals(serverName)) { if (widget.desc.uuid == Core.getQuickLaunchByUuid()) {
Environment.load(widget.desc); Environment.load(widget.desc);
return true; return true;
}
} }
System.err.println("No server config with -uuid " + Core.getQuickLaunchByUuid() + " was found to quick launch.");
}
if (initServer != null) {
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);
return true;
}
}
System.err.println("No server config with -server " + serverName + " was found to quick launch.");
} }
return false; return false;
} }