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