diff --git a/.travis.yml b/.travis.yml index 2e90b62..5b5dea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ env: - secure: UG+b1tEgc8xv9x4r//2OAIK1RrYv6n209KTTFMMwcnAa7DI8HaP8nljRa5/VhDhuKHdlVrYH/tI90v7UVBs0GDVNwK5V17Io0fMm3FUGZekSthTCqqno5wAGa9r6a6mMLtSaSmIFeIKi0+0d2ZwplRuhj/dtEYjjBBj+kK8g4nE= - secure: St/fecUDInFBCRriYqgp2F8PU9/SooorgxD9Mrs+b0EsC7AbtSsQXvdIv2Lp6xzdQ0VSXPcLIhULPOYrmBKnGQ/NjXTIZXxnroyQxxnI6xyEWIZwiHRY/bKRJDRbQTxD9NL32szKiDSwnw7pu6llF4D64UqQvziq4Gm6VohU75M= - secure: bD15GVZWowiknbfLavh8CxSh0GsnF5kT4kZ6ggCuUDGyj0mzqf7dNRnchQIKkCG0WRYyTrFN4pEiygeywWsipEeAVv9Xhx3cuUZmzeQaR5KCWabSwJ8gK6jZd1YhcWmM9vrdPHobZr65MP0y/8mu/Fovgky9dY7KDf4G3SebNrM= - - PARABOT_VERSION=2.6.0 + - PARABOT_VERSION=2.6.2 cache: directories: @@ -53,5 +53,7 @@ deploy: acl: public_read on: repo: Parabot/Parabot - all_branches: true + branch: + - master + - development jdk: 'oraclejdk7' diff --git a/README.md b/README.md index dd1421e..b263025 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Parabot -Parabot V2.5. +Parabot V2.6.2. #### Website diff --git a/pom.xml b/pom.xml index ee19873..0f5810a 100755 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.parabot client - 2.6.0 + 2.6.2 jar @@ -67,13 +67,13 @@ junit junit - 4.11 + 4.12 provided org.parabot internal-api - 1.4.41 + 1.4.46 diff --git a/src/main/java/org/parabot/core/Context.java b/src/main/java/org/parabot/core/Context.java index bc11df5..a880890 100644 --- a/src/main/java/org/parabot/core/Context.java +++ b/src/main/java/org/parabot/core/Context.java @@ -14,8 +14,8 @@ import org.parabot.core.ui.listeners.PBKeyListener; import org.parabot.environment.api.interfaces.Paintable; import org.parabot.environment.input.Keyboard; import org.parabot.environment.input.Mouse; +import org.parabot.environment.randoms.RandomHandler; import org.parabot.environment.scripts.Script; -import org.parabot.environment.scripts.randoms.RandomHandler; import org.parabot.environment.servers.ServerProvider; import java.applet.Applet; diff --git a/src/main/java/org/parabot/core/ui/BotUI.java b/src/main/java/org/parabot/core/ui/BotUI.java index 4764c78..e2f8b1c 100644 --- a/src/main/java/org/parabot/core/ui/BotUI.java +++ b/src/main/java/org/parabot/core/ui/BotUI.java @@ -6,12 +6,11 @@ import org.parabot.core.Directories; import org.parabot.core.ui.components.GamePanel; import org.parabot.core.ui.components.VerboseLoader; import org.parabot.core.ui.images.Images; -import org.parabot.core.ui.listeners.PBKeyListener; import org.parabot.core.ui.utils.SwingUtil; import org.parabot.environment.OperatingSystem; import org.parabot.environment.api.utils.StringUtils; +import org.parabot.environment.randoms.Random; import org.parabot.environment.scripts.Script; -import org.parabot.environment.scripts.randoms.Random; import javax.imageio.ImageIO; import javax.swing.*; diff --git a/src/main/java/org/parabot/core/ui/RandomUI.java b/src/main/java/org/parabot/core/ui/RandomUI.java index 6774f95..2581266 100644 --- a/src/main/java/org/parabot/core/ui/RandomUI.java +++ b/src/main/java/org/parabot/core/ui/RandomUI.java @@ -2,7 +2,7 @@ package org.parabot.core.ui; import org.parabot.core.Context; import org.parabot.core.Core; -import org.parabot.environment.scripts.randoms.Random; +import org.parabot.environment.randoms.Random; import javax.swing.*; import java.awt.event.ActionEvent; diff --git a/src/main/java/org/parabot/environment/randoms/Random.java b/src/main/java/org/parabot/environment/randoms/Random.java new file mode 100644 index 0000000..716b585 --- /dev/null +++ b/src/main/java/org/parabot/environment/randoms/Random.java @@ -0,0 +1,41 @@ +package org.parabot.environment.randoms; + +/** + * @author JKetelaar + */ +public interface Random { + + /** + * Determines whether this random should activate + * + * @return true if this random should be activate + */ + public boolean activate(); + + /** + * Executes this random + */ + public void execute(); + + /** + * Returns the name of the random + * + * @return Name of the random + */ + public String getName(); + + /** + * Returns the name of the server which the random is made for + * + * @return Name of the server + */ + public String getServer(); + + /** + * Returns the RandomType of the random + * + * @return The RandomType of the random + */ + public RandomType getRandomType(); + +} diff --git a/src/main/java/org/parabot/environment/randoms/RandomHandler.java b/src/main/java/org/parabot/environment/randoms/RandomHandler.java new file mode 100644 index 0000000..c1dee3e --- /dev/null +++ b/src/main/java/org/parabot/environment/randoms/RandomHandler.java @@ -0,0 +1,139 @@ +package org.parabot.environment.randoms; + +import org.parabot.core.Core; +import org.parabot.core.parsers.randoms.RandomParser; +import org.parabot.core.ui.Logger; + +import java.util.ArrayList; + +/** + * @author JKetelaar + */ +public class RandomHandler { + private ArrayList randoms; + + /** + * The randoms that will actually run + */ + private ArrayList activeRandoms; + + public RandomHandler() { + this.randoms = new ArrayList<>(); + this.activeRandoms = new ArrayList<>(); + } + + public void init() { + RandomParser.enable(); + checkAndRun(RandomType.ON_SERVER_START); + } + + /** + * Adds a random to the random list + * + * @param random The random that will be added to the arraylist + */ + public void addRandom(Random random) { + if (random == null) { + throw new NullPointerException("Null random"); + } + for (Random r : randoms) { + if (r.getClass() == random.getClass()) { + Core.verbose("Ignored added random, duplicate."); + return; + } + } + randoms.add(random); + setActive(random); + } + + /** + * @param random + * @deprecated + */ + @Deprecated + public void addRandom(org.parabot.environment.scripts.randoms.Random random) { + new IllegalArgumentException("This type of random is deprecated").printStackTrace(); + } + + /** + * Adds a random to the active randoms + * + * @param random + */ + public void setActive(Random random) { + this.activeRandoms.add(random); + } + + /** + * Adds a random to the active randoms + * + * @param random + */ + public void setActive(String random) { + for (Random r : this.randoms) { + if (r.getName().equalsIgnoreCase(random.toLowerCase())) { + this.activeRandoms.add(r); + } + } + } + + /** + * Sets the whole random arraylist to the arraylist given as argument + * + * @param randoms The new random arraylist + */ + public void setRandoms(ArrayList randoms) { + this.randoms = randoms; + } + + /** + * Clears all added randoms + */ + public void clearRandoms() { + this.randoms.clear(); + } + + /** + * Clears all active randoms + */ + public void clearActiveRandoms() { + this.activeRandoms.clear(); + } + + /** + * Checks if random occurs and runs it + * + * @return returns true if a random has been executed, otherwise false + */ + public boolean checkAndRun(RandomType type) { + for (Random r : this.activeRandoms) { + if (r.getRandomType().getId() == type.getId() && r.activate()) { + Logger.addMessage("Running random '" + r.getName() + "'", true); + r.execute(); + return true; + } + } + return false; + } + + /** + * Checks if random occurs and runs it + * + * @return returns true if a random has been executed, otherwise false + * @see RandomHandler#checkAndRun(RandomType) + * @deprecated + */ + @Deprecated + public boolean checkAndRun() { + new IllegalArgumentException("This method is deprecated").printStackTrace(); + return false; + } + + public ArrayList getRandoms() { + return this.randoms; + } + + public ArrayList getActiveRandoms() { + return this.activeRandoms; + } +} \ No newline at end of file diff --git a/src/main/java/org/parabot/environment/randoms/RandomType.java b/src/main/java/org/parabot/environment/randoms/RandomType.java new file mode 100644 index 0000000..250bd9a --- /dev/null +++ b/src/main/java/org/parabot/environment/randoms/RandomType.java @@ -0,0 +1,32 @@ +package org.parabot.environment.randoms; + +/** + * @author JKetelaar + */ +public enum RandomType { + + SCRIPT(0, "Script"), + ON_SCRIPT_START(0, "On script start"), + ON_SERVER_START(0, "On server start"), + ON_SCRIPT_FINISH(0, "On script finish"); + + private int id; + private String name; + + RandomType(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public static RandomType getDefault() { + return SCRIPT; + } +} diff --git a/src/main/java/org/parabot/environment/scripts/Script.java b/src/main/java/org/parabot/environment/scripts/Script.java index aa33f4b..2e646e9 100644 --- a/src/main/java/org/parabot/environment/scripts/Script.java +++ b/src/main/java/org/parabot/environment/scripts/Script.java @@ -6,6 +6,7 @@ import org.parabot.core.ui.BotUI; import org.parabot.core.ui.Logger; import org.parabot.environment.api.utils.PBPreferences; import org.parabot.environment.api.utils.Time; +import org.parabot.environment.randoms.RandomType; import org.parabot.environment.scripts.framework.*; import org.parabot.environment.scripts.framework.Frameworks; import org.parabot.environment.scripts.randoms.Random; @@ -13,170 +14,173 @@ import org.parabot.environment.scripts.randoms.Random; import java.util.Collection; /** - * * Script template, scripts are 'add-ons' which executes various tasks in-game * * @author Everel - * */ public class Script implements Runnable { - public static final int TYPE_STRATEGY = 0; - public static final int TYPE_LOOP = 1; - public static final int TYPE_OTHER = 2; + public static final int TYPE_STRATEGY = 0; + public static final int TYPE_LOOP = 1; + public static final int TYPE_OTHER = 2; - public static final int STATE_RUNNING = 0; - public static final int STATE_PAUSE = 1; - public static final int STATE_STOPPED = 2; + public static final int STATE_RUNNING = 0; + public static final int STATE_PAUSE = 1; + public static final int STATE_STOPPED = 2; - private Collection strategies; - private PBPreferences preferences; - private AbstractFramework frameWork; - private int state; - private int frameWorkType; - private int scriptID; + private Collection strategies; + private PBPreferences preferences; + private AbstractFramework frameWork; + private int state; + private int frameWorkType; + private int scriptID; - public boolean onExecute() { - return true; - } + public boolean onExecute() { + return true; + } - public void onFinish() { + public void onFinish() { - } + } - public final void provide(final Collection strategies) { - this.strategies = strategies; - } + public final void provide(final Collection strategies) { + this.strategies = strategies; + } - public final int getFrameWorkType() { - return frameWorkType; - } + public final int getFrameWorkType() { + return frameWorkType; + } - public final void setFrameWork(int frameWorkType) { - if(frameWorkType < 0 || frameWorkType > 2) { - throw new RuntimeException("Invalid framework type"); - } - this.frameWorkType = frameWorkType; - } + public final void setFrameWork(int frameWorkType) { + if (frameWorkType < 0 || frameWorkType > 2) { + throw new RuntimeException("Invalid framework type"); + } + this.frameWorkType = frameWorkType; + } - public final void setAbstractFrameWork(AbstractFramework f) { - this.frameWork = f; - } + public final void setAbstractFrameWork(AbstractFramework f) { + this.frameWork = f; + } - public final void addRandom(Random random) { - Context.getInstance().getRandomHandler().addRandom(random); - } + public final void addRandom(Random random) { + Context.getInstance().getRandomHandler().addRandom(random); + } - @Override - public final void run() { - Context context = Context.getInstance(); + @Override + public final void run() { + Context context = Context.getInstance(); - Core.verbose("Initializing script..."); - context.getServerProvider().initScript(this); - Core.verbose("Done."); + Core.verbose("Initializing script..."); + context.getServerProvider().initScript(this); + Core.verbose("Done."); - if(!onExecute()) { - Core.verbose("Script#onExecute returned false, unloading and stopping script..."); - context.getServerProvider().unloadScript(this); - this.state = STATE_STOPPED; - Core.verbose("Done."); - return; - } + if (!onExecute()) { + Core.verbose("Script#onExecute returned false, unloading and stopping script..."); + context.getServerProvider().unloadScript(this); + this.state = STATE_STOPPED; + Core.verbose("Done."); + return; + } - Core.verbose("Detecting script framework..."); - context.setRunningScript(this); - BotUI.getInstance().toggleRun(); - if(this instanceof LoopTask) { - Core.verbose("Script framework detected: LoopTask"); - frameWorkType = TYPE_LOOP; - frameWork = Frameworks.getLooper((LoopTask) this); - } else if(strategies != null && !strategies.isEmpty()) { - Core.verbose("Script framework detected: Strategies"); - frameWorkType = TYPE_STRATEGY; - frameWork = Frameworks.getStrategyWorker(strategies); - } else { - Core.verbose("Unknown script framework: Other"); - frameWorkType = TYPE_OTHER; - } - Core.verbose("Running script..."); - Logger.addMessage("Script started.", true); - try { - while(this.state != STATE_STOPPED) { - if(context.getRandomHandler().checkAndRun()) { - continue; - } + context.getRandomHandler().checkAndRun(RandomType.ON_SCRIPT_START); - if(this.state == STATE_PAUSE) { - sleep(500); - continue; - } - if(!frameWork.execute()) { - break; - } - } - } catch (Throwable t) { - t.printStackTrace(); - } - Core.verbose("Script stopped/finished, unloading and stopping..."); - onFinish(); - Logger.addMessage("Script stopped.", false); - context.getServerProvider().unloadScript(this); - this.state = STATE_STOPPED; - context.setRunningScript(null); + Core.verbose("Detecting script framework..."); + context.setRunningScript(this); + BotUI.getInstance().toggleRun(); + if (this instanceof LoopTask) { + Core.verbose("Script framework detected: LoopTask"); + frameWorkType = TYPE_LOOP; + frameWork = Frameworks.getLooper((LoopTask) this); + } else if (strategies != null && !strategies.isEmpty()) { + Core.verbose("Script framework detected: Strategies"); + frameWorkType = TYPE_STRATEGY; + frameWork = Frameworks.getStrategyWorker(strategies); + } else { + Core.verbose("Unknown script framework: Other"); + frameWorkType = TYPE_OTHER; + } + Core.verbose("Running script..."); + Logger.addMessage("Script started.", true); + try { + while (this.state != STATE_STOPPED) { + if (context.getRandomHandler().checkAndRun(RandomType.SCRIPT)) { + continue; + } - Core.verbose("Resetting key bindings..."); - Context.getInstance().getPbKeyListener().resetBindings(); + if (this.state == STATE_PAUSE) { + sleep(500); + continue; + } + if (!frameWork.execute()) { + break; + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + Core.verbose("Script stopped/finished, unloading and stopping..."); + onFinish(); - BotUI.getInstance().toggleRun(); - Core.verbose("Done."); - } + context.getRandomHandler().checkAndRun(RandomType.ON_SCRIPT_FINISH); - /** - * Sleeps until the SleepCondition is valid. - * - * DEPRECATED! use {@link Time#sleep(SleepCondition, int)} - * - * @param conn - * the condition. - * @param timeout - * the time in miliseconds before it stops sleeping. - * @return whether it ran successfully without timing out. - */ - @Deprecated - public final boolean sleep(SleepCondition conn, int timeout) { - return Time.sleep(conn, timeout); - } + Logger.addMessage("Script stopped.", false); + context.getServerProvider().unloadScript(this); + this.state = STATE_STOPPED; + context.setRunningScript(null); - /** - * Sets the script's state - * @param state - */ - public final void setState(final int state) { - if(state < 0 || state > 2) { - throw new IllegalArgumentException("Illegal state"); - } - this.state = state; - } + Core.verbose("Resetting key bindings..."); + Context.getInstance().getPbKeyListener().resetBindings(); - /** - * Sleeps for an amount of milliseconds - * @param ms - */ - public final void sleep(int ms) { - Time.sleep(ms); - } + BotUI.getInstance().toggleRun(); + Core.verbose("Done."); + } - public int getState() { - return state; - } + /** + * Sleeps until the SleepCondition is valid. + *

