diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattles.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattles.java index e8ce86b47..8ec20e5de 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattles.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/BawkBawkBattles.java @@ -87,6 +87,7 @@ import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeColorCha import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeDeadlyTnt; import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeDiamondHunt; import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeEggSmash; +import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeEmpty; import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeFallingBlocks; import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeFastFood; import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeKangarooJump; @@ -381,27 +382,33 @@ public class BawkBawkBattles extends TeamGame implements IThrown private Challenge selectChallenge() { - int limit = _list.size(); - int attemps = 0; - - Challenge instance = _list.random(); - - while (!isSuitable(instance)) + if (GetPlayers(false).size() > MIN_PLAYERS_BLOCK_ATTEMPT) { - if (attemps < limit) - { - instance = _list.random(); - attemps++; - } - else - { - _list.resetPlayed(); - attemps = 0; - } - } + int limit = _list.size(); + int attemps = 0; - System.out.println("Found matching challenge: " + instance.getName()); - return instance; + Challenge instance = _list.random(); + + while (!isSuitable(instance)) + { + if (attemps < limit) + { + instance = _list.random(); + attemps++; + } + else + { + _list.resetPlayed(); + attemps = 0; + } + } + + return instance; + } + else + { + return new ChallengeEmpty(this); + } } private boolean isSuitable(Challenge instance) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEmpty.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEmpty.java new file mode 100644 index 000000000..c3695fe6c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeEmpty.java @@ -0,0 +1,40 @@ +package nautilus.game.arcade.game.games.mineware.challenge.type; + +import java.util.ArrayList; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +import nautilus.game.arcade.game.games.mineware.BawkBawkBattles; +import nautilus.game.arcade.game.games.mineware.challenge.Challenge; +import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType; + +/** + * This challenge is used to prevent the game from crashing if it's forced to start with only one player. + */ +public class ChallengeEmpty extends Challenge +{ + public ChallengeEmpty(BawkBawkBattles host) + { + super(host, ChallengeType.FirstComplete, "Empty", new String[] { "Not enough players" }); + + Settings.setUseMapHeight(); + } + + @Override + public ArrayList createSpawns() + { + ArrayList spawns = new ArrayList<>(); + spawns.add(getCenter().add(0, 1, 0)); + return spawns; + } + + @Override + public void createMap() + { + Block center = getCenter().getBlock(); + center.setType(Material.BARRIER); + addBlock(center); + } +}