Skip to content

Commit

Permalink
Fixed issue with used percentage for vote streaks not working
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCodez committed Feb 11, 2024
1 parent f63ab7b commit 159eb54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 10 additions & 0 deletions VotingPlugin/src/com/bencodez/votingplugin/VotingPluginMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ public VoteSite getVoteSite(String site, boolean checkEnabled) {

}

public ArrayList<VoteSite> getVoteSitesEnabled() {
ArrayList<VoteSite> sites = new ArrayList<VoteSite>();
for (VoteSite site : getVoteSites()) {
if (site.isEnabled()) {
sites.add(site);
}
}
return sites;
}

public String getVoteSiteName(boolean checkEnabled, String... urls) {
ArrayList<String> sites = getConfigVoteSites().getVoteSitesNames(checkEnabled);
for (String url : urls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ public boolean checkVoteStreak(VotingPluginUser user, String type, boolean force
if (streak.contains("-")) {
// multiple
multiple = true;

}
plugin.debug("Streak: " + streak + " multiple: " + multiple);
if (StringParser.getInstance().isInt(s)) {
int streakRequired = Integer.parseInt(s);
if (streakRequired != 0) {
Expand All @@ -287,8 +289,7 @@ public boolean checkVoteStreak(VotingPluginUser user, String type, boolean force
}
} else {
if (curStreak != 0 && curStreak % streakRequired == 0) {
giveVoteStreakReward(user, user.isOnline(), type, streakRequired + "-", curStreak,
forceBungee);
giveVoteStreakReward(user, user.isOnline(), type, streak, curStreak, forceBungee);
gotReward = true;
plugin.debug(
user.getPlayerName() + " got VoteStreak " + streakRequired + "* for " + type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public void checkDayVoteStreak(boolean forceBungee) {
if (!voteStreakUpdatedToday(LocalDateTime.now())) {
if (!plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage() || hasPercentageTotal(
TopVoter.Daily, plugin.getSpecialRewardsConfig().getVoteStreakRequirementDay(), null)) {
plugin.debug("Adding day vote streak to " + getUUID() + " "
plugin.extraDebug("Adding day vote streak to " + getUUID() + " "
+ plugin.getSpecialRewardsConfig().isVoteStreakRequirementUsePercentage() + " "
+ hasPercentageTotal(TopVoter.Daily,
plugin.getSpecialRewardsConfig().getVoteStreakRequirementDay(), null));
Expand Down Expand Up @@ -687,11 +687,12 @@ public boolean hasPercentageTotal(TopVoter top, double percentage, LocalDateTime
int total = getTotal(top);
switch (top) {
case Daily:
return total / plugin.getVoteSites().size() * 100 > percentage;
return (double) total / (double) plugin.getVoteSitesEnabled().size() * 100 > percentage;
case Monthly:
return total / (plugin.getVoteSites().size() * time.getMonth().length(false)) * 100 > percentage;
return (double) total / ((double) plugin.getVoteSitesEnabled().size() * time.getMonth().length(false))
* 100 > percentage;
case Weekly:
return total / (plugin.getVoteSites().size() * 7) * 100 > percentage;
return (double) total / ((double) plugin.getVoteSitesEnabled().size() * 7) * 100 > percentage;
default:
return false;
}
Expand Down

0 comments on commit 159eb54

Please sign in to comment.