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