mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
RandomHandler improved
This commit is contained in:
@@ -9,6 +9,7 @@ import org.parabot.environment.scripts.framework.Frameworks;
|
||||
import org.parabot.environment.scripts.framework.LoopTask;
|
||||
import org.parabot.environment.scripts.framework.SleepCondition;
|
||||
import org.parabot.environment.scripts.framework.Strategy;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -59,6 +60,10 @@ public class Script implements Runnable {
|
||||
public final void setAbstractFrameWork(AbstractFramework f) {
|
||||
this.frameWork = f;
|
||||
}
|
||||
|
||||
public final void addRandom(Random random) {
|
||||
Context.getInstance().getRandomHandler().addRandom(random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.parabot.environment.scripts.randoms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
@@ -11,7 +13,7 @@ public class RandomHandler {
|
||||
private ArrayList<Random> randoms;
|
||||
|
||||
public RandomHandler() {
|
||||
randoms = new ArrayList<>();
|
||||
this.randoms = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,8 +21,24 @@ public class RandomHandler {
|
||||
* @param random
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all added randoms
|
||||
*/
|
||||
public void clearRandoms() {
|
||||
randoms.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if random occurs and runs it
|
||||
|
||||
Reference in New Issue
Block a user