Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public void onplayerVote(PlayerVoteEvent event) {
}
}

if (voteSite.isWaitUntilVoteDelay() && !user.canVoteSite(voteSite)) {
boolean queuedProxyVoteAlreadyRecorded = ProxyVoteDelayCheck.isQueuedVoteAlreadyRecorded(event.isBungee(),
event.getTime(), user.getTime(voteSite));
if (voteSite.isWaitUntilVoteDelay() && !queuedProxyVoteAlreadyRecorded && !user.canVoteSite(voteSite)) {
if (!event.isRealVote()) {
plugin.getLogger().info(user.getPlayerName() + " did a not real vote, bypassing WaitUntilVoteDelay");
} else {
Expand All @@ -157,6 +159,10 @@ public void onplayerVote(PlayerVoteEvent event) {
.info(user.getPlayerName() + " has bypass permission for WaitUntilVoteDelay, bypassing");
}
}
if (queuedProxyVoteAlreadyRecorded) {
plugin.debug("Allowing queued proxy vote for " + user.getPlayerName() + " on " + voteSite.getKey()
+ "; proxy vote time already matches LastVotes: " + event.getTime());
}

UUID voteUUID = UUID.randomUUID();
if (event.isBungee() && event.getBungeeTextTotals() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bencodez.votingplugin.listeners;

/**
* Handles the WaitUntilVoteDelay exception for votes queued by a proxy.
*/
public final class ProxyVoteDelayCheck {

private ProxyVoteDelayCheck() {
}

/**
* A proxy stores the real vote timestamp before its queued message reaches the
* backend. The backend must accept that one delivery when the stored timestamp
* is the same timestamp carried by the message.
*
* @param proxyVote true when the vote was forwarded by VotingPlugin's proxy
* @param messageVoteTime real vote time included in the proxy message
* @param storedVoteTime current backend last-vote time for the site
* @return true when the delay check should allow the queued delivery
*/
public static boolean isQueuedVoteAlreadyRecorded(boolean proxyVote, long messageVoteTime, long storedVoteTime) {
return proxyVote && messageVoteTime > 0L && messageVoteTime == storedVoteTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bencodez.votingplugin.tests;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import com.bencodez.votingplugin.listeners.ProxyVoteDelayCheck;

class ProxyVoteDelayCheckTest {

@Test
void acceptsQueuedProxyVoteWhenTheProxyTimestampIsAlreadyStored() {
assertTrue(ProxyVoteDelayCheck.isQueuedVoteAlreadyRecorded(true, 12345L, 12345L));
}

@Test
void doesNotBypassTheDelayForDirectOrStaleProxyVotes() {
assertFalse(ProxyVoteDelayCheck.isQueuedVoteAlreadyRecorded(false, 12345L, 12345L));
assertFalse(ProxyVoteDelayCheck.isQueuedVoteAlreadyRecorded(true, 12344L, 12345L));
assertFalse(ProxyVoteDelayCheck.isQueuedVoteAlreadyRecorded(true, 0L, 0L));
}
}
Loading