[FEATURE] Added methods to allow runs of multiple randoms

This commit is contained in:
JKetelaar
2017-04-23 01:39:33 +02:00
parent ed5b454260
commit 4831cae068
@@ -100,6 +100,40 @@ public class RandomHandler {
this.activeRandoms.clear();
}
/**
* Executes a specific random
*
* @param r
* @return True if the random is executed, false if not
*/
public boolean executeRandom(Random r){
if (r.activate()) {
Logger.addMessage("Running random '" + r.getName() + "'", true);
try {
r.execute();
return true;
}catch (Exception e){
Logger.addMessage("Random failed: '" + r.getName() + "'", false);
e.printStackTrace();
}
}
return false;
}
/**
* Runs all randoms of a certain type
*
* @param type
*/
public void runAll(RandomType type){
for (Random r : this.activeRandoms) {
if (r.getRandomType().getId() == type.getId()) {
executeRandom(r);
}
}
}
/**
* Checks if random occurs and runs it
*
@@ -107,15 +141,8 @@ public class RandomHandler {
*/
public boolean checkAndRun(RandomType type) {
for (Random r : this.activeRandoms) {
if (r.getRandomType().getId() == type.getId() && r.activate()) {
Logger.addMessage("Running random '" + r.getName() + "'", true);
try {
r.execute();
}catch (Exception e){
Logger.addMessage("Random failed: '" + r.getName() + "'", false);
e.printStackTrace();
}
return true;
if (r.getRandomType().getId() == type.getId()) {
return executeRandom(r);
}
}
return false;