Prevent game crash if started with one player
This commit is contained in:
parent
efce89a7e7
commit
839d9263fd
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user