#40: Don't start games if requirements are not satisfied

This commit is contained in:
Daniel Saukel 2016-06-17 15:44:04 +02:00
parent 83b92e9a13
commit 4fb23b482b
2 changed files with 21 additions and 8 deletions

View File

@ -149,6 +149,7 @@ public class Announcer {
this.maxPlayersPerGroup = maxPlayersPerGroup; this.maxPlayersPerGroup = maxPlayersPerGroup;
} }
/* Getters and setters */
/** /**
* @return the name of the announcer * @return the name of the announcer
*/ */
@ -297,6 +298,20 @@ public class Announcer {
return startTask; return startTask;
} }
/**
* @return whether enough players and groups joined the announced game to start
*/
public boolean areRequirementsFulfilled() {
int i = 0;
for (DGroup group : dGroups) {
if (group != null && group.getPlayers().size() >= minPlayersPerGroup) {
i++;
}
}
return i >= minGroupsPerGame;
}
/* Actions */
/** /**
* Cancels the start task and sets it to null. * Cancels the start task and sets it to null.
*/ */
@ -383,14 +398,7 @@ public class Announcer {
showGUI(player); showGUI(player);
int i = 0; if (areRequirementsFulfilled()) {
for (DGroup group : dGroups) {
if (group != null && group.getPlayers().size() >= minPlayersPerGroup) {
i++;
}
}
if (i >= minGroupsPerGame) {
if (startTask == null) { if (startTask == null) {
startTask = new AnnouncerStartGameTask(this); startTask = new AnnouncerStartGameTask(this);
startTask.runTaskLater(plugin, 20 * 30L); startTask.runTaskLater(plugin, 20 * 30L);

View File

@ -59,6 +59,11 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
if (!announcer.areRequirementsFulfilled()) {
cancel();
return;
}
Game game = null; Game game = null;
for (DGroup dGroup : announcer.getDGroups()) { for (DGroup dGroup : announcer.getDGroups()) {