mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
Moved random handler to different package
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package org.parabot.environment.scripts.randoms;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public interface Random {
|
||||
|
||||
/**
|
||||
* Determines whether this random should activate
|
||||
* @return <b>true</b> if this random should activate
|
||||
*/
|
||||
public boolean activate();
|
||||
|
||||
/**
|
||||
* Executes this random
|
||||
*/
|
||||
public void execute();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.parabot.environment.scripts.randoms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class RandomHandler {
|
||||
private ArrayList<Random> randoms;
|
||||
|
||||
public RandomHandler() {
|
||||
randoms = new ArrayList<Random>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a random to the random list
|
||||
* @param random
|
||||
*/
|
||||
public void addRandom(Random random) {
|
||||
randoms.add(random);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if random occures and runs it
|
||||
* @return returns <b>true</b> if a random has been executed, otherwise <b>false</b>
|
||||
*/
|
||||
public boolean checkAndRun() {
|
||||
for(Random r : randoms) {
|
||||
if(r.activate()) {
|
||||
r.execute();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user