Refactor onChallengeUpdate method.
This commit is contained in:
parent
4c8292e7c9
commit
115508cf72
@ -144,7 +144,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
|
|
||||||
private Challenge _challenge;
|
private Challenge _challenge;
|
||||||
private ArrayList<Block> _lastChallengeBlocks;
|
private ArrayList<Block> _lastChallengeBlocks;
|
||||||
private long _challengeTime;
|
private long _delay;
|
||||||
|
|
||||||
private String _restrictCommand = "restrict";
|
private String _restrictCommand = "restrict";
|
||||||
private String _skipCommand = "skip";
|
private String _skipCommand = "skip";
|
||||||
@ -322,23 +322,21 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
if (!IsLive())
|
if (!IsLive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_challenge == null)
|
if (_challenge == null) // Triggered after the first challenge ends.
|
||||||
{
|
{
|
||||||
if (!UtilTime.elapsed(_challengeTime, 1500))
|
if (!UtilTime.elapsed(_delay, 1500))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
resetDeadPlayers();
|
|
||||||
|
|
||||||
_challenge = selectChallenge();
|
_challenge = selectChallenge();
|
||||||
|
|
||||||
|
resetDeadPlayers();
|
||||||
keepSearchingWhenNull();
|
keepSearchingWhenNull();
|
||||||
|
|
||||||
resetLastChallengeMap();
|
resetLastChallengeMap();
|
||||||
|
|
||||||
_deathEffect.removeSpawnedEntities();
|
_deathEffect.removeSpawnedEntities();
|
||||||
|
|
||||||
setupChallengeSpawnLocations();
|
setupChallengeSpawnLocations();
|
||||||
|
|
||||||
_challenge.createMap();
|
_challenge.createMap();
|
||||||
_challenge.markSpawnLocations(); // Debug
|
_challenge.markSpawnLocations(); // Debug
|
||||||
|
|
||||||
@ -351,60 +349,72 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
challengeWithRooms.assignRooms();
|
challengeWithRooms.assignRooms();
|
||||||
}
|
}
|
||||||
|
|
||||||
_challengeTime = System.currentTimeMillis();
|
_delay = System.currentTimeMillis();
|
||||||
_settings.setWaiting(true);
|
_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;
|
return;
|
||||||
|
|
||||||
if (!_settings.areMessagesBeingSent() && !_settings.areMessagesSent())
|
|
||||||
{
|
|
||||||
addEffectsToPlayers();
|
|
||||||
startChallengeDescriptionThread();
|
|
||||||
}
|
}
|
||||||
else if (_settings.areMessagesSent())
|
|
||||||
{
|
|
||||||
removeEffectsFromPlayers();
|
|
||||||
|
|
||||||
_settings.setWaiting(false);
|
displayDescriptionAndStartChallenge();
|
||||||
_settings.setChallengeStarted(true);
|
|
||||||
|
|
||||||
_challenge.start();
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new ChallengeStartEvent(_challenge));
|
|
||||||
|
|
||||||
Manager.getPluginManager().registerEvents(_challenge, Manager.getPlugin());
|
|
||||||
_settings.markMessagesAsSent(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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();
|
||||||
_settings.setCrumbling(true);
|
|
||||||
announceCrumbling();
|
|
||||||
}
|
|
||||||
else if (canEndChallengeFromCrumble())
|
|
||||||
{
|
|
||||||
_settings.setCrumbling(false);
|
|
||||||
endCurrentChallenge();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else if (canEndChallengeFromCrumble())
|
||||||
{
|
{
|
||||||
|
_settings.setCrumbling(false);
|
||||||
endCurrentChallenge();
|
endCurrentChallenge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
updateChallengeTimer();
|
endCurrentChallenge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateChallengeTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void announceCrumbling()
|
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()
|
private void resetDeadPlayers()
|
||||||
{
|
{
|
||||||
for (Player player : GetPlayers(false))
|
for (Player player : GetPlayers(false))
|
||||||
@ -519,17 +496,17 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
|
|
||||||
private void teleportPlayersToSpawnpoints()
|
private void teleportPlayersToSpawnpoints()
|
||||||
{
|
{
|
||||||
// int i = 0;
|
// int i = 0;
|
||||||
//
|
//
|
||||||
// for (Player player : getChallengers())
|
// for (Player player : getChallengers())
|
||||||
// {
|
// {
|
||||||
// player.teleport(spawnpoints.get(i++));
|
// player.teleport(spawnpoints.get(i++));
|
||||||
//
|
//
|
||||||
// if (i >= spawnpoints.size())
|
// if (i >= spawnpoints.size())
|
||||||
// {
|
// {
|
||||||
// i = 0;
|
// i = 0;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
for (Player player : getChallengers())
|
for (Player player : getChallengers())
|
||||||
{
|
{
|
||||||
@ -614,7 +591,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
|
|
||||||
public void endCurrentChallenge()
|
public void endCurrentChallenge()
|
||||||
{
|
{
|
||||||
_challengeTime = System.currentTimeMillis();
|
_delay = System.currentTimeMillis();
|
||||||
|
|
||||||
resetPlayersOnChallengeEnding();
|
resetPlayersOnChallengeEnding();
|
||||||
|
|
||||||
@ -1386,7 +1363,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
if (event.GetState() != GameState.Live)
|
if (event.GetState() != GameState.Live)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_challengeTime = System.currentTimeMillis();
|
_delay = System.currentTimeMillis();
|
||||||
|
|
||||||
_chickenAttack = new ChickenAttack(this, _chickenAttackCenter);
|
_chickenAttack = new ChickenAttack(this, _chickenAttackCenter);
|
||||||
}
|
}
|
||||||
@ -1545,9 +1522,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
|
|||||||
return _challenge;
|
return _challenge;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getChallengeTime()
|
public long getCurrentDelay()
|
||||||
{
|
{
|
||||||
return _challengeTime;
|
return _delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user