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

View File

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

View File

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

View File

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