mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 08:39:09 +00:00
Improved the random handler
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package org.parabot.environment.scripts.randoms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
@@ -11,14 +11,20 @@ import org.parabot.core.Core;
|
||||
*/
|
||||
public class RandomHandler {
|
||||
private ArrayList<Random> randoms;
|
||||
|
||||
/**
|
||||
* The randoms that will actually run
|
||||
*/
|
||||
private ArrayList<Random> activeRandoms;
|
||||
|
||||
public RandomHandler() {
|
||||
this.randoms = new ArrayList<>();
|
||||
this.activeRandoms = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a random to the random list
|
||||
* @param random
|
||||
* @param random The random that will be added to the arraylist
|
||||
*/
|
||||
public void addRandom(Random random) {
|
||||
if(random == null) {
|
||||
@@ -32,12 +38,39 @@ public class RandomHandler {
|
||||
}
|
||||
randoms.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<Random> randoms){
|
||||
this.randoms = randoms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all added randoms
|
||||
*/
|
||||
public void clearRandoms() {
|
||||
randoms.clear();
|
||||
this.randoms.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all active randoms
|
||||
*/
|
||||
public void clearActiveRandoms(){
|
||||
this.activeRandoms.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,12 +78,21 @@ public class RandomHandler {
|
||||
* @return returns <b>true</b> if a random has been executed, otherwise <b>false</b>
|
||||
*/
|
||||
public boolean checkAndRun() {
|
||||
for(Random r : randoms) {
|
||||
for(Random r : this.activeRandoms) {
|
||||
if(r.activate()) {
|
||||
Core.verbose("Running random '" + r.getName() + "'.");
|
||||
r.execute();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<Random> getRandoms(){
|
||||
return this.randoms;
|
||||
}
|
||||
|
||||
public ArrayList<Random> getActiveRandoms(){
|
||||
return this.activeRandoms;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user