mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 00:38:16 +00:00
Merge pull request #207 from Parabot/bugfix/random-loop-run
[BUGFIX] Random loop run
This commit is contained in:
@@ -24,7 +24,7 @@ public class RandomHandler {
|
|||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
RandomParser.enable();
|
RandomParser.enable();
|
||||||
checkAndRun(RandomType.ON_SERVER_START);
|
runAll(RandomType.ON_SERVER_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,6 +100,40 @@ public class RandomHandler {
|
|||||||
this.activeRandoms.clear();
|
this.activeRandoms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a specific random
|
||||||
|
*
|
||||||
|
* @param r
|
||||||
|
* @return True if the random is executed, false if not
|
||||||
|
*/
|
||||||
|
public boolean executeRandom(Random r){
|
||||||
|
if (r.activate()) {
|
||||||
|
Logger.addMessage("Running random '" + r.getName() + "'", true);
|
||||||
|
try {
|
||||||
|
r.execute();
|
||||||
|
return true;
|
||||||
|
}catch (Exception e){
|
||||||
|
Logger.addMessage("Random failed: '" + r.getName() + "'", false);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs all randoms of a certain type
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public void runAll(RandomType type){
|
||||||
|
for (Random r : this.activeRandoms) {
|
||||||
|
if (r.getRandomType().getId() == type.getId()) {
|
||||||
|
executeRandom(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if random occurs and runs it
|
* Checks if random occurs and runs it
|
||||||
*
|
*
|
||||||
@@ -107,15 +141,8 @@ public class RandomHandler {
|
|||||||
*/
|
*/
|
||||||
public boolean checkAndRun(RandomType type) {
|
public boolean checkAndRun(RandomType type) {
|
||||||
for (Random r : this.activeRandoms) {
|
for (Random r : this.activeRandoms) {
|
||||||
if (r.getRandomType().getId() == type.getId() && r.activate()) {
|
if (r.getRandomType().getId() == type.getId()) {
|
||||||
Logger.addMessage("Running random '" + r.getName() + "'", true);
|
return executeRandom(r);
|
||||||
try {
|
|
||||||
r.execute();
|
|
||||||
}catch (Exception e){
|
|
||||||
Logger.addMessage("Random failed: '" + r.getName() + "'", false);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class Script implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.getRandomHandler().checkAndRun(RandomType.ON_SCRIPT_START);
|
context.getRandomHandler().runAll(RandomType.ON_SCRIPT_START);
|
||||||
|
|
||||||
Core.verbose("Detecting script framework...");
|
Core.verbose("Detecting script framework...");
|
||||||
context.setRunningScript(this);
|
context.setRunningScript(this);
|
||||||
@@ -120,7 +120,7 @@ public class Script implements Runnable {
|
|||||||
Core.verbose("Script stopped/finished, unloading and stopping...");
|
Core.verbose("Script stopped/finished, unloading and stopping...");
|
||||||
onFinish();
|
onFinish();
|
||||||
|
|
||||||
context.getRandomHandler().checkAndRun(RandomType.ON_SCRIPT_FINISH);
|
context.getRandomHandler().runAll(RandomType.ON_SCRIPT_FINISH);
|
||||||
|
|
||||||
Logger.addMessage("Script stopped.", false);
|
Logger.addMessage("Script stopped.", false);
|
||||||
context.getServerProvider().unloadScript(this);
|
context.getServerProvider().unloadScript(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user