mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-02 16:49:10 +00:00
2006Scape Changes
Remove Need For Server JSON Remove "servers" Folder Remove Some Unused Methods
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
package org.parabot;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.network.NetworkInterface;
|
||||
import org.parabot.core.network.proxy.ProxySocket;
|
||||
import org.parabot.core.network.proxy.ProxyType;
|
||||
import org.parabot.core.ui.BotUI;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.Environment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -45,9 +48,9 @@ public final class Landing {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
Core.verbose("Starting 2006Scape...");
|
||||
ServerSelector.initServer = "2006Scape";
|
||||
Core.verbose("Starting " + Configuration.serverName + "...");
|
||||
new BotUI();
|
||||
|
||||
}
|
||||
|
||||
private static void parseArgs(String... args) {
|
||||
@@ -70,9 +73,6 @@ public final class Landing {
|
||||
case "-scriptsbin":
|
||||
Directories.setScriptCompiledDirectory(new File(args[++i]));
|
||||
break;
|
||||
case "-serversbin":
|
||||
Directories.setServerCompiledDirectory(new File(args[++i]));
|
||||
break;
|
||||
case "-clearcache":
|
||||
Directories.clearCache();
|
||||
break;
|
||||
|
||||
@@ -39,7 +39,6 @@ public class Directories {
|
||||
cached.put("Compiled", new File(cached.get("Root"), "/2006Scape/scripts/compiled/"));
|
||||
cached.put("Resources", new File(cached.get("Root"), "/2006Scape/scripts/resources/"));
|
||||
cached.put("Settings", new File(cached.get("Root"), "/2006Scape/settings/"));
|
||||
cached.put("Servers", new File(cached.get("Root"), "/2006Scape/servers/"));
|
||||
cached.put("Cache", new File(cached.get("Root"), "/2006Scape/cache/"));
|
||||
cached.put("Screenshots", new File(cached.get("Root"), "/2006Scape/screenshots/"));
|
||||
Verboser.verbose("Directories cached.");
|
||||
@@ -59,18 +58,6 @@ public class Directories {
|
||||
cached.put("Compiled", f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set server bin folder
|
||||
*
|
||||
* @param f
|
||||
*/
|
||||
public static void setServerCompiledDirectory(File f) {
|
||||
if (!f.isDirectory()) {
|
||||
throw new IllegalArgumentException(f + "is not a directory.");
|
||||
}
|
||||
cached.put("Servers", f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root directory outside of the main Parabot folder.
|
||||
*
|
||||
@@ -125,15 +112,6 @@ public class Directories {
|
||||
return cached.get("Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Parabot servers folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getServerPath() {
|
||||
return cached.get("Servers");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Parabot cache folder.
|
||||
*
|
||||
|
||||
@@ -19,4 +19,12 @@ public class Configuration extends org.parabot.api.Configuration {
|
||||
public static final String ITEM_API = DATA_API + "items/";
|
||||
|
||||
public static final Version BOT_VERSION = ProjectProperties.getProjectVersion();
|
||||
|
||||
public static final String serverName = "2006Scape";
|
||||
public static final String clientJar = "https://2006scape.org/Downloads/client.jar";
|
||||
public static final String hooksFile = "https://2006scape.org/Downloads/bot/2006Scape_hooks.xml";
|
||||
public static final String providerJar = "https://2006scape.org/Downloads/bot/Provider.jar";
|
||||
public static final String clientClass = "Game";
|
||||
public static final Double clientVersion = 1.0;
|
||||
|
||||
}
|
||||
|
||||
@@ -286,9 +286,7 @@ public class ClassPath {
|
||||
/**
|
||||
* Dumps a resource from a input stream
|
||||
*
|
||||
* @param classPath
|
||||
* @param name
|
||||
* @param inputstream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.parabot.core.desc;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
|
||||
/**
|
||||
* Holds information about a server
|
||||
*
|
||||
@@ -11,11 +13,10 @@ public class ServerDescription implements Comparable<ServerDescription> {
|
||||
private final double revision;
|
||||
public int uuid;
|
||||
|
||||
public ServerDescription(final String serverName, final String author,
|
||||
final double revision) {
|
||||
this.serverName = serverName;
|
||||
this.author = author;
|
||||
this.revision = revision;
|
||||
public ServerDescription() {
|
||||
this.serverName = Configuration.serverName;
|
||||
this.author = Configuration.serverName;
|
||||
this.revision = Configuration.clientVersion;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package org.parabot.core.desc;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
@@ -22,74 +18,9 @@ import java.util.zip.CRC32;
|
||||
*/
|
||||
public class ServerProviderInfo {
|
||||
|
||||
private final HashMap<String, Integer> settings;
|
||||
private final Properties properties;
|
||||
|
||||
public ServerProviderInfo(URL providerInfo, String username, String password) {
|
||||
this.properties = new Properties();
|
||||
this.settings = new HashMap<>();
|
||||
try {
|
||||
Core.verbose("Reading info: " + providerInfo);
|
||||
BufferedReader br = WebUtil.getReader(new URL(providerInfo.toString()), username, password);
|
||||
|
||||
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(br);
|
||||
for (Object o : jsonObject.entrySet()) {
|
||||
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) o;
|
||||
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")) {
|
||||
JSONObject object = (JSONObject) pairs.getValue();
|
||||
parseSettings(object);
|
||||
} else {
|
||||
properties.put(String.valueOf(pairs.getKey()), String.valueOf(pairs.getValue()));
|
||||
}
|
||||
}
|
||||
if (br != null) {
|
||||
br.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /2006Scape/servers/config.json} file.
|
||||
*
|
||||
* @param clientJar Name of the client jar file
|
||||
* @param hooks Name of the hooks file
|
||||
* @param name Server name
|
||||
* @param clientClass Entry class within the client jar
|
||||
* @param bankTabs Bank tabs - only relevant for certain servers. Default 0
|
||||
*/
|
||||
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs) {
|
||||
this(clientJar, hooks, name, clientClass, bankTabs, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /2006Scape/servers/config.json} file.
|
||||
*
|
||||
* @param clientJar Name of the client jar file
|
||||
* @param hooks Name of the hooks file
|
||||
* @param name Server name
|
||||
* @param clientClass Entry class within the client jar
|
||||
* @param bankTabs Bank tabs - only relevant for certain servers. Default 0
|
||||
* @param randoms A URL to an endpoint where the Randoms are located. Can be Null, in which case getRandoms() will fallback to the default BDN Randoms URL.
|
||||
*/
|
||||
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs, String randoms) {
|
||||
this.properties = new Properties();
|
||||
this.settings = new HashMap<>();
|
||||
|
||||
this.properties.setProperty("client_jar", clientJar);
|
||||
this.properties.setProperty("hooks", hooks);
|
||||
this.properties.setProperty("name", name);
|
||||
this.properties.setProperty("client_class", clientClass);
|
||||
this.properties.setProperty("provider_crc32", String.valueOf(getCRC32(name, "provider")));
|
||||
this.properties.setProperty("client_crc32", String.valueOf(getCRC32(name, "client")));
|
||||
this.properties.setProperty("bank_tabs", String.valueOf(bankTabs));
|
||||
this.properties.setProperty("randoms_jar", randoms);
|
||||
}
|
||||
|
||||
public URL getClient() {
|
||||
try {
|
||||
return new URL(properties.getProperty("client_jar"));
|
||||
return new URL(Configuration.clientJar);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -98,7 +29,7 @@ public class ServerProviderInfo {
|
||||
|
||||
public URL getExtendedHookFile() {
|
||||
try {
|
||||
return new URL(properties.getProperty("hooks") /*+ "&extended=true"*/);
|
||||
return new URL(Configuration.hooksFile /*+ "&extended=true"*/);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
return getHookFile();
|
||||
@@ -107,7 +38,7 @@ public class ServerProviderInfo {
|
||||
|
||||
public URL getHookFile() {
|
||||
try {
|
||||
return new URL(properties.getProperty("hooks"));
|
||||
return new URL(Configuration.hooksFile);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -115,31 +46,19 @@ public class ServerProviderInfo {
|
||||
}
|
||||
|
||||
public String getClientClass() {
|
||||
return properties.getProperty("client_class");
|
||||
return Configuration.clientClass;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return properties.getProperty("name");
|
||||
return Configuration.serverName;
|
||||
}
|
||||
|
||||
public long getCRC32() {
|
||||
return Long.parseLong(properties.getProperty("provider_crc32"));
|
||||
return Long.parseLong(String.valueOf(getCRC32(Configuration.serverName, "provider")));
|
||||
}
|
||||
|
||||
public long getClientCRC32() {
|
||||
return Long.parseLong(properties.getProperty("client_crc32"));
|
||||
}
|
||||
|
||||
public int getBankTabs() {
|
||||
return Integer.parseInt(properties.getProperty("bank_tabs"));
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getSettings() {
|
||||
return settings;
|
||||
return Long.parseLong(String.valueOf(getCRC32(Configuration.serverName, "client")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,16 +68,11 @@ public class ServerProviderInfo {
|
||||
*/
|
||||
public URL getRandoms() {
|
||||
try {
|
||||
String randomsUrl = properties.getProperty("randoms_jar");
|
||||
if (randomsUrl == null || randomsUrl.length() == 0) {
|
||||
// Fallback to default BDN URL if there is no 'randoms' specified in the server JSON configuration.
|
||||
randomsUrl = Configuration.GET_RANDOMS;
|
||||
}
|
||||
String randomsUrl = Configuration.GET_RANDOMS;
|
||||
return new URL(randomsUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Will never return null, unless the BDN URL is changed. It shouldn't be.
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -168,7 +82,7 @@ public class ServerProviderInfo {
|
||||
* @return provider version
|
||||
*/
|
||||
public String getProviderVersion() {
|
||||
String providerType = WebUtil.getJsonValue(String.format(Configuration.GET_SERVER_PROVIDER_TYPE, properties.getProperty("name")), "type");
|
||||
String providerType = WebUtil.getJsonValue(String.format(Configuration.GET_SERVER_PROVIDER_TYPE, Configuration.serverName), "type");
|
||||
if (providerType != null) {
|
||||
String providerInfo = String.format(Configuration.SERVER_PROVIDER_INFO, providerType);
|
||||
return WebUtil.getJsonValue(providerInfo, "version");
|
||||
@@ -183,13 +97,4 @@ public class ServerProviderInfo {
|
||||
crc.update(name.getBytes());
|
||||
return crc.getValue();
|
||||
}
|
||||
|
||||
private void parseSettings(JSONObject object) {
|
||||
for (Object settingObject : object.entrySet()) {
|
||||
Map.Entry<?, ?> settingValue = (Map.Entry<?, ?>) settingObject;
|
||||
String key = (String) settingValue.getKey();
|
||||
long value = (Long) settingValue.getValue();
|
||||
settings.put(key, (int) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-15
@@ -1,7 +1,8 @@
|
||||
package org.parabot.core.parsers.servers;
|
||||
package org.parabot.core.parsers;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.environment.servers.executers.LocalPublicServerExecuter;
|
||||
import org.parabot.environment.servers.executers.ServerExecuter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -19,20 +20,8 @@ public abstract class ServerParser {
|
||||
|
||||
public static final ServerDescription[] getDescriptions() {
|
||||
SERVER_CACHE.clear();
|
||||
final ArrayList<ServerParser> parsers = new ArrayList<>();
|
||||
parsers.add(new LocalServers());
|
||||
|
||||
Core.verbose("Parsing server providers...");
|
||||
for (final ServerParser parser : parsers) {
|
||||
parser.execute();
|
||||
}
|
||||
|
||||
if (Core.inVerboseMode()) {
|
||||
for (final ServerDescription desc : SERVER_CACHE.keySet()) {
|
||||
Core.verbose(desc.toString());
|
||||
}
|
||||
Core.verbose("Server providers parsed.");
|
||||
}
|
||||
ServerDescription desc = new ServerDescription();
|
||||
SERVER_CACHE.put(desc, new LocalPublicServerExecuter());
|
||||
|
||||
Map<ServerDescription, ServerExecuter> SORTED_SERVER_CACHE = new TreeMap<ServerDescription, ServerExecuter>(SERVER_CACHE);
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
package org.parabot.core.parsers.servers;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.desc.ServerProviderInfo;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.servers.ServerManifest;
|
||||
import org.parabot.environment.servers.executers.LocalPublicServerExecuter;
|
||||
import org.parabot.environment.servers.executers.LocalServerExecuter;
|
||||
import org.parabot.environment.servers.loader.ServerLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Parses local server providers located in the servers directory
|
||||
*
|
||||
* @author Everel, JKetelaar
|
||||
*/
|
||||
public class LocalServers extends ServerParser {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
// parse classes in server directories
|
||||
final ClassPath basePath = new ClassPath();
|
||||
basePath.parseJarFiles(false);
|
||||
basePath.addClasses(Directories.getServerPath());
|
||||
|
||||
final ArrayList<ClassPath> classPaths = new ArrayList<>();
|
||||
classPaths.add(basePath);
|
||||
for (final ClassPath classPath : basePath.getJarFiles()) {
|
||||
classPaths.add(classPath);
|
||||
}
|
||||
|
||||
for (final ClassPath path : classPaths) {
|
||||
// init the server loader
|
||||
final ServerLoader loader = new ServerLoader(path);
|
||||
|
||||
// loop through all classes which extends the 'ServerProvider' class
|
||||
for (final String className : loader.getServerClassNames()) {
|
||||
try {
|
||||
// get class
|
||||
final Class<?> serverProviderClass = loader
|
||||
.loadClass(className);
|
||||
// get annotation
|
||||
final Object annotation = serverProviderClass
|
||||
.getAnnotation(ServerManifest.class);
|
||||
if (annotation == null) {
|
||||
throw new RuntimeException("Missing manifest at "
|
||||
+ className);
|
||||
}
|
||||
// cast object annotation to server manifest annotation
|
||||
final ServerManifest manifest = (ServerManifest) annotation;
|
||||
// get constructor
|
||||
final Constructor<?> con = serverProviderClass
|
||||
.getConstructor();
|
||||
|
||||
SERVER_CACHE.put(
|
||||
new ServerDescription(manifest.name(), manifest
|
||||
.author(), manifest.version()),
|
||||
new LocalServerExecuter(con, path,
|
||||
manifest.name()));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (File file : Directories.listJSONFiles(Directories.getServerPath())) {
|
||||
Core.verbose("[Local server in]: " + file.getName());
|
||||
try {
|
||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(new FileReader(file));
|
||||
String name = (String) object.get("name");
|
||||
String author = (String) object.get("author");
|
||||
double version = (Double) object.get("version");
|
||||
String clientClass = (String) object.get("client-class");
|
||||
Object bank;
|
||||
int bankTabs = 0;
|
||||
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");
|
||||
String randoms = (String) locations.get("randoms");
|
||||
|
||||
if (randoms == null) {
|
||||
randoms = Configuration.GET_RANDOMS;
|
||||
}
|
||||
|
||||
Core.verbose("[LocalServers]: Parsed server: " + name);
|
||||
|
||||
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(server, hooks, name, clientClass, bankTabs, randoms);
|
||||
|
||||
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,8 +1,9 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.parsers.servers.ServerParser;
|
||||
import org.parabot.core.parsers.ServerParser;
|
||||
import org.parabot.core.ui.components.ServerComponent;
|
||||
import org.parabot.environment.Environment;
|
||||
|
||||
@@ -22,7 +23,7 @@ import javax.swing.JScrollPane;
|
||||
|
||||
public class ServerSelector extends JPanel {
|
||||
private static final long serialVersionUID = 5238720307271493899L;
|
||||
public static String initServer;
|
||||
public static String initServer = Configuration.serverName;
|
||||
private static ServerSelector instance;
|
||||
|
||||
public ServerSelector() {
|
||||
|
||||
@@ -1,41 +1,24 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.ui.fonts.Fonts;
|
||||
import org.parabot.environment.Environment;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* A neat looking server component
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
public class ServerComponent extends JPanel implements MouseListener,
|
||||
MouseMotionListener {
|
||||
public class ServerComponent extends JPanel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final String name;
|
||||
public ServerDescription desc;
|
||||
private boolean hovered;
|
||||
|
||||
public ServerComponent(final ServerDescription desc) {
|
||||
this.desc = desc;
|
||||
setLayout(null);
|
||||
this.name = desc.getServerName().replaceAll(" ", "");
|
||||
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,41 +26,8 @@ public class ServerComponent extends JPanel implements MouseListener,
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
setOpaque(false);
|
||||
super.paintComponent(g);
|
||||
setOpaque(true);
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
|
||||
Color bgColor = Color.LIGHT_GRAY;
|
||||
if (hovered) {
|
||||
bgColor = Color.GRAY;
|
||||
}
|
||||
|
||||
g2d.setColor(bgColor);
|
||||
g2d.fillRect(0, 0, w, h);
|
||||
g.setColor(Color.black);
|
||||
Font title = Fonts.getResource("leelawadee.ttf", 16);
|
||||
g.setFont(title);
|
||||
String serverName = desc.getServerName();
|
||||
int sw = g.getFontMetrics().stringWidth(serverName);
|
||||
g.drawString(serverName, (w / 2) - (sw / 2), 30);
|
||||
|
||||
Font normal = Fonts.getResource("leelawadee.ttf");
|
||||
g.setFont(normal);
|
||||
FontMetrics fm = g.getFontMetrics();
|
||||
String author = "Author: " + desc.getAuthor();
|
||||
String revision = "Revision: " + desc.getRevision();
|
||||
|
||||
g.drawString(author, (w / 2) - (fm.stringWidth(author) / 2), 55);
|
||||
g.drawString(revision, (w / 2) - (fm.stringWidth(revision) / 2), 70);
|
||||
}
|
||||
|
||||
public void load(final ServerDescription desc) {
|
||||
VerboseLoader.get().switchState(VerboseLoader.STATE_LOADING);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -86,44 +36,4 @@ public class ServerComponent extends JPanel implements MouseListener,
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
if (!hovered) {
|
||||
hovered = true;
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if (hovered) {
|
||||
hovered = false;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (hovered) {
|
||||
load(desc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +1,44 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.io.ProgressListener;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.core.ui.fonts.Fonts;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.RescaleOp;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
/**
|
||||
* An informative JPanel which tells the user what bot is doing
|
||||
*
|
||||
* @author Everel, EmmaStone
|
||||
*/
|
||||
public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
public static final int STATE_LOADING = 1;
|
||||
private static final long serialVersionUID = 7412412644921803896L;
|
||||
private static final int STATE_AUTHENTICATION = 0;
|
||||
private static final int STATE_SERVER_SELECT = 2;
|
||||
private static VerboseLoader current;
|
||||
private static String state = "Initializing loader...";
|
||||
private final BufferedImage background;
|
||||
private final BufferedImage banner;
|
||||
private final BufferedImage loginBox;
|
||||
private final ProgressBar progressBar;
|
||||
private int currentState;
|
||||
private FontMetrics fontMetrics;
|
||||
private JPanel loginPanel;
|
||||
|
||||
private VerboseLoader(String username, String password) {
|
||||
private VerboseLoader() {
|
||||
if (current != null) {
|
||||
throw new IllegalStateException("MainScreenComponent already made.");
|
||||
}
|
||||
current = this;
|
||||
this.background = Images.getResource("/storage/images/background.png");
|
||||
this.banner = Images.getResource("/storage/images/logo.png");
|
||||
this.loginBox = Images.getResource("/storage/images/login.png");
|
||||
this.progressBar = new ProgressBar(400, 20);
|
||||
setLayout(new GridBagLayout());
|
||||
setSize(775, 510);
|
||||
setPreferredSize(new Dimension(775, 510));
|
||||
setDoubleBuffered(true);
|
||||
setOpaque(false);
|
||||
|
||||
currentState = STATE_SERVER_SELECT; //Force Server Select
|
||||
|
||||
if (currentState == STATE_AUTHENTICATION) {
|
||||
addLoginPanel();
|
||||
} else if (currentState == STATE_SERVER_SELECT) {
|
||||
addServerPanel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
*
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static VerboseLoader get(String username, String password) {
|
||||
return current == null ? new VerboseLoader(username, password) : current;
|
||||
ServerSelector.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +47,7 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static VerboseLoader get() {
|
||||
return current == null ? new VerboseLoader(null, null) : current;
|
||||
return current == null ? new VerboseLoader() : current;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,101 +56,9 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
* @param message
|
||||
*/
|
||||
public static void setState(final String message) {
|
||||
state = message;
|
||||
current.repaint();
|
||||
}
|
||||
|
||||
public void addServerPanel() {
|
||||
JPanel servers = ServerSelector.getInstance();
|
||||
GridBagLayout bagLayout = (GridBagLayout) getLayout();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
c.weightx = 1;
|
||||
c.weighty = 1;
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.anchor = GridBagConstraints.SOUTH;
|
||||
c.insets = new Insets(0, 0, 25, 0);
|
||||
|
||||
bagLayout.setConstraints(servers, c);
|
||||
add(servers);
|
||||
}
|
||||
|
||||
public void addLoginPanel() {
|
||||
loginPanel = new JPanel();
|
||||
loginPanel.setOpaque(false);
|
||||
|
||||
loginPanel.setLayout(new BoxLayout(loginPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
Font labelFont = Fonts.getResource("leelawadee.ttf");
|
||||
|
||||
JLabel usernameLabel = new JLabel("Username");
|
||||
usernameLabel.setFont(labelFont);
|
||||
usernameLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
usernameLabel.setForeground(Color.white);
|
||||
|
||||
final JTextField userInput = new JTextField(20);
|
||||
final JTextField passInput = new JPasswordField(20);
|
||||
userInput.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
passInput.requestFocus();
|
||||
}
|
||||
|
||||
});
|
||||
userInput.setFont(labelFont);
|
||||
userInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
userInput.setMaximumSize(userInput.getPreferredSize());
|
||||
|
||||
final JButton login = new JButton("Login");
|
||||
|
||||
passInput.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
passInput.setMaximumSize(userInput.getPreferredSize());
|
||||
passInput.setPreferredSize(new Dimension(userInput.getWidth(), 20));
|
||||
passInput.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
login.doClick();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
JLabel passwordLabel = new JLabel("Password");
|
||||
passwordLabel.setFont(labelFont);
|
||||
passwordLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
passwordLabel.setForeground(Color.white);
|
||||
|
||||
login.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
login.setOpaque(false);
|
||||
|
||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 8)));
|
||||
loginPanel.add(usernameLabel);
|
||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||
loginPanel.add(userInput);
|
||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||
loginPanel.add(passwordLabel);
|
||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||
loginPanel.add(passInput);
|
||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 2)));
|
||||
loginPanel.add(login);
|
||||
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
||||
|
||||
add(loginPanel, new GridBagConstraints());
|
||||
}
|
||||
|
||||
public void switchState(int state) {
|
||||
removeAll();
|
||||
if (state == STATE_AUTHENTICATION) {
|
||||
addLoginPanel();
|
||||
} else if (state == STATE_SERVER_SELECT) {
|
||||
addServerPanel();
|
||||
}
|
||||
this.currentState = state;
|
||||
revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints on this panel
|
||||
*/
|
||||
@@ -237,19 +99,8 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
fontMetrics = g.getFontMetrics();
|
||||
}
|
||||
|
||||
if (currentState == STATE_AUTHENTICATION) {
|
||||
g.drawImage(loginBox, loginPanel.getX() - 30, loginPanel.getY() - 22, null);
|
||||
}
|
||||
|
||||
g.setColor(Color.white);
|
||||
|
||||
if (currentState == STATE_LOADING) {
|
||||
progressBar.draw(g, (getWidth() / 2) - 200, 220);
|
||||
g.setFont(Fonts.getResource("leelawadee.ttf"));
|
||||
int x = (getWidth() / 2) - (fontMetrics.stringWidth(state) / 2);
|
||||
g.drawString(state, x, 200);
|
||||
}
|
||||
|
||||
g.setFont(Fonts.getResource("leelawadee.ttf"));
|
||||
final String version = Configuration.BOT_VERSION.get();
|
||||
g.drawString(version,
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.parabot.core.Core;
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.lib.Library;
|
||||
import org.parabot.core.lib.javafx.JavaFX;
|
||||
import org.parabot.core.parsers.servers.ServerParser;
|
||||
import org.parabot.core.parsers.ServerParser;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package org.parabot.environment.servers;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.environment.servers.executers.ServerExecuter;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
* Loads locally stored server providers
|
||||
*
|
||||
@@ -34,14 +30,6 @@ public class LocalServerExecuter extends ServerExecuter {
|
||||
Core.verbose("Adding server provider jar to buildpath: "
|
||||
+ this.classPath.lastParsed.toString());
|
||||
this.classPath.addToBuildPath();
|
||||
} else {
|
||||
Core.verbose("Adding server providers directory to buildpath: "
|
||||
+ Directories.getServerPath().getPath());
|
||||
try {
|
||||
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// finalize
|
||||
super.finalize(this.serverProvider, this.serverName);
|
||||
|
||||
+6
-5
@@ -1,5 +1,6 @@
|
||||
package org.parabot.environment.servers.executers;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
@@ -30,11 +31,11 @@ public class LocalPublicServerExecuter extends ServerExecuter {
|
||||
private final String providerUrl;
|
||||
private final ServerProviderInfo serverProviderInfo;
|
||||
|
||||
public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) {
|
||||
this.serverName = serverName;
|
||||
this.serverUrl = serverUrl;
|
||||
this.providerUrl = providerUrl;
|
||||
this.serverProviderInfo = serverProviderInfo;
|
||||
public LocalPublicServerExecuter() {
|
||||
this.serverName = Configuration.serverName;
|
||||
this.serverUrl = Configuration.clientJar;
|
||||
this.providerUrl = Configuration.providerJar;
|
||||
this.serverProviderInfo = new ServerProviderInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.parabot.environment.servers.executers;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
* Loads locally stored server providers
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
public class LocalServerExecuter extends ServerExecuter {
|
||||
private final Constructor<?> serverProviderConstructor;
|
||||
private final ClassPath classPath;
|
||||
private final String serverName;
|
||||
|
||||
public LocalServerExecuter(Constructor<?> serverProviderConstructor,
|
||||
ClassPath classPath, final String serverName) {
|
||||
this.serverProviderConstructor = serverProviderConstructor;
|
||||
this.classPath = classPath;
|
||||
this.serverName = serverName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// add jar or directory to buildpath.
|
||||
if (this.classPath.isJar()) {
|
||||
Core.verbose("Adding server provider jar to buildpath: "
|
||||
+ this.classPath.lastParsed.toString());
|
||||
this.classPath.addToBuildPath();
|
||||
} else {
|
||||
Core.verbose("Adding server providers directory to buildpath: "
|
||||
+ Directories.getServerPath().getPath());
|
||||
try {
|
||||
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// finalize
|
||||
try {
|
||||
super.finalize((ServerProvider) serverProviderConstructor.newInstance(), this.serverName);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user