Moved randoms from provider to client

This commit is contained in:
JKetelaar
2015-02-03 14:05:06 +01:00
parent e11e8ec154
commit 7c2b76094e
3 changed files with 2 additions and 80 deletions
+1 -5
View File
@@ -14,7 +14,6 @@ import org.parabot.environment.servers.ServerManifest;
import org.parabot.environment.servers.ServerProvider;
import org.parabot.environment.servers.Type;
import org.rev317.min.accessors.Client;
import org.rev317.min.randoms.Executer;
import org.rev317.min.script.ScriptEngine;
import org.rev317.min.ui.BotMenu;
@@ -29,8 +28,6 @@ import java.net.URL;
@ServerManifest(author = "Everel & JKetelaar", name = "Server name here", type = Type.INJECTION, version = 2.1)
public class Loader extends ServerProvider {
private boolean extended = true;
//private HookFile hookFile = new HookFile(Context.getInstance().getServerProviderInfo().getExtendedHookFile(), HookFile.TYPE_XML);
//private HookFile hookFile = new HookFile(Context.getInstance().getServerProviderInfo().getHookFile(), HookFile.TYPE_XML);
public static Client getClient() {
return (Client) Context.getInstance().getClient();
@@ -102,7 +99,6 @@ public class Loader extends ServerProvider {
@Override
public void init() {
Executer executer = new Executer();
executer.getRandoms();
}
}
+1 -1
View File
@@ -212,7 +212,7 @@ public class Bank {
*/
public static void depositAllExcept(int... exceptions) {
if (Bank.isOpen()) {
final ArrayList<Integer> ignored = new ArrayList<Integer>();
final ArrayList<Integer> ignored = new ArrayList<>();
for (int i : exceptions) {
ignored.add(i);
}
-74
View File
@@ -1,74 +0,0 @@
package org.rev317.min.randoms;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.io.ProgressListener;
import org.parabot.environment.api.utils.WebUtil;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
/**
* @author JKetelaar
*/
public class Executer {
/* TODO Move to client */
public void getRandoms() {
Core.verbose("Downloading randoms");
downloadRandoms();
Core.verbose("Parsing random(s)");
parseRandoms();
}
private void parseRandoms() {
File myJar = new File(Directories.getCachePath() + "/randoms.jar");
if (!myJar.exists() || !myJar.canRead()) {
return;
}
try {
URL url = myJar.toURI().toURL();
URL[] urls = new URL[]{url};
String server = Context.getInstance().getServerProviderInfo().getServerName();
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
Class<?> classToLoad = Class.forName("org.parabot.randoms.Core", true, child);
Method method = classToLoad.getDeclaredMethod("init", String.class);
Object instance = classToLoad.newInstance();
Object result = method.invoke(instance, server);
Core.verbose("Parsed random(s)!");
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | MalformedURLException e) {
e.printStackTrace();
Core.verbose("Failed to parse random(s)...");
}
}
private void downloadRandoms() {
try {
File random = new File(Directories.getCachePath() + "/randoms.jar");
if (random.exists()) {
Core.verbose("Random already exists, no need to download it.");
return;
}
String downloadLink = "http://bdn.parabot.org/api/get.php?action=randoms";
WebUtil.downloadFile(new URL(downloadLink), random, new ProgressListener() {
@Override
public void onProgressUpdate(double v) {
}
@Override
public void updateDownloadSpeed(double v) {
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}