+ * DEPRECATED! use {@link Time#sleep(SleepCondition, int)} + * + * @param conn the condition. + * @param timeout the time in miliseconds before it stops sleeping. + * @return whether it ran successfully without timing out. + */ + @Deprecated + public final boolean sleep(SleepCondition conn, int timeout) { + return Time.sleep(conn, timeout); + } - public PBPreferences getPreferences(){ - if (this.preferences == null){ - this.preferences = new PBPreferences(scriptID); - } - return this.preferences; - } + /** + * Sets the script's state + * + * @param state + */ + public final void setState(final int state) { + if (state < 0 || state > 2) { + throw new IllegalArgumentException("Illegal state"); + } + this.state = state; + } - public void setScriptID(int scriptID){ - this.scriptID = scriptID; - } + /** + * Sleeps for an amount of milliseconds + * + * @param ms + */ + public final void sleep(int ms) { + Time.sleep(ms); + } + + public int getState() { + return state; + } + + public PBPreferences getPreferences() { + if (this.preferences == null) { + this.preferences = new PBPreferences(scriptID); + } + return this.preferences; + } + + public void setScriptID(int scriptID) { + this.scriptID = scriptID; + } } diff --git a/src/main/java/org/parabot/environment/scripts/randoms/Random.java b/src/main/java/org/parabot/environment/scripts/randoms/Random.java index 03a4fdb..07b9e04 100644 --- a/src/main/java/org/parabot/environment/scripts/randoms/Random.java +++ b/src/main/java/org/parabot/environment/scripts/randoms/Random.java @@ -1,18 +1,19 @@ package org.parabot.environment.scripts.randoms; /** - * * @author Everel - * + * @deprecated + * @see org.parabot.environment.randoms.Random */ +@Deprecated public interface Random { - + /** * Determines whether this random should activate * @return true if this random should activate */ public boolean activate(); - + /** * Executes this random */ diff --git a/src/main/java/org/parabot/environment/scripts/randoms/RandomHandler.java b/src/main/java/org/parabot/environment/scripts/randoms/RandomHandler.java index a40db78..12ffe85 100644 --- a/src/main/java/org/parabot/environment/scripts/randoms/RandomHandler.java +++ b/src/main/java/org/parabot/environment/scripts/randoms/RandomHandler.java @@ -1,108 +1,11 @@ package org.parabot.environment.scripts.randoms; -import org.parabot.core.Core; -import org.parabot.core.ui.Logger; - -import java.util.ArrayList; - /** - * * @author Everel - * + * @deprecated + * @see org.parabot.environment.randoms.RandomHandler */ -public class RandomHandler { - private ArrayList randoms; +@Deprecated +public class RandomHandler extends org.parabot.environment.randoms.RandomHandler { - /** - * The randoms that will actually run - */ - private ArrayList activeRandoms; - - public RandomHandler() { - this.randoms = new ArrayList<>(); - this.activeRandoms = new ArrayList<>(); - } - - /** - * Adds a random to the random list - * @param random The random that will be added to the arraylist - */ - public void addRandom(Random random) { - if(random == null) { - throw new NullPointerException("Null random"); - } - for(Random r : randoms) { - if(r.getClass() == random.getClass()) { - Core.verbose("Ignored added random, duplicate."); - return; - } - } - randoms.add(random); - setActive(random); - } - - /** - * Adds a random to the active randoms - * @param random - */ - public void setActive(Random random){ - this.activeRandoms.add(random); - } - - /** - * Adds a random to the active randoms - * @param random - */ - public void setActive(String random){ - for (Random r : this.randoms){ - if (r.getName().equalsIgnoreCase(random.toLowerCase())){ - this.activeRandoms.add(r); - } - } - } - - /** - * Sets the whole random arraylist to the arraylist given as argument - * @param randoms The new random arraylist - */ - public void setRandoms(ArrayList randoms){ - this.randoms = randoms; - } - - /** - * Clears all added randoms - */ - public void clearRandoms() { - this.randoms.clear(); - } - - /** - * Clears all active randoms - */ - public void clearActiveRandoms(){ - this.activeRandoms.clear(); - } - - /** - * Checks if random occurs and runs it - * @return returns true if a random has been executed, otherwise false - */ - public boolean checkAndRun() { - for(Random r : this.activeRandoms) { - if(r.activate()) { - Logger.addMessage("Running random '" + r.getName() + "'", true); - r.execute(); - return true; - } - } - return false; - } - - public ArrayList getRandoms(){ - return this.randoms; - } - - public ArrayList getActiveRandoms(){ - return this.activeRandoms; - } } \ No newline at end of file diff --git a/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java b/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java index 290bac9..f18712b 100644 --- a/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java +++ b/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java @@ -27,7 +27,8 @@ public abstract class ServerExecuter { Context context = Context.getInstance(provider); context.load(); PaintComponent.getInstance().startPainting(context); - RandomParser.enable(); + + Context.getInstance().getRandomHandler().init(); } catch (Throwable t) { t.printStackTrace(); }