Added for tweaks for randoms

This commit is contained in:
JKetelaar
2014-12-17 13:05:08 +01:00
parent 461f3806af
commit ea2074f146
5 changed files with 27 additions and 22 deletions
+1 -1
View File
@@ -10,4 +10,4 @@
out out
*.iml *.iml
.idea .idea
Loader2.java DeprecatedLoader.java
+5 -3
View File
@@ -14,6 +14,7 @@ import org.parabot.environment.servers.ServerManifest;
import org.parabot.environment.servers.ServerProvider; import org.parabot.environment.servers.ServerProvider;
import org.parabot.environment.servers.Type; import org.parabot.environment.servers.Type;
import org.rev317.min.accessors.Client; import org.rev317.min.accessors.Client;
import org.rev317.min.randoms.Executer;
import org.rev317.min.script.ScriptEngine; import org.rev317.min.script.ScriptEngine;
import org.rev317.min.ui.BotMenu; import org.rev317.min.ui.BotMenu;
@@ -23,8 +24,8 @@ import java.io.File;
import java.net.URL; import java.net.URL;
/** /**
* @author Everel, JKetelaar * @author Everel, JKetelaar
*/ */
@ServerManifest(author = "Everel & JKetelaar", name = "Server name here", type = Type.INJECTION, version = 2.1) @ServerManifest(author = "Everel & JKetelaar", name = "Server name here", type = Type.INJECTION, version = 2.1)
public class Loader extends ServerProvider { public class Loader extends ServerProvider {
private boolean extended = true; private boolean extended = true;
@@ -101,6 +102,7 @@ public class Loader extends ServerProvider {
@Override @Override
public void init() { public void init() {
//new Downloader(); Executer executer = new Executer();
executer.getRandoms();
} }
} }
+1
View File
@@ -30,6 +30,7 @@ public class Bank {
public static int INV_PARENT_ID = 5064; public static int INV_PARENT_ID = 5064;
public static int BANK_OPEN_INDEX = 1; public static int BANK_OPEN_INDEX = 1;
static { static {
Properties p = Context.getInstance().getServerProviderInfo().getProperties(); Properties p = Context.getInstance().getServerProviderInfo().getProperties();
if (p.containsKey("bankInterface")) if (p.containsKey("bankInterface"))
BANK_INTERFACE = Integer.parseInt(p.getProperty("bankInterface")); BANK_INTERFACE = Integer.parseInt(p.getProperty("bankInterface"));
@@ -15,27 +15,27 @@ import java.net.URLClassLoader;
/** /**
* @author JKetelaar * @author JKetelaar
*/ */
public class Downloader { public class Executer {
//TODO: Move to parabot itself /* TODO Move to Parabot client */
public Downloader(){ public void getRandoms() {
if (downloadRandoms()) { Core.verbose("Downloading randoms");
Core.verbose("Parsing random(s)..."); downloadRandoms();
parseRandoms(); Core.verbose("Parsing random(s)");
}else{ parseRandoms();
Core.verbose("There do not seem to be any randoms for this server...");
}
} }
private void parseRandoms(){ private void parseRandoms() {
File myJar = new File(Directories.getCachePath() + "/randoms.jar"); File myJar = new File(Directories.getCachePath() + "/randoms.jar");
if (!myJar.exists() || !myJar.canRead()){ if (!myJar.exists() || !myJar.canRead()) {
return; return;
} }
try { try {
URL url = myJar.toURI().toURL(); URL url = myJar.toURI().toURL();
URL[] urls = new URL[]{url}; URL[] urls = new URL[]{url};
String server = "ikov"; // String server = Context.getInstance().getServerProviderInfo().getServerName();
String server = "pkhonor";
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader()); URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
Class<?> classToLoad = Class.forName("org.parabot.randoms.Core", true, child); Class<?> classToLoad = Class.forName("org.parabot.randoms.Core", true, child);
Method method = classToLoad.getDeclaredMethod("init", String.class); Method method = classToLoad.getDeclaredMethod("init", String.class);
@@ -44,17 +44,18 @@ public class Downloader {
Core.verbose("Parsed random(s)!"); Core.verbose("Parsed random(s)!");
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | MalformedURLException e) { } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();
Core.verbose("Failed to random(s)...");
} }
} }
private boolean downloadRandoms(){ private void downloadRandoms() {
try { try {
File random = new File(Directories.getCachePath() + "/randoms.jar"); File random = new File(Directories.getCachePath() + "/randoms.jar");
if (random.exists()){ if (random.exists()) {
Core.verbose("Random already exists, no need to download it."); Core.verbose("Random already exists, no need to download it.");
return true; return;
} }
String downloadLink = "http://sdn.parabot.org/randoms.php"; String downloadLink = "http://bdn.parabot.org/api/get.php?action=randoms";
WebUtil.downloadFile(new URL(downloadLink), random, new ProgressListener() { WebUtil.downloadFile(new URL(downloadLink), random, new ProgressListener() {
@Override @Override
public void onProgressUpdate(double v) { public void onProgressUpdate(double v) {
@@ -66,9 +67,8 @@ public class Downloader {
} }
}); });
return random.exists();
} catch (Exception e) { } catch (Exception e) {
return false; e.printStackTrace();
} }
} }
} }
+2
View File
@@ -1,6 +1,7 @@
package org.rev317.min.ui; package org.rev317.min.ui;
import org.parabot.core.Context; import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.environment.scripts.randoms.Random; import org.parabot.environment.scripts.randoms.Random;
import javax.swing.*; import javax.swing.*;
@@ -60,6 +61,7 @@ public class RandomUI implements ActionListener {
if (checkBox.isSelected()) { if (checkBox.isSelected()) {
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) { for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
if (r.getName().equalsIgnoreCase(checkBox.getText().toLowerCase())) { if (r.getName().equalsIgnoreCase(checkBox.getText().toLowerCase())) {
Core.verbose("Actived random '" + r.getName() + "'");
Context.getInstance().getRandomHandler().setActive(r.getName()); Context.getInstance().getRandomHandler().setActive(r.getName());
} }
} }