Skip to content

Commit

Permalink
Issue #785: Support negative values for resetInHours (disabled reset)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf committed Jul 2, 2016
1 parent d6e558f commit 1307c49
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ItemStack getDisplayItem(ChallengeCompletion completion, boolean withCurr
} else if (cooldown >= ChallengeLogic.MS_HOUR) {
final int hours = (int) (cooldown / ChallengeLogic.MS_HOUR);
lores.add(tr("\u00a74Requirements will reset in {0} hours.", hours));
} else {
} else if (cooldown >= 0) {
final int minutes = Math.round(cooldown / ChallengeLogic.MS_MIN);
lores.add(tr("\u00a74Requirements will reset in {0} minutes.", minutes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ public long getCooldownUntil() {

@Override
public boolean isOnCooldown() {
return cooldownUntil > System.currentTimeMillis();
return cooldownUntil < 0 || cooldownUntil > System.currentTimeMillis();
}

@Override
public long getCooldownInMillis() {
if (cooldownUntil < 0) {
return -1;
}
long now = System.currentTimeMillis();
return cooldownUntil > now ? cooldownUntil - now : 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,13 @@ public void completeChallenge(PlayerInfo playerInfo, String challengeName) {
if (challenges.containsKey(challengeName)) {
ChallengeCompletion completion = challenges.get(challengeName);
if (!completion.isOnCooldown()) {
long now = System.currentTimeMillis();
completion.setCooldownUntil(now + uSkyBlock.getInstance().getChallengeLogic().getResetInMillis(challengeName));
long resetInMillis = uSkyBlock.getInstance().getChallengeLogic().getResetInMillis(challengeName);
if (resetInMillis >= 0) {
long now = System.currentTimeMillis();
completion.setCooldownUntil(now + resetInMillis);
} else {
completion.setCooldownUntil(resetInMillis);
}
}
completion.addTimesCompleted();
}
Expand Down

0 comments on commit 1307c49

Please sign in to comment.