Retrieve scoreboard data only when possible

This commit is contained in:
Thanos Paravantis 2016-06-28 11:46:38 +03:00
parent a714144159
commit 7218dc710f
2 changed files with 72 additions and 6 deletions

View File

@ -1509,13 +1509,12 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private void displayAlivePlayers() private void displayAlivePlayers()
{ {
int data = _challenge.getPlayersIn(false).size();
Scoreboard.WriteBlank(); Scoreboard.WriteBlank();
Scoreboard.Write(C.cGreen + C.Bold + "Alive"); Scoreboard.Write(C.cGreen + C.Bold + "Alive");
if (_settings.isChallengeStarted()) if (_settings.isChallengeStarted())
{ {
int data = _challenge.getPlayersIn(false).size();
Scoreboard.Write("" + data); Scoreboard.Write("" + data);
} }
else else
@ -1526,13 +1525,12 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private void displayCompletedPlayers() private void displayCompletedPlayers()
{ {
int data = _challenge.getData().getCompletedPlayers().size();
Scoreboard.WriteBlank(); Scoreboard.WriteBlank();
Scoreboard.Write(C.cGold + C.Bold + "Completed"); Scoreboard.Write(C.cGold + C.Bold + "Completed");
if (_settings.isChallengeStarted()) if (_settings.isChallengeStarted())
{ {
int data = _challenge.getData().getCompletedPlayers().size();
Scoreboard.Write("" + data); Scoreboard.Write("" + data);
} }
else else
@ -1543,13 +1541,12 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private void displayDeadPlayers() private void displayDeadPlayers()
{ {
int data = _challenge.getData().getLostPlayers().size();
Scoreboard.WriteBlank(); Scoreboard.WriteBlank();
Scoreboard.Write(C.cGray + C.Bold + "Dead"); Scoreboard.Write(C.cGray + C.Bold + "Dead");
if (_settings.isChallengeStarted()) if (_settings.isChallengeStarted())
{ {
int data = _challenge.getData().getLostPlayers().size();
Scoreboard.Write("" + data); Scoreboard.Write("" + data);
} }
else else

View File

@ -0,0 +1,69 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.common.util.UtilMath;
public class ChallengeList
{
private List<Challenge> _challenges = new ArrayList<>();
private List<Challenge> _played = new ArrayList<>();
private Challenge _restricted;
public Challenge select()
{
if (_restricted == null)
{
if (_played.size() == _challenges.size())
{
System.out.println("All challenges played, resetting and selecting new one.");
_played.clear();
return UtilMath.randomElement(_challenges);
}
else
{
Challenge challenge = UtilMath.randomElement(_challenges);
System.out.println("Attempt: " + challenge.getName());
while (_played.contains(challenge))
{
System.out.println("Attempt (Loop): " + challenge.getName());
challenge = UtilMath.randomElement(_challenges);
}
System.out.println("Selected: " + challenge.getName());
return challenge;
}
}
else
{
System.out.println("Restricted: " + _restricted.getName());
return _restricted;
}
}
public void add(Challenge... challenges)
{
for (Challenge challenge : challenges)
{
_challenges.add(challenge);
}
}
public void restrict(Challenge challenge)
{
_restricted = challenge;
}
public void unrestrict()
{
_restricted = null;
}
public int size()
{
return _challenges.size();
}
}