[CLEANUP] Formatted code

This commit is contained in:
Jeroen Ketelaar
2020-10-01 22:30:45 +02:00
committed by Dark98
parent b939a70482
commit e040259e5e
108 changed files with 1262 additions and 1017 deletions
+3 -1
View File
@@ -12,9 +12,11 @@ import org.parabot.core.ui.BotUI;
import org.parabot.core.ui.ServerSelector; import org.parabot.core.ui.ServerSelector;
import org.parabot.core.ui.utils.UILog; import org.parabot.core.ui.utils.UILog;
import javax.swing.*;
import java.io.File; import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/** /**
* @author Everel, JKetelaar, Matt, Dane * @author Everel, JKetelaar, Matt, Dane
* @version 2.8.1 * @version 2.8.1
+10 -10
View File
@@ -19,7 +19,7 @@ import org.parabot.environment.scripts.Script;
import org.parabot.environment.servers.ServerProvider; import org.parabot.environment.servers.ServerProvider;
import java.applet.Applet; import java.applet.Applet;
import java.awt.*; import java.awt.Dimension;
import java.io.File; import java.io.File;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.ArrayList; import java.util.ArrayList;
@@ -34,26 +34,26 @@ import java.util.TimerTask;
public class Context { public class Context {
public static final HashMap<ThreadGroup, Context> threadGroups = new HashMap<>(); public static final HashMap<ThreadGroup, Context> threadGroups = new HashMap<>();
private static ArrayList<Paintable> paintables = new ArrayList<>(); private static final ArrayList<Paintable> paintables = new ArrayList<>();
private static Context instance; private static Context instance;
private static String username; private static String username;
private ASMClassLoader classLoader; private final ASMClassLoader classLoader;
private ClassPath classPath; private final ClassPath classPath;
private ServerProvider serverProvider; private final ServerProvider serverProvider;
private final RandomHandler randomHandler;
private final PaintDebugger paintDebugger;
private final JSONParser jsonParser;
private final PrintStream defaultOut;
private final PrintStream defaultErr;
private Applet gameApplet; private Applet gameApplet;
private HookParser hookParser; private HookParser hookParser;
private Script runningScript; private Script runningScript;
private RandomHandler randomHandler;
private Object clientInstance; private Object clientInstance;
private PaintDebugger paintDebugger;
private Mouse mouse; private Mouse mouse;
private Keyboard keyboard; private Keyboard keyboard;
private PBKeyListener pbKeyListener; private PBKeyListener pbKeyListener;
private ServerProviderInfo providerInfo; private ServerProviderInfo providerInfo;
private JSONParser jsonParser;
private PrintStream defaultOut;
private PrintStream defaultErr;
private Context(final ServerProvider serverProvider) { private Context(final ServerProvider serverProvider) {
threadGroups.put(Thread.currentThread().getThreadGroup(), this); threadGroups.put(Thread.currentThread().getThreadGroup(), this);
+5 -6
View File
@@ -8,8 +8,7 @@ import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.Version; import org.parabot.environment.api.utils.Version;
import org.parabot.environment.api.utils.WebUtil; import org.parabot.environment.api.utils.WebUtil;
import javax.swing.*; import java.awt.Desktop;
import java.awt.*;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -20,6 +19,8 @@ import java.net.URLEncoder;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import javax.swing.JOptionPane;
/** /**
* The core of parabot * The core of parabot
* *
@@ -28,17 +29,15 @@ import java.security.NoSuchAlgorithmException;
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public class Core { public class Core {
private static final Version currentVersion = Configuration.BOT_VERSION;
private static int quickLaunchByUuid = -1; // used like -server, but denoted by an Int rather than the server name private static int quickLaunchByUuid = -1; // used like -server, but denoted by an Int rather than the server name
private static boolean debug; // Debug mode is Offline Mode. No BDN connection for Servers/Scripts/User Login. Not related to debug messages. private static boolean debug; // Debug mode is Offline Mode. No BDN connection for Servers/Scripts/User Login. Not related to debug 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
private static boolean validate = true; private static boolean validate = true;
private static boolean secure = true; private static boolean secure = true;
private static Version currentVersion = Configuration.BOT_VERSION;
public static void disableValidation() { public static void disableValidation() {
Core.validate = false; Core.validate = false;
} }
@@ -251,7 +250,7 @@ public class Core {
byte[] mdbytes = md.digest(); byte[] mdbytes = md.digest();
StringBuilder sb = new StringBuilder(""); StringBuilder sb = new StringBuilder();
for (byte mdbyte : mdbytes) { for (byte mdbyte : mdbytes) {
sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1)); sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1));
} }
@@ -12,7 +12,7 @@ import java.util.Properties;
public class ProjectProperties { public class ProjectProperties {
private static ProjectProperties instance; private static ProjectProperties instance;
private Properties cached = new Properties(); private final Properties cached = new Properties();
private ProjectProperties() { private ProjectProperties() {
setProperties(); setProperties();
@@ -22,14 +22,19 @@ import java.util.Map;
*/ */
public class ASMClassLoader extends ClassLoader { public class ASMClassLoader extends ClassLoader {
private final Map<String, Class<?>> classCache;
public ClassPath classPath; public ClassPath classPath;
private Map<String, Class<?>> classCache;
public ASMClassLoader(final ClassPath classPath) { public ASMClassLoader(final ClassPath classPath) {
this.classCache = new HashMap<String, Class<?>>(); this.classCache = new HashMap<String, Class<?>>();
this.classPath = classPath; this.classPath = classPath;
} }
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
return findClass(name);
}
@Override @Override
protected URL findResource(String name) { protected URL findResource(String name) {
if (getSystemResource(name) == null) { if (getSystemResource(name) == null) {
@@ -47,11 +52,6 @@ public class ASMClassLoader extends ClassLoader {
return getSystemResource(name); return getSystemResource(name);
} }
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
return findClass(name);
}
@Override @Override
protected Class<?> findClass(String name) throws ClassNotFoundException { protected Class<?> findClass(String name) throws ClassNotFoundException {
try { try {
@@ -5,7 +5,7 @@ import org.objectweb.asm.commons.Remapper;
import java.util.HashMap; import java.util.HashMap;
public class ClassRemapper extends Remapper { public class ClassRemapper extends Remapper {
private static HashMap<String, String> remapNames = new HashMap<String, String>(); private static final HashMap<String, String> remapNames = new HashMap<String, String>();
static { static {
remapNames.put("java/net/Socket", "org/parabot/core/network/proxy/ProxySocket"); remapNames.put("java/net/Socket", "org/parabot/core/network/proxy/ProxySocket");
@@ -5,7 +5,15 @@ import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.parabot.core.Core; import org.parabot.core.Core;
import org.parabot.core.Directories; import org.parabot.core.Directories;
import org.parabot.core.asm.redirect.*; import org.parabot.core.asm.redirect.ClassRedirect;
import org.parabot.core.asm.redirect.ProcessBuilderRedirect;
import org.parabot.core.asm.redirect.RuntimeMXBeanRedirect;
import org.parabot.core.asm.redirect.RuntimeRedirect;
import org.parabot.core.asm.redirect.StackTraceElementRedirect;
import org.parabot.core.asm.redirect.SystemRedirect;
import org.parabot.core.asm.redirect.ThreadRedirect;
import org.parabot.core.asm.redirect.ToolkitRedirect;
import org.parabot.core.asm.redirect.URLClassLoaderRedirect;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -3,7 +3,14 @@ package org.parabot.core.asm.adapters;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*; import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.parabot.core.asm.ASMUtils; import org.parabot.core.asm.ASMUtils;
import org.parabot.core.asm.interfaces.Injectable; import org.parabot.core.asm.interfaces.Injectable;
@@ -15,12 +22,12 @@ import java.lang.reflect.Modifier;
* @author Everel * @author Everel
*/ */
public class AddCallbackAdapter implements Injectable, Opcodes { public class AddCallbackAdapter implements Injectable, Opcodes {
private MethodNode method; private final MethodNode method;
private String invokeClass; private final String invokeClass;
private String invokeMethod; private final String invokeMethod;
private String desc; private final String desc;
private int[] args; private final int[] args;
private boolean conditional; private final boolean conditional;
public AddCallbackAdapter(final MethodNode method, public AddCallbackAdapter(final MethodNode method,
final String invokeClass, final String invokeMethod, final String invokeClass, final String invokeMethod,
@@ -2,11 +2,16 @@ package org.parabot.core.asm.adapters;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
public class AddDebugAdapter { public class AddDebugAdapter {
private final MethodNode mn;
private ClassNode owner; private ClassNode owner;
private MethodNode mn;
public AddDebugAdapter(ClassNode owner, MethodNode mn) { public AddDebugAdapter(ClassNode owner, MethodNode mn) {
this.owner = owner; this.owner = owner;
@@ -17,13 +17,13 @@ import java.lang.reflect.Modifier;
* @author Everel * @author Everel
*/ */
public class AddGetterAdapter implements Opcodes, Injectable { public class AddGetterAdapter implements Opcodes, Injectable {
private ClassNode into; private final ClassNode into;
private ClassNode fieldLocation; private final ClassNode fieldLocation;
private FieldNode fieldNode; private final FieldNode fieldNode;
private String methodName; private final String methodName;
private String returnDesc; private final String returnDesc;
private boolean staticField; private final boolean staticField;
private boolean staticMethod; private final boolean staticMethod;
private long multiplier; private long multiplier;
/** /**
@@ -14,8 +14,8 @@ import org.parabot.core.asm.interfaces.Injectable;
public class AddInterfaceAdapter implements Injectable { public class AddInterfaceAdapter implements Injectable {
private static String accessorPackage; private static String accessorPackage;
private ClassNode node; private final ClassNode node;
private String interfaceClass; private final String interfaceClass;
public AddInterfaceAdapter(ClassNode node, String interfaceClass) { public AddInterfaceAdapter(ClassNode node, String interfaceClass) {
this.node = node; this.node = node;
@@ -35,17 +35,6 @@ public class AddInterfaceAdapter implements Injectable {
accessorPackage = packageName; accessorPackage = packageName;
} }
protected static void addInterface(ClassNode node, String i) {
ASMUtils.makePublic(node);
for (Object mn : node.methods) {
MethodNode methodNode = (MethodNode) mn;
if (methodNode.name.startsWith("<init")) {
ASMUtils.makePublic(methodNode);
}
}
node.interfaces.add(i);
}
@Override @Override
public void inject() { public void inject() {
Core.verbose("Injecting: " + this.toString()); Core.verbose("Injecting: " + this.toString());
@@ -56,4 +45,15 @@ public class AddInterfaceAdapter implements Injectable {
public String toString() { public String toString() {
return new StringBuilder("[Injectable: interface, into classname: ").append(node.name).append(", interface: ").append(accessorPackage).append(interfaceClass).append("]").toString(); return new StringBuilder("[Injectable: interface, into classname: ").append(node.name).append(", interface: ").append(accessorPackage).append(interfaceClass).append("]").toString();
} }
protected static void addInterface(ClassNode node, String i) {
ASMUtils.makePublic(node);
for (Object mn : node.methods) {
MethodNode methodNode = (MethodNode) mn;
if (methodNode.name.startsWith("<init")) {
ASMUtils.makePublic(methodNode);
}
}
node.interfaces.add(i);
}
} }
@@ -15,17 +15,17 @@ import java.lang.reflect.Modifier;
* @author Everel * @author Everel
*/ */
public class AddInvokerAdapter implements Opcodes, Injectable { public class AddInvokerAdapter implements Opcodes, Injectable {
private ClassNode into; private final ClassNode into;
private ClassNode methodLocation; private final ClassNode methodLocation;
private MethodNode mn; private final MethodNode mn;
private String argsDesc; private final String argsDesc;
private String returnDesc; private final String returnDesc;
private String methodName; private final String methodName;
private boolean isInterface; private final boolean isInterface;
private String instanceCast; private final String instanceCast;
private String mName; private final String mName;
private String mDesc; private final String mDesc;
private String argsCheckCast; private final String argsCheckCast;
private boolean isStatic; private boolean isStatic;
@@ -13,12 +13,12 @@ import org.parabot.core.asm.interfaces.Injectable;
* @author Everel * @author Everel
*/ */
public class AddSetterAdapter implements Opcodes, Injectable { public class AddSetterAdapter implements Opcodes, Injectable {
private ClassNode fieldLocation; private final ClassNode fieldLocation;
private ClassNode into; private final ClassNode into;
private FieldNode field; private final FieldNode field;
private String name; private final String name;
private String desc; private final String desc;
private boolean methodStatic; private final boolean methodStatic;
public AddSetterAdapter(ClassNode fieldLocation, ClassNode into, public AddSetterAdapter(ClassNode fieldLocation, ClassNode into,
FieldNode field, String name, String desc, boolean methodStatic) { FieldNode field, String name, String desc, boolean methodStatic) {
@@ -35,6 +35,27 @@ public class AddSetterAdapter implements Opcodes, Injectable {
this(fieldLocation, into, field, name, desc, false); this(fieldLocation, into, field, name, desc, false);
} }
/**
* Injects the setter
*/
@Override
public void inject() {
Core.verbose("Injecting: " + this.toString());
addSetter(fieldLocation, into, field, name, desc, methodStatic);
}
@Override
public String toString() {
return new StringBuilder("[Injectable: setter, into classname: ")
.append(into.name).append(", field classname: ")
.append(fieldLocation.name).append(", field name: ")
.append(field.name).append(", field desc: ").append(field.desc)
.append(", method name: ").append(name)
.append(", method desc: ").append(desc)
.append(", static method: ").append(methodStatic).append("]")
.toString();
}
private static void addSetter(ClassNode fieldLocation, ClassNode into, private static void addSetter(ClassNode fieldLocation, ClassNode into,
FieldNode field, String name, String desc, boolean methodStatic) { FieldNode field, String name, String desc, boolean methodStatic) {
if (desc.contains("L") && !desc.endsWith("Ljava/lang/String;")) { if (desc.contains("L") && !desc.endsWith("Ljava/lang/String;")) {
@@ -61,25 +82,4 @@ public class AddSetterAdapter implements Opcodes, Injectable {
into.methods.add(method); into.methods.add(method);
} }
/**
* Injects the setter
*/
@Override
public void inject() {
Core.verbose("Injecting: " + this.toString());
addSetter(fieldLocation, into, field, name, desc, methodStatic);
}
@Override
public String toString() {
return new StringBuilder("[Injectable: setter, into classname: ")
.append(into.name).append(", field classname: ")
.append(fieldLocation.name).append(", field name: ")
.append(field.name).append(", field desc: ").append(field.desc)
.append(", method name: ").append(name)
.append(", method desc: ").append(desc)
.append(", static method: ").append(methodStatic).append("]")
.toString();
}
} }
@@ -17,8 +17,8 @@ import java.util.ListIterator;
* @author Everel * @author Everel
*/ */
public class AddSuperAdapter implements Injectable { public class AddSuperAdapter implements Injectable {
private ClassNode node; private final ClassNode node;
private String superClass; private final String superClass;
public AddSuperAdapter(final ClassNode node, final String superClass) { public AddSuperAdapter(final ClassNode node, final String superClass) {
this.node = node; this.node = node;
@@ -30,6 +30,19 @@ public class AddSuperAdapter implements Injectable {
this.superClass = superClass; this.superClass = superClass;
} }
@Override
public void inject() {
Core.verbose("Injecting: " + this.toString());
setSuper(node, superClass);
}
@Override
public String toString() {
return new StringBuilder("[Injectable: super, class name: ")
.append(node.name).append(", super: ").append(superClass)
.append("]").toString();
}
private static final void setSuper(final ClassNode node, private static final void setSuper(final ClassNode node,
final String superClass) { final String superClass) {
ListIterator<?> mli = node.methods.listIterator(); ListIterator<?> mli = node.methods.listIterator();
@@ -52,17 +65,4 @@ public class AddSuperAdapter implements Injectable {
node.superName = superClass; node.superName = superClass;
} }
@Override
public void inject() {
Core.verbose("Injecting: " + this.toString());
setSuper(node, superClass);
}
@Override
public String toString() {
return new StringBuilder("[Injectable: super, class name: ")
.append(node.name).append(", super: ").append(superClass)
.append("]").toString();
}
} }
@@ -16,7 +16,7 @@ public class HookFile {
public static final int TYPE_XML = 0; public static final int TYPE_XML = 0;
public static final int TYPE_JSON = 1; public static final int TYPE_JSON = 1;
private URL url; private final URL url;
private int type; private int type;
private boolean isLocal; private boolean isLocal;
@@ -10,6 +10,6 @@ public interface Injectable {
/** /**
* Injects bytecode into a class * Injects bytecode into a class
*/ */
public void inject(); void inject();
} }
@@ -6,7 +6,11 @@ import org.parabot.environment.scripts.Script;
import java.io.InputStream; import java.io.InputStream;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.*; import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.net.URL; import java.net.URL;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
@@ -42,7 +46,9 @@ public class ClassRedirect {
throw RedirectClassAdapter.createSecurityException(); throw RedirectClassAdapter.createSecurityException();
} }
public static Method getDeclaredMethod(Class<?> c, String name, Class<?>... params) throws NoSuchMethodException, SecurityException { public static Method getDeclaredMethod(Class<?> c, String name, Class<?>... params) throws
NoSuchMethodException,
SecurityException {
if (validStack() || validRequest(c)) { if (validStack() || validRequest(c)) {
return c.getDeclaredMethod(name, params); return c.getDeclaredMethod(name, params);
} }
@@ -113,7 +119,9 @@ public class ClassRedirect {
throw RedirectClassAdapter.createSecurityException(); throw RedirectClassAdapter.createSecurityException();
} }
public static Method getMethod(Class<?> c, String name, Class<?>... params) throws NoSuchMethodException, SecurityException { public static Method getMethod(Class<?> c, String name, Class<?>... params) throws
NoSuchMethodException,
SecurityException {
if (validStack() || validRequest(c)) { if (validStack() || validRequest(c)) {
return c.getMethod(name, params); return c.getMethod(name, params);
} }
@@ -207,7 +215,9 @@ public class ClassRedirect {
return c.getAnnotation(annotationClass); return c.getAnnotation(annotationClass);
} }
public static Constructor getDeclaredConstructor(Class c, Class[] parameterTypes) throws NoSuchMethodException, SecurityException { public static Constructor getDeclaredConstructor(Class c, Class[] parameterTypes) throws
NoSuchMethodException,
SecurityException {
return c.getDeclaredConstructor(parameterTypes); return c.getDeclaredConstructor(parameterTypes);
} }
@@ -11,7 +11,7 @@ import java.util.ArrayList;
*/ */
public class FileRedirect extends File { public class FileRedirect extends File {
private static ArrayList<String> cachedFiles = new ArrayList<>(); private static final ArrayList<String> cachedFiles = new ArrayList<>();
public FileRedirect(String pathname) { public FileRedirect(String pathname) {
super(pathname); super(pathname);
@@ -18,11 +18,11 @@ public class RuntimeRedirect {
} }
public static long totalMemory(Runtime runtime) { public static long totalMemory(Runtime runtime) {
return (long) Random.between(1024, 4096); return Random.between(1024, 4096);
} }
public static long freeMemory(Runtime runtime) { public static long freeMemory(Runtime runtime) {
return (long) Random.between(1024, 4096); return Random.between(1024, 4096);
} }
public static Process exec(Runtime r, String[] s) { public static Process exec(Runtime r, String[] s) {
@@ -23,18 +23,6 @@ public class SystemRedirect {
System.exit(i); System.exit(i);
} }
private static String getClassPath(){
String classPath = System.getProperty("java.class.path");
StringBuilder finalClassPath = new StringBuilder();
for (String path : classPath.split(":")) {
if (!path.toLowerCase().contains("parabot")) {
finalClassPath.append(path).append(":");
}
}
return finalClassPath.toString();
}
public static String getProperty(String s) { public static String getProperty(String s) {
String value; String value;
switch (s) { switch (s) {
@@ -107,4 +95,16 @@ public class SystemRedirect {
return System.nanoTime(); return System.nanoTime();
} }
private static String getClassPath() {
String classPath = System.getProperty("java.class.path");
StringBuilder finalClassPath = new StringBuilder();
for (String path : classPath.split(":")) {
if (!path.toLowerCase().contains("parabot")) {
finalClassPath.append(path).append(":");
}
}
return finalClassPath.toString();
}
} }
@@ -4,7 +4,7 @@ import org.parabot.core.asm.RedirectClassAdapter;
public class ThreadRedirect { public class ThreadRedirect {
private static int count = 0; private static final int count = 0;
public static void start(Thread t) { public static void start(Thread t) {
t.start(); t.start();
@@ -1,6 +1,10 @@
package org.parabot.core.asm.redirect; package org.parabot.core.asm.redirect;
import java.awt.*; import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
@@ -11,12 +11,12 @@ import org.parabot.core.asm.interfaces.Injectable;
* @author Everel * @author Everel
*/ */
public class Callback implements Injectable { public class Callback implements Injectable {
private MethodNode method; private final MethodNode method;
private String invokeClass; private final String invokeClass;
private String invokeMethod; private final String invokeMethod;
private String desc; private final String desc;
private final boolean conditional;
private int[] args; private int[] args;
private boolean conditional;
public Callback(final String className, final String methodName, public Callback(final String className, final String methodName,
final String methodDesc, final String callbackClass, final String methodDesc, final String callbackClass,
@@ -13,12 +13,12 @@ import org.parabot.core.asm.interfaces.Injectable;
* @author Everel * @author Everel
*/ */
public class Getter implements Injectable { public class Getter implements Injectable {
private ClassNode into; private final ClassNode into;
private ClassNode fieldLocation; private final ClassNode fieldLocation;
private FieldNode fieldNode; private final FieldNode fieldNode;
private String methodName; private final String methodName;
private String returnDesc; private final String returnDesc;
private boolean staticMethod; private final boolean staticMethod;
private long multiplier; private long multiplier;
/** /**
@@ -9,8 +9,8 @@ import org.parabot.core.asm.interfaces.Injectable;
* @author Everel * @author Everel
*/ */
public class Interface implements Injectable { public class Interface implements Injectable {
private String className; private final String className;
private String interfaceClass; private final String interfaceClass;
public Interface(String className, String interfaceClass) { public Interface(String className, String interfaceClass) {
this.className = className; this.className = className;
@@ -13,18 +13,18 @@ import org.parabot.core.asm.interfaces.Injectable;
* @author Everel * @author Everel
*/ */
public class Invoker implements Injectable { public class Invoker implements Injectable {
private ClassNode into; private final ClassNode into;
private ClassNode methodLocation; private final ClassNode methodLocation;
private MethodNode mn; private final MethodNode mn;
private String argsDesc; private final String argsDesc;
private String returnDesc; private final String returnDesc;
private String methodName; private final String methodName;
private boolean isInterface; private final boolean isInterface;
private String instanceCast; private final String instanceCast;
private String argsCheckCastDesc; private final String argsCheckCastDesc;
private String mName; private final String mName;
private String mDesc; private final String mDesc;
public Invoker(String methodLoc, String invMethName, String argsDesc, public Invoker(String methodLoc, String invMethName, String argsDesc,
String returnDesc, String methodName) { String returnDesc, String methodName) {
@@ -48,17 +48,6 @@ public class Invoker implements Injectable {
this.argsCheckCastDesc = argsCheckCastDesc; this.argsCheckCastDesc = argsCheckCastDesc;
} }
private static MethodNode getMethod(ClassNode into, String name, String argsDesc, String returnDesc) {
for (Object method : into.methods) {
MethodNode m = (MethodNode) method;
if (m.name.equals(name) && m.desc.substring(0, m.desc.indexOf(')') + 1).equals(argsDesc)
&& (returnDesc == null || Type.getType(m.desc).getReturnType().getDescriptor().equals(returnDesc))) {
return m;
}
}
return null;
}
/** /**
* Short route for getAdaptar().inject(); * Short route for getAdaptar().inject();
* *
@@ -83,4 +72,15 @@ public class Invoker implements Injectable {
public String toString() { public String toString() {
return String.format("Injectable type: Invoker, accessor: %s, method name: %s, invokes method: %s", methodLocation.name, methodName, mName); return String.format("Injectable type: Invoker, accessor: %s, method name: %s, invokes method: %s", methodLocation.name, methodName, mName);
} }
private static MethodNode getMethod(ClassNode into, String name, String argsDesc, String returnDesc) {
for (Object method : into.methods) {
MethodNode m = (MethodNode) method;
if (m.name.equals(name) && m.desc.substring(0, m.desc.indexOf(')') + 1).equals(argsDesc)
&& (returnDesc == null || Type.getType(m.desc).getReturnType().getDescriptor().equals(returnDesc))) {
return m;
}
}
return null;
}
} }
@@ -12,12 +12,12 @@ import org.parabot.core.asm.interfaces.Injectable;
* @author Everel * @author Everel
*/ */
public class Setter implements Injectable { public class Setter implements Injectable {
private ClassNode fieldLocation; private final ClassNode fieldLocation;
private ClassNode into; private final ClassNode into;
private FieldNode field; private final FieldNode field;
private String name; private final String name;
private String desc; private final String desc;
private boolean methodStatic; private final boolean methodStatic;
public Setter(final String fieldLocation, String into, final String fieldName, final String methodName, final String desc, final boolean methodStatic, final String fieldDesc) { public Setter(final String fieldLocation, String into, final String fieldName, final String methodName, final String desc, final boolean methodStatic, final String fieldDesc) {
this.fieldLocation = ASMUtils.getClass(fieldLocation); this.fieldLocation = ASMUtils.getClass(fieldLocation);
@@ -9,8 +9,8 @@ import org.parabot.core.asm.interfaces.Injectable;
* @author Everel * @author Everel
*/ */
public class Super implements Injectable { public class Super implements Injectable {
private String className; private final String className;
private String superClassName; private final String superClassName;
public Super(String className, String superClassName) { public Super(String className, String superClassName) {
this.className = className; this.className = className;
@@ -11,7 +11,13 @@ import org.parabot.core.build.BuildPath;
import org.parabot.core.io.SizeInputStream; import org.parabot.core.io.SizeInputStream;
import org.parabot.core.ui.components.VerboseLoader; import org.parabot.core.ui.components.VerboseLoader;
import java.io.*; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@@ -35,11 +41,11 @@ public class ClassPath {
public final ArrayList<String> classNames; public final ArrayList<String> classNames;
public final HashMap<String, ClassNode> classes; public final HashMap<String, ClassNode> classes;
public final Map<String, File> resources; public final Map<String, File> resources;
private final ClassRemapper classRemapper;
private final boolean isJar;
private final ArrayList<URL> jarFiles;
public URL lastParsed; public URL lastParsed;
private ClassRemapper classRemapper;
private boolean isJar;
private boolean parseJar; private boolean parseJar;
private ArrayList<URL> jarFiles;
public ClassPath() { public ClassPath() {
this(false); this(false);
@@ -180,23 +186,6 @@ public class ClassPath {
} }
} }
/**
* Loads class from input stream
*
* @param in
*
* @throws IOException
*/
protected void loadClass(InputStream in) throws IOException {
ClassReader cr = new ClassReader(in);
ClassNode cn = new ClassNode();
RemappingClassAdapter rca = new RemappingClassAdapter(cn, classRemapper);
RedirectClassAdapter redir = new RedirectClassAdapter(rca);
cr.accept(redir, ClassReader.EXPAND_FRAMES);
classNames.add(cn.name.replace('/', '.'));
classes.put(cn.name, cn);
}
/** /**
* Determines if this classpath represents a jar file * Determines if this classpath represents a jar file
* *
@@ -221,31 +210,6 @@ public class ClassPath {
return jars; return jars;
} }
/**
* Dumps a resource from a input stream
*
* @param classPath
* @param name
* @param inputstream
*
* @throws IOException
*/
private void loadResource(final String name, final InputStream in)
throws IOException {
final File f = File.createTempFile("bot", ".tmp",
Directories.getTempDirectory());
f.deleteOnExit();
try (OutputStream out = new FileOutputStream(f)) {
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
} catch (IOException e) {
}
this.resources.put(name, f);
}
/** /**
* Adds this jar to buildpath * Adds this jar to buildpath
*/ */
@@ -302,4 +266,46 @@ public class ClassPath {
} }
} }
/**
* Loads class from input stream
*
* @param in
*
* @throws IOException
*/
protected void loadClass(InputStream in) throws IOException {
ClassReader cr = new ClassReader(in);
ClassNode cn = new ClassNode();
RemappingClassAdapter rca = new RemappingClassAdapter(cn, classRemapper);
RedirectClassAdapter redir = new RedirectClassAdapter(rca);
cr.accept(redir, ClassReader.EXPAND_FRAMES);
classNames.add(cn.name.replace('/', '.'));
classes.put(cn.name, cn);
}
/**
* Dumps a resource from a input stream
*
* @param classPath
* @param name
* @param inputstream
*
* @throws IOException
*/
private void loadResource(final String name, final InputStream in)
throws IOException {
final File f = File.createTempFile("bot", ".tmp",
Directories.getTempDirectory());
f.deleteOnExit();
try (OutputStream out = new FileOutputStream(f)) {
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
} catch (IOException e) {
}
this.resources.put(name, f);
}
} }
@@ -6,9 +6,9 @@ package org.parabot.core.desc;
* @author Everel * @author Everel
*/ */
public class ServerDescription implements Comparable<ServerDescription> { public class ServerDescription implements Comparable<ServerDescription> {
private String serverName; private final String serverName;
private String author; private final String author;
private double revision; private final double revision;
public int uuid; public int uuid;
public ServerDescription(final String serverName, final String author, public ServerDescription(final String serverName, final String author,
@@ -22,8 +22,8 @@ import java.util.zip.CRC32;
*/ */
public class ServerProviderInfo { public class ServerProviderInfo {
private HashMap<String, Integer> settings; private final HashMap<String, Integer> settings;
private Properties properties; private final Properties properties;
public ServerProviderInfo(URL providerInfo, String username, String password) { public ServerProviderInfo(URL providerInfo, String username, String password) {
this.properties = new Properties(); this.properties = new Properties();
@@ -52,6 +52,7 @@ public class ServerProviderInfo {
/** /**
* Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /parabot/servers/config.json} file. Also loads the default Settings map from the BDN. * Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /parabot/servers/config.json} file. Also loads the default Settings map from the BDN.
*
* @param clientJar Name of the client jar file * @param clientJar Name of the client jar file
* @param hooks Name of the hooks file * @param hooks Name of the hooks file
* @param name Server name * @param name Server name
@@ -64,6 +65,7 @@ public class ServerProviderInfo {
/** /**
* Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /parabot/servers/config.json} file. Also loads the default Settings map from the BDN. * Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /parabot/servers/config.json} file. Also loads the default Settings map from the BDN.
*
* @param clientJar Name of the client jar file * @param clientJar Name of the client jar file
* @param hooks Name of the hooks file * @param hooks Name of the hooks file
* @param name Server name * @param name Server name
@@ -93,22 +95,6 @@ public class ServerProviderInfo {
this.properties.setProperty("randoms_jar", randoms); this.properties.setProperty("randoms_jar", randoms);
} }
private long getCRC32(String name, String type) {
CRC32 crc = new CRC32();
name += "-" + type;
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);
}
}
public URL getClient() { public URL getClient() {
try { try {
return new URL(properties.getProperty("client_jar")); return new URL(properties.getProperty("client_jar"));
@@ -198,4 +184,20 @@ public class ServerProviderInfo {
return null; return null;
} }
private long getCRC32(String name, String type) {
CRC32 crc = new CRC32();
name += "-" + type;
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);
}
}
} }
@@ -11,8 +11,8 @@ import java.net.URLEncoder;
* @author Everel * @author Everel
*/ */
public class Account { public class Account {
private String username; private final String username;
private String password; private final String password;
private String api; private String api;
/** /**
@@ -13,12 +13,13 @@ import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.scripts.executers.BDNScriptsExecuter; import org.parabot.environment.scripts.executers.BDNScriptsExecuter;
import org.parabot.environment.servers.executers.PublicServerExecuter; import org.parabot.environment.servers.executers.PublicServerExecuter;
import javax.swing.*;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.JOptionPane;
/** /**
* Handles logging in to parabot forum, only certain classes may use this class. * Handles logging in to parabot forum, only certain classes may use this class.
* *
@@ -7,6 +7,6 @@ package org.parabot.core.forum;
*/ */
public interface AccountManagerAccess { public interface AccountManagerAccess {
public void setManager(AccountManager manager); void setManager(AccountManager manager);
} }
@@ -7,11 +7,11 @@ import java.io.InputStream;
* @author Everel * @author Everel
*/ */
public class SizeInputStream extends InputStream { public class SizeInputStream extends InputStream {
private final ProgressListener l;
private final InputStream in;
private final long startTime;
private final double size;
public int bytesRead; public int bytesRead;
private ProgressListener l;
private InputStream in;
private long startTime;
private double size;
public SizeInputStream(InputStream in, int size, ProgressListener l) { public SizeInputStream(InputStream in, int size, ProgressListener l) {
this.in = in; this.in = in;
@@ -5,7 +5,7 @@ import java.io.IOException;
public class Runtime { public class Runtime {
private static Runtime cached; private static Runtime cached;
private java.lang.Runtime rt; private final java.lang.Runtime rt;
private Runtime(java.lang.Runtime rt) { private Runtime(java.lang.Runtime rt) {
this.rt = rt; this.rt = rt;
@@ -3,17 +3,28 @@ package org.parabot.core.network.proxy;
import org.parabot.core.Core; import org.parabot.core.Core;
import org.parabot.core.ui.utils.UILog; import org.parabot.core.ui.utils.UILog;
import javax.swing.*; import java.io.BufferedReader;
import java.io.*; import java.io.DataInputStream;
import java.net.*; import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.JOptionPane;
public class ProxySocket extends Socket { public class ProxySocket extends Socket {
private static final List<ProxySocket> connections = new ArrayList<ProxySocket>();
public static boolean auth = false; public static boolean auth = false;
private static List<ProxySocket> connections = new ArrayList<ProxySocket>();
private static ProxyType proxyType = ProxyType.NONE; private static ProxyType proxyType = ProxyType.NONE;
private static int proxyPort = 0; private static int proxyPort = 0;
private static String username = null, password = null; private static String username = null, password = null;
@@ -112,6 +123,44 @@ public class ProxySocket extends Socket {
} }
} }
@Override
public int getPort() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return port;
}
return super.getPort();
}
@Override
public InetAddress getInetAddress() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return addr;
}
return super.getInetAddress();
}
@Override
public SocketAddress getRemoteSocketAddress() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return cachedAddr;
}
return super.getRemoteSocketAddress();
}
@Override
public SocketChannel getChannel() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return null;
}
return super.getChannel();
}
@Override
public void close() throws IOException {
connections.remove(this);
super.close();
}
private void initProxy() throws IOException { private void initProxy() throws IOException {
System.out.println("Proxying:" + addr + ":" + port + " Over:" System.out.println("Proxying:" + addr + ":" + port + " Over:"
+ proxyInetAddress + ":" + proxyPort + " Type:" + proxyType); + proxyInetAddress + ":" + proxyPort + " Type:" + proxyType);
@@ -269,42 +318,4 @@ public class ProxySocket extends Socket {
in.readShort(); // the returned port #, ignored in.readShort(); // the returned port #, ignored
} }
@Override
public int getPort() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return port;
}
return super.getPort();
}
@Override
public InetAddress getInetAddress() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return addr;
}
return super.getInetAddress();
}
@Override
public SocketAddress getRemoteSocketAddress() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return cachedAddr;
}
return super.getRemoteSocketAddress();
}
@Override
public SocketChannel getChannel() {
if (super.getInetAddress().equals(proxyInetAddress)) {
return null;
}
return super.getChannel();
}
@Override
public void close() throws IOException {
connections.remove(this);
super.close();
}
} }
@@ -2,7 +2,8 @@ package org.parabot.core.paint;
import org.parabot.core.Context; import org.parabot.core.Context;
import java.awt.*; import java.awt.Color;
import java.awt.Graphics;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
@@ -2,10 +2,14 @@ package org.parabot.core.parsers.hooks;
import org.parabot.core.asm.hooks.HookFile; import org.parabot.core.asm.hooks.HookFile;
import org.parabot.core.asm.interfaces.Injectable; import org.parabot.core.asm.interfaces.Injectable;
import org.parabot.core.asm.wrappers.*; import org.parabot.core.asm.wrappers.Callback;
import org.parabot.core.asm.wrappers.Getter;
import org.parabot.core.asm.wrappers.Interface;
import org.parabot.core.asm.wrappers.Invoker;
import org.parabot.core.asm.wrappers.Setter;
import org.parabot.core.asm.wrappers.Super;
import org.parabot.core.forum.AccountManager; import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess; import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.environment.api.utils.PBPreferences;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@@ -5,7 +5,12 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.parabot.core.asm.adapters.AddInterfaceAdapter; import org.parabot.core.asm.adapters.AddInterfaceAdapter;
import org.parabot.core.asm.hooks.HookFile; import org.parabot.core.asm.hooks.HookFile;
import org.parabot.core.asm.wrappers.*; import org.parabot.core.asm.wrappers.Callback;
import org.parabot.core.asm.wrappers.Getter;
import org.parabot.core.asm.wrappers.Interface;
import org.parabot.core.asm.wrappers.Invoker;
import org.parabot.core.asm.wrappers.Setter;
import org.parabot.core.asm.wrappers.Super;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashMap; import java.util.HashMap;
@@ -120,7 +125,7 @@ public class JSONHookParser extends HookParser {
String clazz = o.containsKey("class") ? this.get(o, "class") : interfaces.get(this.get(o, "accessor")); String clazz = o.containsKey("class") ? this.get(o, "class") : interfaces.get(this.get(o, "accessor"));
String into = o.containsKey("into") ? this.get(o, "into") : clazz; String into = o.containsKey("into") ? this.get(o, "into") : clazz;
g[i] = new Getter(into, clazz, this.get(o, "field"), this.get(o, "method"), desc, o.containsKey("static") ? (boolean) o.get("static") : false, 0, null); g[i] = new Getter(into, clazz, this.get(o, "field"), this.get(o, "method"), desc, o.containsKey("static") && (boolean) o.get("static"), 0, null);
} }
return g; return g;
} }
@@ -153,7 +158,7 @@ public class JSONHookParser extends HookParser {
String clazz = o.containsKey("class") ? this.get(o, "class") : interfaces.get(this.get(o, "accessor")); String clazz = o.containsKey("class") ? this.get(o, "class") : interfaces.get(this.get(o, "accessor"));
String into = o.containsKey("into") ? this.get(o, "into") : clazz; String into = o.containsKey("into") ? this.get(o, "into") : clazz;
s[i] = new Setter(into, clazz, this.get(o, "field"), this.get(o, "method"), desc, o.containsKey("static") ? (boolean) o.get("static") : false, null); s[i] = new Setter(into, clazz, this.get(o, "field"), this.get(o, "method"), desc, o.containsKey("static") && (boolean) o.get("static"), null);
} }
return s; return s;
} }
@@ -3,18 +3,24 @@ package org.parabot.core.parsers.hooks;
import org.parabot.core.Core; import org.parabot.core.Core;
import org.parabot.core.asm.adapters.AddInterfaceAdapter; import org.parabot.core.asm.adapters.AddInterfaceAdapter;
import org.parabot.core.asm.hooks.HookFile; import org.parabot.core.asm.hooks.HookFile;
import org.parabot.core.asm.wrappers.*; import org.parabot.core.asm.wrappers.Callback;
import org.parabot.core.asm.wrappers.Getter;
import org.parabot.core.asm.wrappers.Interface;
import org.parabot.core.asm.wrappers.Invoker;
import org.parabot.core.asm.wrappers.Setter;
import org.parabot.core.asm.wrappers.Super;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
/** /**
* Parses an XML file which injects the hooks and other bytecode manipulation * Parses an XML file which injects the hooks and other bytecode manipulation
* methods * methods
@@ -22,9 +28,9 @@ import java.util.Map;
* @author JKetelaar * @author JKetelaar
*/ */
public class XMLHookParser extends HookParser { public class XMLHookParser extends HookParser {
private Document doc; private final Document doc;
private HashMap<String, String> interfaceMap; private final HashMap<String, String> interfaceMap;
private HashMap<String, String> constants; private final HashMap<String, String> constants;
private boolean parsedInterfaces; private boolean parsedInterfaces;
public XMLHookParser(HookFile hookFile) { public XMLHookParser(HookFile hookFile) {
@@ -170,8 +176,8 @@ public class XMLHookParser extends HookParser {
final String fieldName = getValue("field", addGetter); final String fieldName = getValue("field", addGetter);
final String fieldDesc = isSet("descfield", addGetter) ? getValue("descfield", addGetter) : null; final String fieldDesc = isSet("descfield", addGetter) ? getValue("descfield", addGetter) : null;
final String methodName = getValue("methodname", addGetter); final String methodName = getValue("methodname", addGetter);
boolean staticMethod = isSet("methstatic", addGetter) ? (getValue( boolean staticMethod = isSet("methstatic", addGetter) && (getValue(
"methstatic", addGetter).equals("true")) : false; "methstatic", addGetter).equals("true"));
String returnDesc = isSet("desc", addGetter) ? getValue("desc", String returnDesc = isSet("desc", addGetter) ? getValue("desc",
addGetter) : null; addGetter) : null;
String array = ""; String array = "";
@@ -244,8 +250,8 @@ public class XMLHookParser extends HookParser {
final String fieldName = getValue("field", addSetter); final String fieldName = getValue("field", addSetter);
final String fieldDesc = isSet("descfield", addSetter) ? getValue("descfield", addSetter) : null; final String fieldDesc = isSet("descfield", addSetter) ? getValue("descfield", addSetter) : null;
final String methodName = getValue("methodname", addSetter); final String methodName = getValue("methodname", addSetter);
boolean staticMethod = isSet("methstatic", addSetter) ? (getValue( boolean staticMethod = isSet("methstatic", addSetter) && (getValue(
"methstatic", addSetter).equals("true")) : false; "methstatic", addSetter).equals("true"));
String returnDesc = isSet("desc", addSetter) ? getValue("desc", String returnDesc = isSet("desc", addSetter) ? getValue("desc",
addSetter) : null; addSetter) : null;
String array = ""; String array = "";
@@ -320,7 +326,7 @@ public class XMLHookParser extends HookParser {
String returnDesc = isSet("desc", addInvoker) ? resolveDesc(getValue( String returnDesc = isSet("desc", addInvoker) ? resolveDesc(getValue(
"desc", addInvoker)) : null; "desc", addInvoker)) : null;
final boolean isInterface = isSet("interface", addInvoker) ? Boolean.parseBoolean(getValue("interface", addInvoker)) : false; final boolean isInterface = isSet("interface", addInvoker) && Boolean.parseBoolean(getValue("interface", addInvoker));
final String instanceCast = isSet("instancecast", addInvoker) ? getValue("instancecast", addInvoker) : null; final String instanceCast = isSet("instancecast", addInvoker) ? getValue("instancecast", addInvoker) : null;
final String checkCastArgsDesc = isSet("castargs", addInvoker) ? getValue("castargs", addInvoker) : null; final String checkCastArgsDesc = isSet("castargs", addInvoker) ? getValue("castargs", addInvoker) : null;
@@ -464,7 +470,7 @@ public class XMLHookParser extends HookParser {
} }
return ""; return "";
} }
Node node = (Node) nodes.item(0); Node node = nodes.item(0);
return node.getNodeValue(); return node.getNodeValue();
} }
@@ -1,25 +1,25 @@
package org.parabot.core.parsers.randoms; package org.parabot.core.parsers.randoms;
import org.parabot.api.io.WebUtil;
import org.parabot.core.Configuration;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.io.NoProgressListener;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import org.parabot.api.io.WebUtil;
import org.parabot.api.output.Logger;
import org.parabot.core.Configuration;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.io.NoProgressListener;
/** /**
* @author JKetelaar * @author JKetelaar
*/ */
public class PublicRandoms extends RandomParser { public class PublicRandoms extends RandomParser {
private String fileName = ((Configuration.BOT_VERSION.isNightly()) ? "randoms-nightly.jar" : "randoms.jar"); private final String fileName = ((Configuration.BOT_VERSION.isNightly()) ? "randoms-nightly.jar" : "randoms.jar");
@Override @Override
public void parse() { public void parse() {
@@ -1,10 +1,5 @@
package org.parabot.core.parsers.servers; package org.parabot.core.parsers.servers;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.parabot.core.Configuration; import org.parabot.core.Configuration;
@@ -19,6 +14,12 @@ import org.parabot.environment.servers.executers.LocalPublicServerExecuter;
import org.parabot.environment.servers.executers.LocalServerExecuter; import org.parabot.environment.servers.executers.LocalServerExecuter;
import org.parabot.environment.servers.loader.ServerLoader; 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 * Parses local server providers located in the servers directory
* *
@@ -88,7 +89,6 @@ public class LocalServers extends ServerParser {
} }
String uuidStr = (String) object.get("uuid"); // optional 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");
@@ -10,10 +10,11 @@ import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil; import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.servers.executers.PublicServerExecuter; import org.parabot.environment.servers.executers.PublicServerExecuter;
import javax.swing.*;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.net.URL; import java.net.URL;
import javax.swing.JOptionPane;
/** /**
* Parses servers hosted on Parabot * Parses servers hosted on Parabot
* *
@@ -16,8 +16,8 @@ import java.util.Arrays;
* @author Everel * @author Everel
*/ */
public class RefClass extends RefModifiers { public class RefClass extends RefModifiers {
private final Class<?> clazz;
private Object instance; private Object instance;
private Class<?> clazz;
public RefClass(Class<?> clazz) { public RefClass(Class<?> clazz) {
this(clazz, null); this(clazz, null);
@@ -9,7 +9,7 @@ import java.lang.reflect.Constructor;
* @author Everel * @author Everel
*/ */
public class RefConstructor extends RefModifiers { public class RefConstructor extends RefModifiers {
private Constructor<?> constructor; private final Constructor<?> constructor;
public RefConstructor(Constructor<?> constructor) { public RefConstructor(Constructor<?> constructor) {
super(constructor.getModifiers()); super(constructor.getModifiers());
@@ -9,8 +9,8 @@ import java.lang.reflect.Type;
* @author Everel * @author Everel
*/ */
public class RefField extends RefModifiers { public class RefField extends RefModifiers {
private Field field; private final Field field;
private Object instance; private final Object instance;
public RefField(Field field) { public RefField(Field field) {
this(field, null); this(field, null);
@@ -8,8 +8,8 @@ import java.lang.reflect.Method;
* @author Everel * @author Everel
*/ */
public class RefMethod extends RefModifiers { public class RefMethod extends RefModifiers {
private Method method; private final Method method;
private Object instance; private final Object instance;
public RefMethod(Method method) { public RefMethod(Method method) {
this(method, null); this(method, null);
@@ -3,8 +3,10 @@ package org.parabot.core.ui;
import org.parabot.core.ui.components.PaintComponent; import org.parabot.core.ui.components.PaintComponent;
import org.parabot.environment.OperatingSystem; import org.parabot.environment.OperatingSystem;
import javax.swing.*; import java.awt.Color;
import java.awt.*; import java.awt.Dimension;
import javax.swing.JDialog;
/** /**
* @author Everel * @author Everel
+117 -99
View File
@@ -13,15 +13,33 @@ import org.parabot.environment.api.utils.StringUtils;
import org.parabot.environment.randoms.Random; import org.parabot.environment.randoms.Random;
import org.parabot.environment.scripts.Script; import org.parabot.environment.scripts.Script;
import javax.imageio.ImageIO; import java.awt.AWTException;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*; import java.awt.Point;
import java.awt.event.*; import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.WindowConstants;
/** /**
* The bot user interface * The bot user interface
* *
@@ -73,79 +91,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
return instance; return instance;
} }
private void createMenu() {
menuBar = new JMenuBar();
file = new JMenu("File");
scripts = new JMenu("Script");
features = new JMenu("Features");
JMenuItem screenshot = new JMenuItem("Create screenshot");
JMenuItem proxy = new JMenuItem("Network");
JMenuItem randoms = new JMenuItem("Randoms");
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
JMenuItem logger = new JCheckBoxMenuItem("Logger");
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
dialog.setSelected(true);
}
JMenuItem explorer = new JMenuItem("Reflection explorer");
JMenuItem exit = new JMenuItem("Exit");
run = new JMenuItem("Run");
run.setIcon(new ImageIcon(Images.getResource("/storage/images/run.png")));
pause = new JMenuItem("Pause");
pause.setEnabled(false);
pause.setIcon(new ImageIcon(Images.getResource("/storage/images/pause.png")));
stop = new JMenuItem("Stop");
stop.setEnabled(false);
stop.setIcon(new ImageIcon(Images.getResource("/storage/images/stop.png")));
cacheClear = new JMenuItem("Clear cache");
cacheClear.setIcon(new ImageIcon(Images.getResource("/storage/images/trash.png")));
notifications = new JMenuItem("Notifications");
notifications.setIcon(new ImageIcon(Images.getResource("/storage/images/bell.png")));
screenshot.addActionListener(this);
proxy.addActionListener(this);
randoms.addActionListener(this);
dialog.addActionListener(this);
logger.addActionListener(this);
explorer.addActionListener(this);
exit.addActionListener(this);
cacheClear.addActionListener(this);
notifications.addActionListener(this);
run.addActionListener(this);
pause.addActionListener(this);
stop.addActionListener(this);
file.add(screenshot);
file.add(proxy);
file.add(randoms);
file.add(dialog);
file.add(logger);
file.add(explorer);
file.add(exit);
scripts.add(run);
scripts.add(pause);
scripts.add(stop);
features.add(cacheClear);
features.add(notifications);
menuBar.add(file);
menuBar.add(scripts);
menuBar.add(features);
setJMenuBar(menuBar);
}
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
this.performCommand(e.getActionCommand()); this.performCommand(e.getActionCommand());
@@ -254,10 +199,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
} }
} }
protected void setDialog(JDialog dialog) {
BotUI.dialog = dialog;
}
@Override @Override
public void componentMoved(ComponentEvent e) { public void componentMoved(ComponentEvent e) {
if (dialog == null || !isVisible()) { if (dialog == null || !isVisible()) {
@@ -276,24 +217,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
} }
} }
private void scriptRunning() {
run.setEnabled(false);
pause.setEnabled(true);
stop.setEnabled(true);
}
private void scriptStopped() {
run.setEnabled(true);
pause.setEnabled(false);
stop.setEnabled(false);
}
private void setScriptState(int state) {
if (Context.getInstance().getRunningScript() != null) {
Context.getInstance().getRunningScript().setState(state);
}
}
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
if (isVisible()) { if (isVisible()) {
@@ -362,4 +285,99 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
public JMenuItem getNotifications() { public JMenuItem getNotifications() {
return notifications; return notifications;
} }
protected void setDialog(JDialog dialog) {
BotUI.dialog = dialog;
}
private void createMenu() {
menuBar = new JMenuBar();
file = new JMenu("File");
scripts = new JMenu("Script");
features = new JMenu("Features");
JMenuItem screenshot = new JMenuItem("Create screenshot");
JMenuItem proxy = new JMenuItem("Network");
JMenuItem randoms = new JMenuItem("Randoms");
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
JMenuItem logger = new JCheckBoxMenuItem("Logger");
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
dialog.setSelected(true);
}
JMenuItem explorer = new JMenuItem("Reflection explorer");
JMenuItem exit = new JMenuItem("Exit");
run = new JMenuItem("Run");
run.setIcon(new ImageIcon(Images.getResource("/storage/images/run.png")));
pause = new JMenuItem("Pause");
pause.setEnabled(false);
pause.setIcon(new ImageIcon(Images.getResource("/storage/images/pause.png")));
stop = new JMenuItem("Stop");
stop.setEnabled(false);
stop.setIcon(new ImageIcon(Images.getResource("/storage/images/stop.png")));
cacheClear = new JMenuItem("Clear cache");
cacheClear.setIcon(new ImageIcon(Images.getResource("/storage/images/trash.png")));
notifications = new JMenuItem("Notifications");
notifications.setIcon(new ImageIcon(Images.getResource("/storage/images/bell.png")));
screenshot.addActionListener(this);
proxy.addActionListener(this);
randoms.addActionListener(this);
dialog.addActionListener(this);
logger.addActionListener(this);
explorer.addActionListener(this);
exit.addActionListener(this);
cacheClear.addActionListener(this);
notifications.addActionListener(this);
run.addActionListener(this);
pause.addActionListener(this);
stop.addActionListener(this);
file.add(screenshot);
file.add(proxy);
file.add(randoms);
file.add(dialog);
file.add(logger);
file.add(explorer);
file.add(exit);
scripts.add(run);
scripts.add(pause);
scripts.add(stop);
features.add(cacheClear);
features.add(notifications);
menuBar.add(file);
menuBar.add(scripts);
menuBar.add(features);
setJMenuBar(menuBar);
}
private void scriptRunning() {
run.setEnabled(false);
pause.setEnabled(true);
stop.setEnabled(true);
}
private void scriptStopped() {
run.setEnabled(true);
pause.setEnabled(false);
stop.setEnabled(false);
}
private void setScriptState(int state) {
if (Context.getInstance().getRunningScript() != null) {
Context.getInstance().getRunningScript().setState(state);
}
}
} }
+22 -10
View File
@@ -2,11 +2,23 @@ package org.parabot.core.ui;
import org.parabot.core.ui.components.GamePanel; import org.parabot.core.ui.components.GamePanel;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*; import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
/** /**
* @author JKetelaar * @author JKetelaar
*/ */
@@ -78,6 +90,14 @@ public class Logger extends JPanel {
addMessage(message, true); addMessage(message, true);
} }
public boolean isClearable() {
return clearable;
}
public void setClearable() {
this.clearable = true;
}
protected static void clearLogger() { protected static void clearLogger() {
instance.model.clear(); instance.model.clear();
} }
@@ -96,12 +116,4 @@ public class Logger extends JPanel {
} }
}; };
} }
public boolean isClearable() {
return clearable;
}
public void setClearable() {
this.clearable = true;
}
} }
+12 -2
View File
@@ -8,8 +8,11 @@ import org.parabot.core.ui.utils.SwingUtil;
import org.parabot.core.ui.utils.UILog; import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.input.Keyboard; import org.parabot.environment.input.Keyboard;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*; import java.awt.Desktop;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
@@ -17,6 +20,13 @@ import java.awt.event.KeyEvent;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/** /**
* Users must login with their parabot account through this LoginUI class * Users must login with their parabot account through this LoginUI class
* *
+128 -114
View File
@@ -5,7 +5,26 @@ import org.parabot.core.network.proxy.ProxySocket;
import org.parabot.core.network.proxy.ProxyType; import org.parabot.core.network.proxy.ProxyType;
import org.parabot.core.ui.utils.UILog; import org.parabot.core.ui.utils.UILog;
import javax.swing.*; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
@@ -13,11 +32,6 @@ import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
import javax.swing.text.Document; import javax.swing.text.Document;
import javax.swing.text.PlainDocument; import javax.swing.text.PlainDocument;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
public class NetworkUI extends JFrame implements KeyListener, ActionListener, public class NetworkUI extends JFrame implements KeyListener, ActionListener,
DocumentListener { DocumentListener {
@@ -60,6 +74,110 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
super.setVisible(b); super.setVisible(b);
} }
@Override
public void keyPressed(KeyEvent e) {
Object source = e.getSource();
if (source == proxyPort || source == proxyHost) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
actionPerformed(null);
}
}
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
@Override
public void insertUpdate(DocumentEvent arg0) {
if (proxyPort.isValid()) {
proxyPort.setText("" + proxyPort.getValue());
}
}
@Override
public void removeUpdate(DocumentEvent arg0) {
insertUpdate(arg0);
}
@Override
public void actionPerformed(ActionEvent arg0) {
boolean b = false;
if (arg0.getSource() == proxyType) {
Object o = proxyType.getSelectedItem();
authCheckBox.setEnabled(o == ProxyType.SOCKS5);
proxyHost.setEnabled(o != ProxyType.NONE);
proxyPort.setEnabled(o != ProxyType.NONE);
b = true;
}
if (b || arg0.getSource() == authCheckBox) {
b = authCheckBox.isSelected() && authCheckBox.isEnabled();
ProxySocket.auth = b;
authUsername.setEnabled(b);
authPassword.setEnabled(b);
return;
}
if (proxyType.getSelectedItem() != ProxyType.NONE) {
if (proxyPort.getText().equals("")
|| proxyHost.getText().equals("")) {
UILog.log("Error", "Please supply proxy information!",
JOptionPane.ERROR_MESSAGE);
return;
}
}
String username = authUsername.getText();
char[] password = authPassword.getPassword();
ProxySocket
.setLogin(username, password);
byte[] mac = new byte[macList.length];
for (int i = 0; i < mac.length; i++) {
mac[i] = (byte) Short.parseShort(
macList[i].getSelectedValue(), 16);
}
NetworkInterface.setMac(mac);
try {
if (ProxySocket.getConnectionCount() > 0) {
try {
System.out.println("Closing Existing Connections...");
ProxySocket.closeConnections();
} catch (Exception e) {
}
}
ProxyType type = (ProxyType) proxyType.getSelectedItem();
String host = proxyHost.getText();
int port = proxyPort.getValue();
ProxySocket.setProxy(type, host, port);
UILog.log("Info", "Network settings have been set!");
} catch (Exception e) {
UILog.log("Error",
"Unable to set proxy info!\n\nReason:" + e.getMessage());
e.printStackTrace();
}
setVisible(false);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void initGUI() { private void initGUI() {
proxyType = new JComboBox<ProxyType>(ProxyType.values()); proxyType = new JComboBox<ProxyType>(ProxyType.values());
@@ -187,110 +305,6 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
return ret; return ret;
} }
@Override
public void keyPressed(KeyEvent e) {
Object source = e.getSource();
if (source == proxyPort || source == proxyHost) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
actionPerformed(null);
}
}
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
@Override
public void insertUpdate(DocumentEvent arg0) {
if (proxyPort.isValid()) {
proxyPort.setText("" + proxyPort.getValue());
}
}
@Override
public void removeUpdate(DocumentEvent arg0) {
insertUpdate(arg0);
}
@Override
public void actionPerformed(ActionEvent arg0) {
boolean b = false;
if (arg0.getSource() == proxyType) {
Object o = proxyType.getSelectedItem();
authCheckBox.setEnabled(o == ProxyType.SOCKS5);
proxyHost.setEnabled(o != ProxyType.NONE);
proxyPort.setEnabled(o != ProxyType.NONE);
b = true;
}
if (b || arg0.getSource() == authCheckBox) {
b = authCheckBox.isSelected() && authCheckBox.isEnabled();
ProxySocket.auth = b;
authUsername.setEnabled(b);
authPassword.setEnabled(b);
return;
}
if (proxyType.getSelectedItem() != ProxyType.NONE) {
if (proxyPort.getText().equals("")
|| proxyHost.getText().equals("")) {
UILog.log("Error", "Please supply proxy information!",
JOptionPane.ERROR_MESSAGE);
return;
}
}
String username = authUsername.getText();
char[] password = authPassword.getPassword();
ProxySocket
.setLogin(username, password);
byte[] mac = new byte[macList.length];
for (int i = 0; i < mac.length; i++) {
mac[i] = (byte) Short.parseShort(
(String) macList[i].getSelectedValue(), 16);
}
NetworkInterface.setMac(mac);
try {
if (ProxySocket.getConnectionCount() > 0) {
try {
System.out.println("Closing Existing Connections...");
ProxySocket.closeConnections();
} catch (Exception e) {
}
}
ProxyType type = (ProxyType) proxyType.getSelectedItem();
String host = proxyHost.getText();
int port = proxyPort.getValue();
ProxySocket.setProxy(type, host, port);
UILog.log("Info", "Network settings have been set!");
} catch (Exception e) {
UILog.log("Error",
"Unable to set proxy info!\n\nReason:" + e.getMessage());
e.printStackTrace();
}
setVisible(false);
}
private JList<String> createMacList() { private JList<String> createMacList() {
String[] hexStrings = new String[256]; String[] hexStrings = new String[256];
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
@@ -312,10 +326,6 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
super("" + defval, size); super("" + defval, size);
} }
protected Document createDefaultModel() {
return new IntTextDocument();
}
public boolean isValid() { public boolean isValid() {
try { try {
int i = Integer.parseInt(getText()); int i = Integer.parseInt(getText());
@@ -333,6 +343,10 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
} }
} }
protected Document createDefaultModel() {
return new IntTextDocument();
}
class IntTextDocument extends PlainDocument { class IntTextDocument extends PlainDocument {
/** /**
* *
@@ -4,11 +4,16 @@ import org.parabot.core.Context;
import org.parabot.core.Core; import org.parabot.core.Core;
import org.parabot.environment.randoms.Random; import org.parabot.environment.randoms.Random;
import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
/** /**
* @author JKetelaar * @author JKetelaar
*/ */
@@ -7,18 +7,27 @@ import org.parabot.core.reflect.RefClass;
import org.parabot.core.reflect.RefField; import org.parabot.core.reflect.RefField;
import org.parabot.environment.api.utils.StringUtils; import org.parabot.environment.api.utils.StringUtils;
import javax.swing.*; import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.HashMap;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode; import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.HashMap;
/** /**
* A Reflection explorer * A Reflection explorer
@@ -27,16 +36,16 @@ import java.util.HashMap;
*/ */
public class ReflectUI extends JFrame { public class ReflectUI extends JFrame {
private static final long serialVersionUID = 98565034137367257L; private static final long serialVersionUID = 98565034137367257L;
private JTree tree; private final JTree tree;
private DefaultMutableTreeNode root; private final DefaultMutableTreeNode root;
private DefaultTreeModel model; private final DefaultTreeModel model;
private JEditorPane basicInfoPane; private final JEditorPane basicInfoPane;
private JEditorPane selectionInfoPane; private final JEditorPane selectionInfoPane;
private Object instance; private final Object instance;
private HashMap<DefaultMutableTreeNode, RefClass> classes; private final HashMap<DefaultMutableTreeNode, RefClass> classes;
private HashMap<DefaultMutableTreeNode, RefField> fields; private final HashMap<DefaultMutableTreeNode, RefField> fields;
public ReflectUI() { public ReflectUI() {
this.root = new DefaultMutableTreeNode("Classes"); this.root = new DefaultMutableTreeNode("Classes");
@@ -267,7 +276,7 @@ public class ReflectUI extends JFrame {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("<h1>").append(refClass.getClassName()).append("</h1><br/>"); builder.append("<h1>").append(refClass.getClassName()).append("</h1><br/>");
if (refClass.getClassName().contains(".")) { if (refClass.getClassName().contains(".")) {
builder.append("<b>Package: </b>").append(refClass.getClassName().substring(0, refClass.getClassName().lastIndexOf("."))).append("<br/>"); builder.append("<b>Package: </b>").append(refClass.getClassName(), 0, refClass.getClassName().lastIndexOf(".")).append("<br/>");
} }
builder.append("<b>Abstract: </b>").append(refClass.isAbstract() ? "yes" : "no").append("<br/>"); builder.append("<b>Abstract: </b>").append(refClass.isAbstract() ? "yes" : "no").append("<br/>");
builder.append("<b>Interface: </b>").append(refClass.isInterface() ? "yes" : "no").append("<br/>"); builder.append("<b>Interface: </b>").append(refClass.isInterface() ? "yes" : "no").append("<br/>");
@@ -5,25 +5,35 @@ import org.parabot.core.Context;
import org.parabot.core.Directories; import org.parabot.core.Directories;
import org.parabot.core.desc.ScriptDescription; import org.parabot.core.desc.ScriptDescription;
import org.parabot.core.parsers.scripts.ScriptParser; import org.parabot.core.parsers.scripts.ScriptParser;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.scripts.Category; import org.parabot.environment.scripts.Category;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.HashMap;
/** /**
* Script Selector GUI, shows all scripts * Script Selector GUI, shows all scripts
@@ -35,12 +45,12 @@ public final class ScriptSelector extends JFrame {
public static ScriptParser parser; public static ScriptParser parser;
private final int WIDTH; private final int WIDTH;
private final int HEIGHT; private final int HEIGHT;
private HashMap<String, DefaultMutableTreeNode> categories; private final HashMap<String, DefaultMutableTreeNode> categories;
private HashMap<String, ScriptDescription> format; private final HashMap<String, ScriptDescription> format;
private DefaultMutableTreeNode root; private final DefaultMutableTreeNode root;
private DefaultTreeModel model; private final DefaultTreeModel model;
private Font fontCategory = new Font("Arial", Font.BOLD, 12); private final Font fontCategory = new Font("Arial", Font.BOLD, 12);
private Font fontScript = new Font("Arial", Font.PLAIN, 12); private final Font fontScript = new Font("Arial", Font.PLAIN, 12);
private JTree tree; private JTree tree;
private JEditorPane scriptInfo; private JEditorPane scriptInfo;
@@ -212,7 +222,7 @@ public final class ScriptSelector extends JFrame {
} }
private class ScriptTreeCellRenderer implements TreeCellRenderer { private class ScriptTreeCellRenderer implements TreeCellRenderer {
private JLabel label; private final JLabel label;
ScriptTreeCellRenderer() { ScriptTreeCellRenderer() {
label = new JLabel(); label = new JLabel();
@@ -6,11 +6,14 @@ import org.parabot.core.parsers.servers.ServerParser;
import org.parabot.core.ui.components.ServerComponent; import org.parabot.core.ui.components.ServerComponent;
import org.parabot.environment.Environment; import org.parabot.environment.Environment;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*; import java.awt.Dimension;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/** /**
* Shows a list of every supported server which can be started * Shows a list of every supported server which can be started
* *
@@ -69,6 +72,22 @@ public class ServerSelector extends JPanel {
return instance; return instance;
} }
/**
* Fetches array of server widgets
*
* @return widgets array
*/
public Queue<ServerComponent> getServers() {
final Queue<ServerComponent> widgets = new LinkedList<>();
ServerDescription[] servers = ServerParser.getDescriptions();
if (servers != null) {
for (ServerDescription desc : servers) {
widgets.add(new ServerComponent(desc));
}
}
return widgets;
}
/** /**
* This method is called when -server argument is given, or -uuid arg is given. * This method is called when -server argument is given, or -uuid arg is given.
* *
@@ -101,20 +120,4 @@ public class ServerSelector extends JPanel {
return false; return false;
} }
/**
* Fetches array of server widgets
*
* @return widgets array
*/
public Queue<ServerComponent> getServers() {
final Queue<ServerComponent> widgets = new LinkedList<>();
ServerDescription[] servers = ServerParser.getDescriptions();
if (servers != null) {
for (ServerDescription desc : servers) {
widgets.add(new ServerComponent(desc));
}
}
return widgets;
}
} }
@@ -2,8 +2,12 @@ package org.parabot.core.ui.components;
import org.parabot.core.Context; import org.parabot.core.Context;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*; import java.awt.Color;
import java.awt.Dimension;
import javax.swing.GroupLayout;
import javax.swing.JPanel;
/** /**
* Main panel where applets are added. * Main panel where applets are added.
@@ -4,10 +4,14 @@ import org.parabot.core.Context;
import org.parabot.environment.api.interfaces.Paintable; import org.parabot.environment.api.interfaces.Paintable;
import org.parabot.environment.api.utils.Time; import org.parabot.environment.api.utils.Time;
import javax.swing.*; import java.awt.AlphaComposite;
import java.awt.*; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.JComponent;
/** /**
* The panel that is painted on * The panel that is painted on
* *
@@ -1,6 +1,10 @@
package org.parabot.core.ui.components; package org.parabot.core.ui.components;
import java.awt.*; import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
/** /**
@@ -9,12 +13,12 @@ import java.awt.geom.Rectangle2D;
* @author Everel * @author Everel
*/ */
public class ProgressBar { public class ProgressBar {
private final int width;
private final int height;
private final Color backColor;
private double value; private double value;
private int width;
private int height;
private double locX; private double locX;
private Color progColor; private Color progColor;
private Color backColor;
private FontMetrics fontMetrics; private FontMetrics fontMetrics;
private String text; private String text;
@@ -53,9 +57,9 @@ public class ProgressBar {
100 + (2 * val), 0); 100 + (2 * val), 0);
}*/ }*/
int r = (int) (((double) (225 - 218) * (double) val) / ((double) 100.D)); int r = (int) (((double) (225 - 218) * (double) val) / 100.D);
int g = (int) (((double) (253 - 165) * (double) val) / ((double) 100.D)); int g = (int) (((double) (253 - 165) * (double) val) / 100.D);
int b = (int) (((double) (145 - 32) * (double) val) / ((double) 100.D)); int b = (int) (((double) (145 - 32) * (double) val) / 100.D);
this.progColor = new Color(255 - r, 253 - g, 145 - b); this.progColor = new Color(255 - r, 253 - g, 145 - b);
} }
@@ -75,7 +79,7 @@ public class ProgressBar {
g2.fill(new Rectangle2D.Double(x, y, locX, height)); g2.fill(new Rectangle2D.Double(x, y, locX, height));
int value = (int) getValue(); int value = (int) getValue();
String percent = Integer.toString(value) + "% " + text; String percent = value + "% " + text;
int strX = (x + (width / 2)) - (fontMetrics.stringWidth(percent) / 2); int strX = (x + (width / 2)) - (fontMetrics.stringWidth(percent) / 2);
g2.setColor(Color.white); g2.setColor(Color.white);
@@ -4,12 +4,18 @@ import org.parabot.core.desc.ServerDescription;
import org.parabot.core.ui.fonts.Fonts; import org.parabot.core.ui.fonts.Fonts;
import org.parabot.environment.Environment; import org.parabot.environment.Environment;
import javax.swing.*; import java.awt.Color;
import java.awt.*; 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.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import javax.swing.JPanel;
/** /**
* A neat looking server component * A neat looking server component
* *
@@ -18,9 +24,8 @@ import java.awt.event.MouseMotionListener;
public class ServerComponent extends JPanel implements MouseListener, public class ServerComponent extends JPanel implements MouseListener,
MouseMotionListener { MouseMotionListener {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final String name;
public ServerDescription desc; public ServerDescription desc;
private String name;
private boolean hovered; private boolean hovered;
public ServerComponent(final ServerDescription desc) { public ServerComponent(final ServerDescription desc) {
@@ -10,14 +10,32 @@ import org.parabot.core.ui.fonts.Fonts;
import org.parabot.core.ui.images.Images; import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.utils.UILog; import org.parabot.core.ui.utils.UILog;
import javax.swing.*; import java.awt.BasicStroke;
import java.awt.*; 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.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp; 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 * An informative JPanel which tells the user what bot is doing
* *
@@ -39,10 +57,12 @@ public class VerboseLoader extends JPanel implements ProgressListener {
} }
}; };
private final BufferedImage background;
private final BufferedImage banner;
private final BufferedImage loginBox;
private final ProgressBar progressBar;
private int currentState; private int currentState;
private FontMetrics fontMetrics; private FontMetrics fontMetrics;
private BufferedImage background, banner, loginBox;
private ProgressBar progressBar;
private JPanel loginPanel; private JPanel loginPanel;
private VerboseLoader(String username, String password) { private VerboseLoader(String username, String password) {
@@ -8,7 +8,6 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL;
/** /**
* A JavaFX Panel embedded into a Swing JFrame - handles notification settings * A JavaFX Panel embedded into a Swing JFrame - handles notification settings
@@ -1,15 +1,16 @@
package org.parabot.core.ui.components.notifications; package org.parabot.core.ui.components.notifications;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
import org.parabot.api.notifications.NotificationManager; import org.parabot.api.notifications.NotificationManager;
import org.parabot.api.notifications.types.NotificationType; import org.parabot.api.notifications.types.NotificationType;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
/** /**
* @author JKetelaar * @author JKetelaar
*/ */
@@ -1,9 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.Button?>
<?import javafx.scene.layout.*?> <?import javafx.scene.control.CheckBox?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="500.0" minWidth="500.0" <?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="500.0"
minWidth="500.0"
prefHeight="503.0" prefWidth="735.0" xmlns="http://javafx.com/javafx/8"> prefHeight="503.0" prefWidth="735.0" xmlns="http://javafx.com/javafx/8">
<top> <top>
<MenuBar BorderPane.alignment="CENTER"> <MenuBar BorderPane.alignment="CENTER">
@@ -1,6 +1,6 @@
package org.parabot.core.ui.fonts; package org.parabot.core.ui.fonts;
import java.awt.*; import java.awt.Font;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@@ -1,6 +1,7 @@
package org.parabot.core.ui.fonts; package org.parabot.core.ui.fonts;
import java.awt.*; import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException; import java.io.IOException;
/** /**
@@ -8,7 +9,7 @@ import java.io.IOException;
*/ */
public class ParabotFont { public class ParabotFont {
private String location; private final String location;
private Font font; private Font font;
public ParabotFont(String location, float size) { public ParabotFont(String location, float size) {
@@ -24,10 +25,6 @@ public class ParabotFont {
} }
} }
private Font createFont(float size) throws IOException, FontFormatException {
return Font.createFont(Font.TRUETYPE_FONT, Fonts.class.getResourceAsStream(this.location)).deriveFont(size);
}
public float getSize() { public float getSize() {
return font.getSize(); return font.getSize();
} }
@@ -45,11 +42,13 @@ public class ParabotFont {
if (obj != null) { if (obj != null) {
if (obj instanceof ParabotFont) { if (obj instanceof ParabotFont) {
ParabotFont otherFont = (ParabotFont) obj; ParabotFont otherFont = (ParabotFont) obj;
if (otherFont.getSize() == this.getSize()) { return otherFont.getSize() == this.getSize();
return true;
}
} }
} }
return false; return false;
} }
private Font createFont(float size) throws IOException, FontFormatException {
return Font.createFont(Font.TRUETYPE_FONT, Fonts.class.getResourceAsStream(this.location)).deriveFont(size);
}
} }
@@ -20,11 +20,6 @@ public class PBKeyListener implements KeyListener {
this.fillBindings(); this.fillBindings();
} }
private void fillBindings() {
this.bindings.add(new ActionEventBinding(KeyEvent.VK_R, "Run"));
this.bindings.add(new ActionEventBinding(KeyEvent.VK_R, "Stop"));
}
public List<Binding> getBindings() { public List<Binding> getBindings() {
return bindings; return bindings;
} }
@@ -63,4 +58,9 @@ public class PBKeyListener implements KeyListener {
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
} }
private void fillBindings() {
this.bindings.add(new ActionEventBinding(KeyEvent.VK_R, "Run"));
this.bindings.add(new ActionEventBinding(KeyEvent.VK_R, "Stop"));
}
} }
@@ -7,7 +7,7 @@ import org.parabot.core.ui.BotUI;
*/ */
public class ActionEventBinding extends Binding { public class ActionEventBinding extends Binding {
private String actionString; private final String actionString;
public ActionEventBinding(int key, String actionString) { public ActionEventBinding(int key, String actionString) {
super(key); super(key);
@@ -1,6 +1,6 @@
package org.parabot.core.ui.utils; package org.parabot.core.ui.utils;
import javax.swing.*; import javax.swing.JOptionPane;
/** /**
* Log messages to the log user interface which is attached to the bot user interface * Log messages to the log user interface which is attached to the bot user interface
@@ -17,7 +17,7 @@ import java.util.LinkedList;
*/ */
public class Environment extends org.parabot.api.io.libraries.Environment { public class Environment extends org.parabot.api.io.libraries.Environment {
private static LinkedList<Library> libs = new LinkedList<>(); private static final LinkedList<Library> libs = new LinkedList<>();
static { static {
libs.add(new JavaFX()); libs.add(new JavaFX());
@@ -1,6 +1,6 @@
package org.parabot.environment.api.interfaces; package org.parabot.environment.api.interfaces;
import java.awt.*; import java.awt.Graphics;
/** /**
* @author Everel * @author Everel
@@ -10,6 +10,6 @@ public interface Paintable {
/** /**
* @param g * @param g
*/ */
public void paint(Graphics g); void paint(Graphics g);
} }
@@ -1,6 +1,11 @@
package org.parabot.environment.api.utils; package org.parabot.environment.api.utils;
import java.io.*; import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.file.Files; import java.nio.file.Files;
import java.security.MessageDigest; import java.security.MessageDigest;
@@ -27,7 +32,7 @@ public class FileUtil {
byte[] mdbytes = md.digest(); byte[] mdbytes = md.digest();
StringBuilder sb = new StringBuilder(""); StringBuilder sb = new StringBuilder();
for (int i = 0; i < mdbytes.length; i++) { for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1)); sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
} }
@@ -91,7 +96,9 @@ public class FileUtil {
* Reads the contents of a text file * Reads the contents of a text file
* *
* @param file file to get contents from * @param file file to get contents from
*
* @return file contents * @return file contents
*
* @throws IOException when anything goes wrong * @throws IOException when anything goes wrong
*/ */
public static String getFileContents(File file) throws IOException { public static String getFileContents(File file) throws IOException {
@@ -103,6 +110,7 @@ public class FileUtil {
* *
* @param file file to write to * @param file file to write to
* @param contents contents to write to given file * @param contents contents to write to given file
*
* @throws IOException when anything goes wrong * @throws IOException when anything goes wrong
*/ */
public static void writeFileContents(File file, String contents) throws IOException { public static void writeFileContents(File file, String contents) throws IOException {
@@ -15,5 +15,5 @@ public interface Filter<F> {
* *
* @return <b>true</b> to include this object, otherwise <b>false</b> to exclude. * @return <b>true</b> to include this object, otherwise <b>false</b> to exclude.
*/ */
public boolean accept(F f); boolean accept(F f);
} }
@@ -13,8 +13,8 @@ import java.util.HashMap;
* @author AlexanderBielen * @author AlexanderBielen
*/ */
public class PBLocalPreferences { public class PBLocalPreferences {
private static JSONParser parser = new JSONParser(); private static final JSONParser parser = new JSONParser();
private File settingsFile; private final File settingsFile;
public PBLocalPreferences(String fileName) { public PBLocalPreferences(String fileName) {
settingsFile = new File(Directories.getSettingsPath() + "/" + secureFileName(fileName)); settingsFile = new File(Directories.getSettingsPath() + "/" + secureFileName(fileName));
@@ -75,6 +75,7 @@ public class PBLocalPreferences {
* Fetches a setting * Fetches a setting
* *
* @param key key to get the value for * @param key key to get the value for
*
* @return value that belongs to given key or null if non-existent * @return value that belongs to given key or null if non-existent
*/ */
public String getSetting(String key) { public String getSetting(String key) {
@@ -110,6 +111,7 @@ public class PBLocalPreferences {
* Replaces all double dots to make sure the link does not leave the settings folder * Replaces all double dots to make sure the link does not leave the settings folder
* *
* @param filePath path to secure * @param filePath path to secure
*
* @return secured string * @return secured string
*/ */
private static String secureFileName(String filePath) { private static String secureFileName(String filePath) {
@@ -25,37 +25,14 @@ public class PBPreferences {
PBPreferences.manager = manager; PBPreferences.manager = manager;
} }
}; };
private final int scriptID;
private Properties properties; private Properties properties;
private int scriptID;
public PBPreferences(int scriptID) { public PBPreferences(int scriptID) {
this.scriptID = scriptID; this.scriptID = scriptID;
this.updateSettings(); this.updateSettings();
} }
private void updateSettings() {
properties = new Properties();
try {
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/" + scriptID,
"apikey=" + manager.getAccount().getApi())
);
JSONArray resultArray;
if ((resultArray = ((JSONArray) result.get("result"))) != null) {
for (Object rObject : resultArray) {
JSONObject resultObject = (JSONObject) rObject;
for (Object map : resultObject.entrySet()) {
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) map;
properties.put(pairs.getKey(), pairs.getValue());
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}
/** /**
* Change a setting * Change a setting
* *
@@ -99,7 +76,7 @@ public class PBPreferences {
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/set/", WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/set/",
"apikey=" + manager.getAccount().getApi() + "apikey=" + manager.getAccount().getApi() +
"&key=" + URLEncoder.encode(String.valueOf(key), "UTF-8") + "&key=" + URLEncoder.encode(String.valueOf(key), "UTF-8") +
"&script=" + String.valueOf(scriptID) "&script=" + scriptID
) )
); );
if ((boolean) result.get("result")) { if ((boolean) result.get("result")) {
@@ -123,7 +100,7 @@ public class PBPreferences {
"apikey=" + manager.getAccount().getApi() + "apikey=" + manager.getAccount().getApi() +
"&key=" + URLEncoder.encode(String.valueOf(key), "UTF-8") + "&key=" + URLEncoder.encode(String.valueOf(key), "UTF-8") +
"&value=" + URLEncoder.encode(String.valueOf(value), "UTF-8") + "&value=" + URLEncoder.encode(String.valueOf(value), "UTF-8") +
"&script=" + String.valueOf(scriptID) "&script=" + scriptID
) )
); );
if ((boolean) result.get("result")) { if ((boolean) result.get("result")) {
@@ -134,4 +111,27 @@ public class PBPreferences {
} }
} }
private void updateSettings() {
properties = new Properties();
try {
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/" + scriptID,
"apikey=" + manager.getAccount().getApi())
);
JSONArray resultArray;
if ((resultArray = ((JSONArray) result.get("result"))) != null) {
for (Object rObject : resultArray) {
JSONObject resultObject = (JSONObject) rObject;
for (Object map : resultObject.entrySet()) {
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) map;
properties.put(pairs.getKey(), pairs.getValue());
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}
} }
@@ -113,6 +113,7 @@ public class Timer {
* *
* @param gained total gained amount * @param gained total gained amount
* @param startAmount start amount * @param startAmount start amount
*
* @return hourly gains * @return hourly gains
*/ */
public int getPerHour(final int gained, final int startAmount) { public int getPerHour(final int gained, final int startAmount) {
@@ -5,7 +5,7 @@ import org.parabot.core.ui.utils.UILog;
public class Version implements Comparable<Version> { public class Version implements Comparable<Version> {
private static boolean notified; private static boolean notified;
private String version; private final String version;
public Version(String version) { public Version(String version) {
if (version == null) { if (version == null) {
@@ -17,19 +17,6 @@ public class Version implements Comparable<Version> {
this.version = version; this.version = version;
} }
private static void notifyRC() {
if (!notified) {
UILog.log(
"Version warning",
"This is an RC version of Parabot\n" +
"This could be an unstable version of Parabot, and might crash at anytime\n\n" +
"If you find an error within the client, please report any at:\n" +
"https://github.com/Parabot/Parabot/issues"
);
notified = true;
}
}
public final String get() { public final String get() {
return this.version; return this.version;
} }
@@ -72,4 +59,17 @@ public class Version implements Comparable<Version> {
public boolean equals(Object that) { public boolean equals(Object that) {
return this == that || that != null && this.getClass() == that.getClass() && this.compareTo((Version) that) == 0; return this == that || that != null && this.getClass() == that.getClass() && this.compareTo((Version) that) == 0;
} }
private static void notifyRC() {
if (!notified) {
UILog.log(
"Version warning",
"This is an RC version of Parabot\n" +
"This could be an unstable version of Parabot, and might crash at anytime\n\n" +
"If you find an error within the client, please report any at:\n" +
"https://github.com/Parabot/Parabot/issues"
);
notified = true;
}
}
} }
@@ -14,6 +14,7 @@ public class WebUtil extends org.parabot.api.io.WebUtil {
* *
* @param url url to get the JSON string from * @param url url to get the JSON string from
* @param key key to search for in the JSON string * @param key key to search for in the JSON string
*
* @return value that belongs to given key * @return value that belongs to given key
*/ */
public static String getJsonValue(String url, String key) { public static String getJsonValue(String url, String key) {
@@ -75,7 +75,7 @@ public abstract class ExceptionHandler implements Thread.UncaughtExceptionHandle
SCRIPT("Script"), SCRIPT("Script"),
CLIENT("Client"); CLIENT("Client");
private String name; private final String name;
ExceptionType(String name) { ExceptionType(String name) {
this.name = name; this.name = name;
@@ -4,11 +4,12 @@ import org.parabot.core.Directories;
import org.parabot.core.ui.utils.UILog; import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.FileUtil; import org.parabot.environment.api.utils.FileUtil;
import javax.swing.*; import java.awt.Desktop;
import java.awt.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.swing.JOptionPane;
/** /**
* Writes exceptions to a file and reports the file location back to the user * Writes exceptions to a file and reports the file location back to the user
*/ */
@@ -2,7 +2,7 @@ package org.parabot.environment.input;
import org.parabot.core.Context; import org.parabot.core.Context;
import java.awt.*; import java.awt.Component;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.util.HashMap; import java.util.HashMap;
@@ -14,13 +14,12 @@ import java.util.Random;
* @author Everel, Matt, Dane * @author Everel, Matt, Dane
*/ */
public class Keyboard implements KeyListener { public class Keyboard implements KeyListener {
private static HashMap<Character, Character> specialChars;
/** /**
* {@code KeyEvent.VK_ENTER} is actually New Line, '\n'. * {@code KeyEvent.VK_ENTER} is actually New Line, '\n'.
* The code for the Enter button is 13. It has no associated {@link KeyEvent} constant. * The code for the Enter button is 13. It has no associated {@link KeyEvent} constant.
*/ */
public static final int ENTER_KEYCODE = 13; public static final int ENTER_KEYCODE = 13;
private static final HashMap<Character, Character> specialChars;
static { static {
char[] spChars = { '~', '!', '@', '#', '%', '^', '&', '*', '(', ')', char[] spChars = { '~', '!', '@', '#', '%', '^', '&', '*', '(', ')',
@@ -33,7 +32,7 @@ public class Keyboard implements KeyListener {
} }
} }
private Component component; private final Component component;
private long pressTime; private long pressTime;
public Keyboard(Component component) { public Keyboard(Component component) {
@@ -44,15 +43,6 @@ public class Keyboard implements KeyListener {
return Context.getInstance().getKeyboard(); return Context.getInstance().getKeyboard();
} }
/**
* Generates a random number in the range of 40-140.
* @return The random number
*/
private static long getRandom() {
Random rand = new Random();
return rand.nextInt(100) + 40;
}
/** /**
* Types the given String and afterwards presses Enter. * Types the given String and afterwards presses Enter.
* *
@@ -64,6 +54,7 @@ public class Keyboard implements KeyListener {
/** /**
* Types the given String and optionally presses Enter afterwards. * Types the given String and optionally presses Enter afterwards.
*
* @param s The String to type. * @param s The String to type.
* @param enterAfter True if {@code KeyEvent.VK_ENTER} should be pressed afterwards. This is actually the '\n' character, for New Line. Useful for logging in. * @param enterAfter True if {@code KeyEvent.VK_ENTER} should be pressed afterwards. This is actually the '\n' character, for New Line. Useful for logging in.
*/ */
@@ -87,6 +78,7 @@ public class Keyboard implements KeyListener {
/** /**
* Creates and sends a single KeyEvent using the given Char. * Creates and sends a single KeyEvent using the given Char.
*
* @param c The char to send. * @param c The char to send.
*/ */
public void clickKey(char c) { public void clickKey(char c) {
@@ -100,6 +92,7 @@ public class Keyboard implements KeyListener {
/** /**
* Creates and sends a given KeyEvent using the given keyCode. * Creates and sends a given KeyEvent using the given keyCode.
* <p>Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER} * <p>Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER}
*
* @param keyCode The keycode to send. * @param keyCode The keycode to send.
*/ */
public void clickKey(int keyCode) { public void clickKey(int keyCode) {
@@ -114,6 +107,7 @@ public class Keyboard implements KeyListener {
* Creates and sends a given PRESS KeyEvent using the given keyCode. Note, this does not send a Release Event * Creates and sends a given PRESS KeyEvent using the given keyCode. Note, this does not send a Release Event
* typically associated with a key click. * typically associated with a key click.
* <p>Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER} * <p>Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER}
*
* @param keyCode * @param keyCode
*/ */
public void pressKey(int keyCode) { public void pressKey(int keyCode) {
@@ -127,6 +121,7 @@ public class Keyboard implements KeyListener {
* Creates and sends a given RELEASE KeyEvent using the given keyCode. Note, this does not send a Press Event * Creates and sends a given RELEASE KeyEvent using the given keyCode. Note, this does not send a Press Event
* typically associated with a key click. * typically associated with a key click.
* <p>Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER} * <p>Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER}
*
* @param keyCode * @param keyCode
*/ */
public void releaseKey(int keyCode) { public void releaseKey(int keyCode) {
@@ -136,13 +131,81 @@ public class Keyboard implements KeyListener {
sendKeyEvent(ke); sendKeyEvent(ke);
} }
/**
* Actually triggers sending of a given KeyEvent in the instance of KeyListeners' {@code component} field.
*
* @param e
*/
public void sendKeyEvent(KeyEvent e) {
for (KeyListener kl : component.getKeyListeners()) {
if (kl instanceof Keyboard) {
continue;
}
if (!e.isConsumed()) {
switch (e.getID()) {
case KeyEvent.KEY_PRESSED:
kl.keyPressed(e);
break;
case KeyEvent.KEY_RELEASED:
kl.keyReleased(e);
break;
case KeyEvent.KEY_TYPED:
kl.keyTyped(e);
break;
}
}
}
}
/**
* Allows the {@code KeyListener.keyPressed} event to be overridden.
*
* @param e
*/
@Override
public void keyPressed(KeyEvent e) {
}
/**
* Allows the {@code KeyListener.keyReleased} event to be overridden.
*
* @param e
*/
@Override
public void keyReleased(KeyEvent e) {
}
/**
* Allows the {@code KeyListener.keyTyped} event to be overridden.
*
* @param e
*/
@Override
public void keyTyped(KeyEvent e) {
}
/**
* Generates a random number in the range of 40-140.
*
* @return The random number
*/
private static long getRandom() {
Random rand = new Random();
return rand.nextInt(100) + 40;
}
/** /**
* Creates KeyEvents to perform a Click of the given Char. This includes a Press, Typed and Release event * Creates KeyEvents to perform a Click of the given Char. This includes a Press, Typed and Release event
* in addition to an initial shiftDown and ending shiftUp if the character is a Special Char such as {@code !"£$%^&*(} * in addition to an initial shiftDown and ending shiftUp if the character is a Special Char such as {@code !"£$%^&*(}
* * <p>
* {@see specialChars} * {@see specialChars}
*
* @param target Component this event is linked to. * @param target Component this event is linked to.
* @param c Char to send. * @param c Char to send.
*
* @return KeyEvents for each action. * @return KeyEvents for each action.
*/ */
private KeyEvent[] createKeyClick(Component target, char c) { private KeyEvent[] createKeyClick(Component target, char c) {
@@ -187,8 +250,10 @@ public class Keyboard implements KeyListener {
/** /**
* Creates KeyEvents for Press and Release of the given keyCode. * Creates KeyEvents for Press and Release of the given keyCode.
*
* @param target * @param target
* @param keyCode * @param keyCode
*
* @return An array containing Press and Release KeyEvents. * @return An array containing Press and Release KeyEvents.
*/ */
private KeyEvent[] createKeyClick(Component target, int keyCode) { private KeyEvent[] createKeyClick(Component target, int keyCode) {
@@ -198,8 +263,10 @@ public class Keyboard implements KeyListener {
/** /**
* Creates a Press type KeyEvent * Creates a Press type KeyEvent
*
* @param target * @param target
* @param keyCode * @param keyCode
*
* @return * @return
*/ */
private KeyEvent createKeyPress(Component target, int keyCode) { private KeyEvent createKeyPress(Component target, int keyCode) {
@@ -223,8 +290,10 @@ public class Keyboard implements KeyListener {
/** /**
* Creates a Release type KeyEvent * Creates a Release type KeyEvent
*
* @param target * @param target
* @param keyCode * @param keyCode
*
* @return * @return
*/ */
private KeyEvent createKeyRelease(Component target, int keyCode) { private KeyEvent createKeyRelease(Component target, int keyCode) {
@@ -234,56 +303,4 @@ public class Keyboard implements KeyListener {
return released; return released;
} }
/**
* Actually triggers sending of a given KeyEvent in the instance of KeyListeners' {@code component} field.
* @param e
*/
public void sendKeyEvent(KeyEvent e) {
for (KeyListener kl : component.getKeyListeners()) {
if (kl instanceof Keyboard) {
continue;
}
if (!e.isConsumed()) {
switch (e.getID()) {
case KeyEvent.KEY_PRESSED:
kl.keyPressed(e);
break;
case KeyEvent.KEY_RELEASED:
kl.keyReleased(e);
break;
case KeyEvent.KEY_TYPED:
kl.keyTyped(e);
break;
}
}
}
}
/**
* Allows the {@code KeyListener.keyPressed} event to be overridden.
* @param e
*/
@Override
public void keyPressed(KeyEvent e) {
}
/**
* Allows the {@code KeyListener.keyReleased} event to be overridden.
* @param e
*/
@Override
public void keyReleased(KeyEvent e) {
}
/**
* Allows the {@code KeyListener.keyTyped} event to be overridden.
* @param e
*/
@Override
public void keyTyped(KeyEvent e) {
}
} }
@@ -3,7 +3,8 @@ package org.parabot.environment.input;
import org.parabot.core.Context; import org.parabot.core.Context;
import org.parabot.environment.api.utils.Time; import org.parabot.environment.api.utils.Time;
import java.awt.*; import java.awt.Component;
import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
@@ -14,7 +15,7 @@ import java.awt.event.MouseMotionListener;
* @author Everel * @author Everel
*/ */
public class Mouse implements MouseListener, MouseMotionListener { public class Mouse implements MouseListener, MouseMotionListener {
private Component component; private final Component component;
private int x; private int x;
private int y; private int y;
@@ -10,32 +10,32 @@ public interface Random {
* *
* @return <b>true</b> if this random should be activate * @return <b>true</b> if this random should be activate
*/ */
public boolean activate(); boolean activate();
/** /**
* Executes this random * Executes this random
*/ */
public void execute(); void execute();
/** /**
* Returns the name of the random * Returns the name of the random
* *
* @return Name of the random * @return Name of the random
*/ */
public String getName(); String getName();
/** /**
* Returns the name of the server which the random is made for * Returns the name of the server which the random is made for
* *
* @return Name of the server * @return Name of the server
*/ */
public String getServer(); String getServer();
/** /**
* Returns the RandomType of the random * Returns the RandomType of the random
* *
* @return The RandomType of the random * @return The RandomType of the random
*/ */
public RandomType getRandomType(); RandomType getRandomType();
} }
@@ -10,12 +10,11 @@ import java.util.ArrayList;
* @author JKetelaar * @author JKetelaar
*/ */
public class RandomHandler { public class RandomHandler {
private ArrayList<Random> randoms;
/** /**
* The randoms that will actually run * The randoms that will actually run
*/ */
private ArrayList<Random> activeRandoms; private final ArrayList<Random> activeRandoms;
private ArrayList<Random> randoms;
public RandomHandler() { public RandomHandler() {
this.randoms = new ArrayList<>(); this.randoms = new ArrayList<>();
@@ -10,8 +10,8 @@ public enum RandomType {
ON_SERVER_START(2, "On server start"), ON_SERVER_START(2, "On server start"),
ON_SCRIPT_FINISH(3, "On script finish"); ON_SCRIPT_FINISH(3, "On script finish");
private int id; private final int id;
private String name; private final String name;
RandomType(int id, String name) { RandomType(int id, String name) {
this.id = id; this.id = id;
@@ -17,7 +17,7 @@ public enum Category {
/** /**
* Cache * Cache
*/ */
private static HashMap<String, BufferedImage> images = new HashMap<>(); private static final HashMap<String, BufferedImage> images = new HashMap<>();
static { static {
images.put("script", Images.getResource("/storage/images/category/script.png")); images.put("script", Images.getResource("/storage/images/category/script.png"));
@@ -8,8 +8,11 @@ import org.parabot.environment.api.utils.PBPreferences;
import org.parabot.environment.api.utils.Time; import org.parabot.environment.api.utils.Time;
import org.parabot.environment.randoms.Random; import org.parabot.environment.randoms.Random;
import org.parabot.environment.randoms.RandomType; import org.parabot.environment.randoms.RandomType;
import org.parabot.environment.scripts.framework.*; import org.parabot.environment.scripts.framework.AbstractFramework;
import org.parabot.environment.scripts.framework.Frameworks; import org.parabot.environment.scripts.framework.Frameworks;
import org.parabot.environment.scripts.framework.LoopTask;
import org.parabot.environment.scripts.framework.SleepCondition;
import org.parabot.environment.scripts.framework.Strategy;
import java.util.Collection; import java.util.Collection;
@@ -9,11 +9,12 @@ import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.scripts.Script; import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.loader.JavaScriptLoader; import org.parabot.environment.scripts.loader.JavaScriptLoader;
import javax.swing.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import javax.swing.JOptionPane;
/** /**
* Loads a script from the BDN * Loads a script from the BDN
* *
@@ -10,7 +10,7 @@ import java.lang.reflect.Constructor;
* @author Everel * @author Everel
*/ */
public class LocalScriptExecuter extends ScriptExecuter { public class LocalScriptExecuter extends ScriptExecuter {
private Constructor<?> scriptConstructor; private final Constructor<?> scriptConstructor;
public LocalScriptExecuter(final Constructor<?> scriptConstructor) { public LocalScriptExecuter(final Constructor<?> scriptConstructor) {
this.scriptConstructor = scriptConstructor; this.scriptConstructor = scriptConstructor;
@@ -42,7 +42,7 @@ class Looper extends AbstractFramework {
} }
class StrategyWorker extends AbstractFramework { class StrategyWorker extends AbstractFramework {
private Collection<Strategy> strategies; private final Collection<Strategy> strategies;
public StrategyWorker(Collection<Strategy> strategies) { public StrategyWorker(Collection<Strategy> strategies) {
this.strategies = strategies; this.strategies = strategies;
@@ -10,6 +10,6 @@ public interface LoopTask {
/** /**
* @return sleepTime in ms * @return sleepTime in ms
*/ */
public int loop(); int loop();
} }
@@ -12,7 +12,7 @@ public interface SleepCondition {
* *
* @return <b>true</b> if valid, otherwise <b>false</b>. * @return <b>true</b> if valid, otherwise <b>false</b>.
*/ */
public boolean isValid(); boolean isValid();
} }
@@ -12,11 +12,11 @@ public interface Strategy {
* *
* @return <b>true</b> if this strategy should be executed, otherwise <b>false</b>. * @return <b>true</b> if this strategy should be executed, otherwise <b>false</b>.
*/ */
public boolean activate(); boolean activate();
/** /**
* Executes this strategy * Executes this strategy
*/ */
public void execute(); void execute();
} }
@@ -14,7 +14,7 @@ import java.util.List;
* @author Everel * @author Everel
*/ */
public class JavaScriptLoader extends ASMClassLoader { public class JavaScriptLoader extends ASMClassLoader {
private ClassPath classPath; private final ClassPath classPath;
public JavaScriptLoader(ClassPath classPath) { public JavaScriptLoader(ClassPath classPath) {
super(classPath); super(classPath);
@@ -13,25 +13,25 @@ public interface Random {
* *
* @return <b>true</b> if this random should activate * @return <b>true</b> if this random should activate
*/ */
public boolean activate(); boolean activate();
/** /**
* Executes this random * Executes this random
*/ */
public void execute(); void execute();
/** /**
* Returns the name of the random * Returns the name of the random
* *
* @return Name of the random * @return Name of the random
*/ */
public String getName(); String getName();
/** /**
* Returns the name of the server which the random is made for * Returns the name of the server which the random is made for
* *
* @return Name of the server * @return Name of the server
*/ */
public String getServer(); String getServer();
} }
@@ -17,8 +17,8 @@ import java.net.MalformedURLException;
@Deprecated @Deprecated
public class LocalServerExecuter extends ServerExecuter { public class LocalServerExecuter extends ServerExecuter {
private final ServerProvider serverProvider; private final ServerProvider serverProvider;
private ClassPath classPath; private final ClassPath classPath;
private String serverName; private final String serverName;
public LocalServerExecuter(ServerProvider serverProvider, public LocalServerExecuter(ServerProvider serverProvider,
ClassPath classPath, final String serverName) { ClassPath classPath, final String serverName) {
@@ -11,14 +11,17 @@ import org.parabot.environment.input.Keyboard;
import org.parabot.environment.input.Mouse; import org.parabot.environment.input.Mouse;
import org.parabot.environment.scripts.Script; import org.parabot.environment.scripts.Script;
import javax.swing.*;
import java.applet.Applet; import java.applet.Applet;
import java.applet.AppletStub; import java.applet.AppletStub;
import java.awt.*; import java.awt.Desktop;
import java.awt.Dimension;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
/** /**
* Provides a server to the bot * Provides a server to the bot
* *
@@ -13,21 +13,22 @@ import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.servers.ServerProvider; import org.parabot.environment.servers.ServerProvider;
import org.parabot.environment.servers.loader.ServerLoader; import org.parabot.environment.servers.loader.ServerLoader;
import javax.swing.*;
import java.io.File; import java.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.net.URL; import java.net.URL;
import javax.swing.JOptionPane;
/** /**
* Fetches a server provider from the local config file * Fetches a server provider from the local config file
* *
* @author JKetelaar * @author JKetelaar
*/ */
public class LocalPublicServerExecuter extends ServerExecuter { public class LocalPublicServerExecuter extends ServerExecuter {
private String serverName; private final String serverName;
private String serverUrl; private final String serverUrl;
private String providerUrl; private final String providerUrl;
private ServerProviderInfo serverProviderInfo; private final ServerProviderInfo serverProviderInfo;
public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) { public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) {
this.serverName = serverName; this.serverName = serverName;
@@ -16,8 +16,8 @@ import java.net.MalformedURLException;
*/ */
public class LocalServerExecuter extends ServerExecuter { public class LocalServerExecuter extends ServerExecuter {
private final Constructor<?> serverProviderConstructor; private final Constructor<?> serverProviderConstructor;
private ClassPath classPath; private final ClassPath classPath;
private String serverName; private final String serverName;
public LocalServerExecuter(Constructor<?> serverProviderConstructor, public LocalServerExecuter(Constructor<?> serverProviderConstructor,
ClassPath classPath, final String serverName) { ClassPath classPath, final String serverName) {

Some files were not shown because too many files have changed in this diff Show More