Prevent game crash if started with one player

This commit is contained in:
Thanos Paravantis 2016-07-13 18:03:38 +03:00
parent efce89a7e7
commit 839d9263fd
2 changed files with 66 additions and 19 deletions

View File

@ -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)

View File

@ -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<Location> createSpawns()
{
ArrayList<Location> 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);
}
}