Skip to content

Commit

Permalink
More fixes for cooldown events
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCodez committed Mar 20, 2024
1 parent d1dc8b3 commit 0a74e33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ public void vote(VotingPluginUser user, VoteSite site) {

public synchronized void check(VotingPluginUser user) {
boolean coolDownCheck = user.getCoolDownCheck();
if (user.canVoteAll() && coolDownCheck) {
user.setCoolDownCheck(false);
PlayerVoteCoolDownEndEvent event = new PlayerVoteCoolDownEndEvent(user);
plugin.getServer().getPluginManager().callEvent(event);
allSiteTasks.remove(user.getJavaUUID());
} else if (!coolDownCheck) {
schedule(user, false);
if (coolDownCheck) {
if (user.canVoteAll()) {
user.setCoolDownCheck(false);
PlayerVoteCoolDownEndEvent event = new PlayerVoteCoolDownEndEvent(user);
plugin.getServer().getPluginManager().callEvent(event);
allSiteTasks.remove(user.getJavaUUID());
} else {
schedulePerSite(user, false);
}
}
}

Expand Down Expand Up @@ -133,8 +135,10 @@ public void run() {
checkPerSite(uuid);
}
}
}, time + 2, TimeUnit.SECONDS);
}, time / +2, TimeUnit.SECONDS);
perSiteTasks.put(uuid, scheduledFuture);
} else {
plugin.extraDebug(user.getUUID() + "/" + user.getPlayerName() + " not scheduling cooldown check");
}
}
}
Expand All @@ -159,6 +163,8 @@ public void run() {
}
}, time + 2, TimeUnit.SECONDS);
allSiteTasks.put(uuid, scheduledFuture);
} else {
plugin.extraDebug(user.getUUID() + "/" + user.getPlayerName() + " not scheduling cooldown check");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -282,7 +281,8 @@ public boolean canVoteSite(VoteSite voteSite) {
.withSecond(0);
LocalDateTime resetTimeTomorrow = resetTime.plusHours(24);

if (ChronoUnit.HOURS.between(lastVote, resetTime) > 24) {
// if (ChronoUnit.HOURS.between(lastVote, resetTime) > 24) {
if (lastVote.isBefore(resetTime)) {
if (now.isAfter(resetTime)) {
return true;
}
Expand Down Expand Up @@ -1316,10 +1316,9 @@ public long voteNextDurationTime(VoteSite voteSite, long time) {
}
}
} else {
LocalDateTime resetTime = plugin.getTimeChecker().getTime().withHour(voteSite.getVoteDelayDailyHour())
.withMinute(0).withSecond(0);
LocalDateTime resetTime = lastVote.withHour(voteSite.getVoteDelayDailyHour()).withMinute(0).withSecond(0);
LocalDateTime resetTimeTomorrow = resetTime.plusHours(24);
if (lastVote.isBefore(resetTime)) {
if (lastVote.isBefore(resetTime) && now.isBefore(resetTime)) {
if (now.isBefore(resetTime)) {
Duration dur = Duration.between(now, resetTime);
return dur.getSeconds();
Expand Down

0 comments on commit 0a74e33

Please sign in to comment.