v2.01 update

This commit is contained in:
Clisprail
2013-09-04 14:45:23 +02:00
parent 36f7e0407e
commit edb17e188b
89 changed files with 2866 additions and 847 deletions
@@ -0,0 +1,49 @@
package org.parabot.environment.servers;
import java.net.MalformedURLException;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.classpath.ClassPath;
/**
*
* Loads locally stored server providers
*
* @author Everel
*
*/
public class LocalServerExecuter extends ServerExecuter {
private final ServerProvider serverProvider;
private ClassPath classPath = null;
private String serverName = null;
public LocalServerExecuter(ServerProvider serverProvider,
ClassPath classPath, final String serverName) {
this.serverProvider = serverProvider;
this.classPath = classPath;
this.serverName = serverName;
}
@Override
public void run(ThreadGroup tg) {
// add jar or directory to buildpath.
if (this.classPath.isJar()) {
Core.verbose("Adding server provider jar to buildpath: "
+ this.classPath.lastParsed.toString());
this.classPath.addToBuildPath();
} else {
Core.verbose("Adding server providers directory to buildpath: "
+ Directories.getServerPath().getPath());
try {
BuildPath.add(Directories.getServerPath().toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
// finalize
super.finalize(tg, this.serverProvider, this.serverName);
}
}
@@ -0,0 +1,105 @@
package org.parabot.environment.servers;
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLEncoder;
import javax.swing.JOptionPane;
import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.classpath.ClassPath;
import org.parabot.core.ui.components.VerboseLoader;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.servers.loader.ServerLoader;
/**
*
* @author Everel
*
*/
public class PublicServerExecuter extends ServerExecuter {
private String serverName = null;
private String jarName = null;
public PublicServerExecuter(final String serverName, final String jarName) {
this.serverName = serverName;
this.jarName = jarName;
}
@Override
public void run(ThreadGroup tg) {
try {
final File destination = new File(Directories.getCachePath(),
this.jarName);
final String jarUrl = String.format(
Configuration.GET_SERVER_PROVIDER,
URLEncoder.encode(this.jarName, "UTF-8"));
Core.verbose("Downloading: " + jarUrl + " ...");
WebUtil.downloadFile(new URL(jarUrl), destination,
VerboseLoader.get());
Core.verbose("Server provider downloaded...");
final ClassPath classPath = new ClassPath();
classPath.addJar(destination);
BuildPath.add(destination.toURI().toURL());
ServerLoader serverLoader = new ServerLoader(classPath);
final String[] classNames = serverLoader.getServerClassNames();
if (classNames == null || classNames.length == 0) {
UILog.log(
"Error",
"Failed to load server provider, error: [No provider found in jar file.]",
JOptionPane.ERROR_MESSAGE);
return;
} else if (classNames.length > 1) {
UILog.log(
"Error",
"Failed to load server provider, error: [Multiple providers found in jar file.]");
return;
}
final String className = classNames[0];
try {
final Class<?> providerClass = serverLoader
.loadClass(className);
final Constructor<?> con = providerClass.getConstructor();
final ServerProvider serverProvider = (ServerProvider) con
.newInstance();
super.finalize(tg, serverProvider, this.serverName);
} catch (NoClassDefFoundError ignored) {
UILog.log(
"Error",
"Failed to load server provider, error: [This server provider is not compitable with this version of parabot]",
JOptionPane.ERROR_MESSAGE);
} catch (ClassNotFoundException ignored) {
UILog.log(
"Error",
"Failed to load server provider, error: [This server provider is not compitable with this version of parabot]",
JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {
t.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
}
}
@@ -0,0 +1,31 @@
package org.parabot.environment.servers;
import org.parabot.core.Context;
import org.parabot.core.ui.components.BotToolbar;
/**
*
* @author Everel
*
*/
public abstract class ServerExecuter {
public abstract void run(final ThreadGroup tg);
public void finalize(final ThreadGroup tg, final ServerProvider provider, final String serverName) {
// loads the server and its it to the gui
new Thread(tg, new Runnable() {
@Override
public void run() {
try {
final Context context = new Context(provider);
BotToolbar.getInstance().addTab(context, serverName);
context.load();
} catch (Throwable t) {
t.printStackTrace();
}
}
}).start();
}
}
@@ -5,7 +5,7 @@ import java.lang.annotation.RetentionPolicy;
/**
* A server manifest
* @author Clisprail
* @author Everel
*
*/
@Retention(RetentionPolicy.RUNTIME)
@@ -16,7 +16,7 @@ import org.parabot.environment.scripts.Script;
/**
* Provides a server to the bot
*
* @author Clisprail
* @author Everel
*
*/
public abstract class ServerProvider implements Opcodes {
@@ -4,7 +4,7 @@ package org.parabot.environment.servers;
*
* Bot type
*
* @author Clisprail
* @author Everel
*
*/
public enum Type {
@@ -12,7 +12,7 @@ import org.parabot.environment.servers.ServerProvider;
*
* An environment to load a server
*
* @author Clisprail
* @author Everel
*
*
*/