Refactor onChallengeUpdate method.

This commit is contained in:
Thanos paravantis 2016-03-19 16:14:56 +02:00
parent 4c8292e7c9
commit 115508cf72

View File

@ -144,7 +144,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private Challenge _challenge;
private ArrayList<Block> _lastChallengeBlocks;
private long _challengeTime;
private long _delay;
private String _restrictCommand = "restrict";
private String _skipCommand = "skip";
@ -322,23 +322,21 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (!IsLive())
return;
if (_challenge == null)
if (_challenge == null) // Triggered after the first challenge ends.
{
if (!UtilTime.elapsed(_challengeTime, 1500))
if (!UtilTime.elapsed(_delay, 1500))
{
return;
resetDeadPlayers();
}
_challenge = selectChallenge();
resetDeadPlayers();
keepSearchingWhenNull();
resetLastChallengeMap();
_deathEffect.removeSpawnedEntities();
setupChallengeSpawnLocations();
_challenge.createMap();
_challenge.markSpawnLocations(); // Debug
@ -351,60 +349,72 @@ public class BawkBawkBattles extends TeamGame implements IThrown
challengeWithRooms.assignRooms();
}
_challengeTime = System.currentTimeMillis();
_delay = System.currentTimeMillis();
_settings.setWaiting(true);
}
else if (_settings.isWaiting())
else if (_settings.isWaiting()) // Triggered when a challenge should start.
{
if (!UtilTime.elapsed(_challengeTime, 1000))
if (!UtilTime.elapsed(_delay, 1000))
{
return;
if (!_settings.areMessagesBeingSent() && !_settings.areMessagesSent())
{
addEffectsToPlayers();
startChallengeDescriptionThread();
}
else if (_settings.areMessagesSent())
{
removeEffectsFromPlayers();
_settings.setWaiting(false);
_settings.setChallengeStarted(true);
_challenge.start();
Bukkit.getServer().getPluginManager().callEvent(new ChallengeStartEvent(_challenge));
Manager.getPluginManager().registerEvents(_challenge, Manager.getPlugin());
_settings.markMessagesAsSent(false);
}
displayDescriptionAndStartChallenge();
}
else
else // Triggered when a challenge should end.
{
if (_challenge.canFinish())
checkChallengeEnd();
}
}
private void displayDescriptionAndStartChallenge()
{
if (_settings.areMessagesSent())
{
removeEffectsFromPlayers();
_settings.setWaiting(false);
_settings.setChallengeStarted(true);
_challenge.start();
Bukkit.getServer().getPluginManager().callEvent(new ChallengeStartEvent(_challenge));
Manager.getPluginManager().registerEvents(_challenge, Manager.getPlugin());
_settings.markMessagesAsSent(false);
}
else if (!_settings.areMessagesBeingSent())
{
addEffectsToPlayers();
startChallengeDescriptionThread();
}
}
private void checkChallengeEnd()
{
if (_challenge.canFinish())
{
if (hasCrumbleSetting())
{
if (hasCrumbleSetting())
if (canStartCrumbling())
{
if (canStartCrumbling())
{
_settings.setCrumbling(true);
announceCrumbling();
}
else if (canEndChallengeFromCrumble())
{
_settings.setCrumbling(false);
endCurrentChallenge();
}
_settings.setCrumbling(true);
announceCrumbling();
}
else
else if (canEndChallengeFromCrumble())
{
_settings.setCrumbling(false);
endCurrentChallenge();
}
}
else
{
updateChallengeTimer();
endCurrentChallenge();
}
}
else
{
updateChallengeTimer();
}
}
private void announceCrumbling()
@ -418,39 +428,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
private ArrayList<Location> getBestSpawnLocations()
{
ArrayList<Location> available = setupChallengeSpawnLocations();
ArrayList<Location> selected = new ArrayList<Location>();
for (int i = 0; i < available.size(); i++)
{
Location furthest = null;
double furthestDist = 0;
for (Location spawn : available)
{
if (selected.contains(spawn))
continue;
double dist = 0;
for (Location loc : selected)
dist += loc.distance(spawn);
if (furthest == null || furthestDist < dist)
{
furthest = spawn;
furthestDist = dist;
}
}
selected.add(furthest);
}
return selected;
}
private void resetDeadPlayers()
{
for (Player player : GetPlayers(false))
@ -482,7 +459,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private ArrayList<Location> setupChallengeSpawnLocations()
{
ArrayList<Location> spawns = _challenge.createSpawns();
_challenge.getData().setSpawns(spawns);
_playersTeam.SetSpawns(spawns);
SpectatorSpawn = UtilWorld.averageLocation(spawns).add(0, 7, 0);
@ -519,18 +496,18 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private void teleportPlayersToSpawnpoints()
{
// int i = 0;
//
// for (Player player : getChallengers())
// {
// player.teleport(spawnpoints.get(i++));
//
// if (i >= spawnpoints.size())
// {
// i = 0;
// }
// }
// int i = 0;
//
// for (Player player : getChallengers())
// {
// player.teleport(spawnpoints.get(i++));
//
// if (i >= spawnpoints.size())
// {
// i = 0;
// }
// }
for (Player player : getChallengers())
{
_playersTeam.SpawnTeleport(player);
@ -614,7 +591,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
public void endCurrentChallenge()
{
_challengeTime = System.currentTimeMillis();
_delay = System.currentTimeMillis();
resetPlayersOnChallengeEnding();
@ -1386,7 +1363,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (event.GetState() != GameState.Live)
return;
_challengeTime = System.currentTimeMillis();
_delay = System.currentTimeMillis();
_chickenAttack = new ChickenAttack(this, _chickenAttackCenter);
}
@ -1545,9 +1522,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return _challenge;
}
public long getChallengeTime()
public long getCurrentDelay()
{
return _challengeTime;
return _delay;
}
@Override