Fix auto ready behavior; resolves #435

This commit is contained in:
Daniel Saukel 2018-10-06 17:30:14 +02:00
parent bbf5de85ec
commit 62f3ff065b
4 changed files with 58 additions and 46 deletions

View File

@ -692,9 +692,9 @@ public class DGamePlayer extends DInstancePlayer {
ready(GameTypeDefault.DEFAULT);
}
public void ready(GameType gameType) {
public boolean ready(GameType gameType) {
if (getDGroup() == null) {
return;
return false;
}
Game game = Game.getByGameWorld(dGroup.getGameWorld());
@ -708,21 +708,24 @@ public class DGamePlayer extends DInstancePlayer {
if (!checkRequirements(game)) {
MessageUtil.sendMessage(player, DMessage.ERROR_REQUIREMENTS.getMessage());
return;
return false;
}
ready = true;
boolean start = true;
for (DGroup gameGroup : game.getDGroups()) {
if (!gameGroup.isPlaying()) {
gameGroup.startGame(game);
if (!gameGroup.startGame(game)) {
start = false;
}
} else {
respawn();
}
}
game.setStarted(true);
return start;
}
public void respawn() {

View File

@ -758,9 +758,9 @@ public class DGroup {
plugin.getGlobalProtectionCache().updateGroupSigns(this);
}
public void startGame(Game game) {
public boolean startGame(Game game) {
if (game == null) {
return;
return false;
}
game.fetchRules();
GameRuleProvider rules = game.getRules();
@ -788,7 +788,7 @@ public class DGroup {
}
if (!ready) {
return;
return false;
}
}
@ -796,7 +796,7 @@ public class DGroup {
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
return false;
}
playing = true;
@ -872,6 +872,7 @@ public class DGroup {
nextFloor = null;
initialLives = rules.getInitialGroupLives();
lives = initialLives;
return true;
}
public void winGame() {

View File

@ -34,7 +34,6 @@ import de.erethon.dungeonsxl.world.DGameWorld;
import org.bukkit.ChatColor;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
@ -46,6 +45,7 @@ public class ReadySign extends DSign {
private GameType gameType;
private double autoStart = -1;
private boolean triggered = false;
private ProgressBar bar;
public ReadySign(DungeonsXL plugin, Sign sign, String[] lines, DGameWorld gameWorld) {
super(plugin, sign, lines, gameWorld);
@ -122,15 +122,14 @@ public class ReadySign extends DSign {
if (!triggered && autoStart >= 0) {
triggered = true;
new BukkitRunnable() {
@Override
public void run() {
onTrigger();
}
}.runTaskLater(plugin, (long) (autoStart * 20));
if (!DGroup.getByPlayer(player).isPlaying()) {
new ProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)).send(plugin);
bar = new ProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart)) {
@Override
public void onFinish() {
onTrigger();
}
};
bar.send(plugin);
}
}
@ -143,17 +142,17 @@ public class ReadySign extends DSign {
return;
}
if (bar != null) {
bar.cancel();
}
for (Player player : getGame().getPlayers()) {
ready(DGamePlayer.getByPlayer(player));
}
}
private void ready(DGamePlayer dPlayer) {
if (dPlayer == null) {
return;
}
if (dPlayer.isReady()) {
if (dPlayer == null || dPlayer.isReady()) {
return;
}
@ -162,7 +161,10 @@ public class ReadySign extends DSign {
if (getGameWorld().getConfig() != null) {
forced = getGameWorld().getConfig().getForcedGameType();
}
dPlayer.ready(forced == null ? gameType : forced);
boolean ready = dPlayer.ready(forced == null ? gameType : forced);
if (ready && bar != null) {
bar.cancel();
}
}
if (dPlayer.isReady()) {

View File

@ -17,7 +17,6 @@
package de.erethon.dungeonsxl.util;
import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.javaplugin.DREPlugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -83,12 +82,19 @@ public class ProgressBar extends BukkitRunnable {
}
if (secondsLeft == 0) {
onFinish();
cancel();
} else {
secondsLeft--;
}
}
/**
* Method to override to set actions when no seconds are left.
*/
public void onFinish() {
}
/**
* Sends the progress bar to a player
*