Skip to content

Commit

Permalink
Added a way to synchronize the timer with a clock, to avoid "long" ep…
Browse files Browse the repository at this point in the history
…isodes due to lag.
  • Loading branch information
AmauryCarrade committed Jul 15, 2014
1 parent 2ddab28 commit 299d2ae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- Synchroniser l'horloge des épisodes avec une vraie horloge (évite le décalage à cause du lag).
- [OK] Synchroniser l'horloge des épisodes avec une vraie horloge (évite le décalage à cause du lag).
- [OK] Prendre en compte les cœurs d'absorption en cas de pommes d'or.
- [OK] Optimiser la vérification de position des joueurs (ou se reposer uniquement sur WorldBorder, via son API).
- Mettre à jour le code pour considérer les UUID (si besoin est).
Expand Down
34 changes: 27 additions & 7 deletions src/main/java/me/azenet/UHPlugin/UHGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class UHGameManager {
private Integer minutesLeft = 0;
private Integer secondsLeft = 0;

private Long episodeStartTime = 0L;


public UHGameManager(UHPlugin plugin) {
this.p = plugin;
Expand Down Expand Up @@ -271,6 +273,7 @@ public void run() {
private void finalizeStart() {
Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "--- GO ---");
this.gameRunning = true;
this.episodeStartTime = System.currentTimeMillis();
}

public Integer getTeamsTeleported() {
Expand All @@ -290,13 +293,28 @@ public void setSlowStartTPFinished(Boolean finished) {


public void updateTimer() {
secondsLeft--;
if (secondsLeft == -1) {
minutesLeft--;
secondsLeft = 59;
if(p.getConfig().getBoolean("episodes.syncTimer")) {
long timeSinceStart = System.currentTimeMillis() - this.episodeStartTime;
long diffSeconds = timeSinceStart / 1000 % 60;
long diffMinutes = timeSinceStart / (60 * 1000) % 60;

if(diffMinutes >= this.getEpisodeLength()) {
shiftEpisode();
}
else {
minutesLeft = (int) (this.getEpisodeLength() - diffMinutes) - 1;
secondsLeft = (int) (60 - diffSeconds) - 1;
}
}
if (minutesLeft == -1) {
shiftEpisode();
else {
secondsLeft--;
if (secondsLeft == -1) {
minutesLeft--;
secondsLeft = 59;
}
if (minutesLeft == -1) {
shiftEpisode();
}
}
}

Expand All @@ -323,6 +341,8 @@ public void shiftEpisode(String shifter) {
this.episode++;
this.minutesLeft = getEpisodeLength();
this.secondsLeft = 0;

this.episodeStartTime = System.currentTimeMillis();
}

/**
Expand Down Expand Up @@ -394,7 +414,7 @@ public UHScoreboardManager getScoreboardManager() {
}

public Integer getEpisodeLength() {
return p.getConfig().getInt("episodeLength");
return p.getConfig().getInt("episodes.length");
}

public Integer getAlivePlayersCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ private void setupBorders() {

/** Overworld border **/

World overworld = getOverworld();
p.getLogger().info(overworld.getName());

World overworld = getOverworld();
BorderData borderOverworld = wb.getWorldBorder(overworld.getName());

if(borderOverworld == null) { // The border needs to be created from scratch
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
episodeLength: 20 # minutes
episodes:
length: 20 # minutes
syncTimer: true # if true, the timer will be synchronized with a clock to avoid having long episodes because of lag

map:
size: 2000
Expand Down

0 comments on commit 299d2ae

Please sign in to comment.