Skip to content

Commit

Permalink
Fixed faulty return of TickTimer and TimerUtils.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Aug 28, 2024
1 parent b21169f commit 01e33be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
22 changes: 9 additions & 13 deletions src/main/java/dev/heliosclient/util/TickTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,31 @@ public void increment(){

// Checks if ticks have passed since the last reset
public boolean every(int ticks) {
if (getElapsedTicks() >= ticks) {
boolean didTimerLapse = getElapsedTicks() >= ticks;
if (didTimerLapse) {
restartTimer();
}
return getElapsedTicks() >= ticks;
return didTimerLapse;
}


public boolean incrementAndEvery(int ticks) {
increment();
if (getElapsedTicks() >= ticks) {
restartTimer();
}
return getElapsedTicks() >= ticks;
return every(ticks);
}

public boolean incrementAndEvery(int ticks, Runnable task) {
increment();
if (getElapsedTicks() >= ticks) {
task.run();
restartTimer();
}
return getElapsedTicks() >= ticks;
return every(ticks,task);
}

public boolean every(int ticks, Runnable task) {
if (getElapsedTicks() >= ticks) {
boolean didTimerLapse = getElapsedTicks() >= ticks;

if (didTimerLapse) {
task.run();
restartTimer();
}
return getElapsedTicks() >= ticks;
return didTimerLapse;
}
}
11 changes: 7 additions & 4 deletions src/main/java/dev/heliosclient/util/TimerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,19 @@ public void scheduleSingleReset(long ms) {

// Checks if ms milliseconds have passed since the last reset
public boolean every(long ms) {
if (getElapsedTime() >= ms / 1000.0)
boolean didTimerLapse = getElapsedTime() >= ms / 1000.0;
if (didTimerLapse)
resetTimer();
return getElapsedTime() >= ms / 1000.0;

return didTimerLapse;
}

public boolean every(long ms, Runnable task) {
if (getElapsedTimeMS() >= ms) {
boolean didTimerLapse = getElapsedTime() >= ms / 1000.0;
if (didTimerLapse) {
task.run();
resetTimer();
}
return getElapsedTimeMS() >= ms;
return didTimerLapse;
}
}

0 comments on commit 01e33be

Please sign in to comment.