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 @@ -2362,7 +2362,7 @@ private CompletionStage<Void> offVoteWithCapturedTopVoterIgnoreAsync(boolean cur
beforeRewardEffects.run();
throw new IllegalStateException("Earlier offline-vote rewards require reconciliation for " + uuid);
}
ArrayList<String> offlineVotes = getOfflineVotes();
ArrayList<String> offlineVotes = new ArrayList<>(getOfflineVotes());
if (offlineVotes.isEmpty()) {
confirmed.complete(null);
return confirmed;
Expand All @@ -2373,7 +2373,8 @@ private CompletionStage<Void> offVoteWithCapturedTopVoterIgnoreAsync(boolean cur
CompletionStage<Void> rewards = plugin.getRewardHandler().giveRewardAsync(this,
plugin.getSpecialRewardsConfig().getData(),
plugin.getSpecialRewardsConfig().getAnySiteRewardsPath(),
new RewardOptions().setOnline(false));
new RewardOptions().setOnline(false)
.addPlaceholder("votes", Integer.toString(offlineVotes.size())));
if (rewards == null) throw new IllegalStateException("Missing offline reward completion");
for (String name : offlineVotes) {
VoteSite site = plugin.getVoteSiteManager().resolveVoteSite(name, true);
Expand Down Expand Up @@ -2676,7 +2677,8 @@ public void resetTotals(TopVoter topVoter) {
*/
public void sendVoteEffects(boolean online) {
plugin.getRewardHandler().giveReward(this, plugin.getSpecialRewardsConfig().getData(),
plugin.getSpecialRewardsConfig().getAnySiteRewardsPath(), new RewardOptions().setOnline(online));
plugin.getSpecialRewardsConfig().getAnySiteRewardsPath(),
new RewardOptions().setOnline(online).addPlaceholder("votes", "1"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,106 @@
import com.bencodez.votingplugin.votesites.VoteSiteManager;

class VotingPluginUserOfflineVoteReplayTest {
@Test
void deniedAnySiteCompletesWithoutChangingSiteRewardSelectionOrDefaultOptions() {
AsyncReplayFixture fixture = asyncFixture();
org.mockito.ArgumentCaptor<RewardOptions> options = org.mockito.ArgumentCaptor.forClass(RewardOptions.class);
CompletableFuture<Void> result = fixture.user.offVoteWithCapturedTopVoterIgnoreAsync(false).toCompletableFuture();
verify(fixture.plugin.getRewardHandler()).giveRewardAsync(eq(fixture.user),
org.mockito.ArgumentMatchers.any(YamlConfiguration.class), eq("AnySiteRewards"), options.capture());
assertFalse(options.getValue().isOnline());
assertFalse(options.getValue().isForceOffline());
assertFalse(options.getValue().isIgnoreRequirements());
// AdvancedCore represents a denied/cancelled reward as normal completion.
// No command effect is fabricated here: the caller continues the site chain.
fixture.anySiteRewards.complete(null);
result.join();
verify(fixture.site).giveRewardsAsync(fixture.user, false, false);
assertTrue(fixture.queued.get().isEmpty());
}

@Test
void anySiteOptionsDoNotShareCountBetweenPlayersOrLaterImmediateInvocations() {
AsyncReplayFixture first = asyncFixture();
AsyncReplayFixture second = asyncFixture();
doReturn("00000000-0000-0000-0000-000000000002").when(second.user).getUUID();
first.queued.set(new ArrayList<>(List.of("Site1", "Site1")));
first.user.offVoteWithCapturedTopVoterIgnoreAsync(false);
org.mockito.ArgumentCaptor<RewardOptions> firstOptions = org.mockito.ArgumentCaptor.forClass(RewardOptions.class);
verify(first.plugin.getRewardHandler()).giveRewardAsync(eq(first.user),
org.mockito.ArgumentMatchers.any(YamlConfiguration.class), eq("AnySiteRewards"), firstOptions.capture());
second.user.offVoteWithCapturedTopVoterIgnoreAsync(false);
org.mockito.ArgumentCaptor<RewardOptions> secondOptions = org.mockito.ArgumentCaptor.forClass(RewardOptions.class);
verify(second.plugin.getRewardHandler()).giveRewardAsync(eq(second.user),
org.mockito.ArgumentMatchers.any(YamlConfiguration.class), eq("AnySiteRewards"), secondOptions.capture());
assertEquals("2", firstOptions.getValue().getPlaceholders().get("votes"));
assertEquals("1", secondOptions.getValue().getPlaceholders().get("votes"));
first.anySiteRewards.complete(null);
second.anySiteRewards.complete(null);
first.user.sendVoteEffects(true);
org.mockito.ArgumentCaptor<RewardOptions> immediate = org.mockito.ArgumentCaptor.forClass(RewardOptions.class);
verify(first.plugin.getRewardHandler()).giveReward(eq(first.user),
org.mockito.ArgumentMatchers.any(YamlConfiguration.class), eq("AnySiteRewards"), immediate.capture());
assertEquals("1", immediate.getValue().getPlaceholders().get("votes"));
assertEquals("2", firstOptions.getValue().getPlaceholders().get("votes"));
}

@Test
void capturedCountExpandsOneAnySiteCommandAndWaitsBeforeCommitting149MixedVotes() {
AsyncReplayFixture fixture = asyncFixture();
doReturn(true).when(fixture.user).isOnline();
ArrayList<String> captured = new ArrayList<>();
for (int i = 0; i < 149; i++) captured.add(i % 2 == 0 ? "Site1" : "Site2");
fixture.queued.set(captured);
when(fixture.plugin.getVoteSiteManager().resolveVoteSite("Site2", true)).thenReturn(fixture.site);
RewardHandler handler = fixture.plugin.getRewardHandler();
AtomicReference<RewardOptions> options = new AtomicReference<>();
ArrayList<String> dispatched = new ArrayList<>();
doAnswer(call -> {
options.set(call.getArgument(3));
dispatched.add(com.bencodez.advancedcore.api.messages.PlaceholderUtils.replacePlaceHolder(
"crate give %votes%", options.get().getPlaceholders()));
return fixture.anySiteRewards;
}).when(handler).giveRewardAsync(eq(fixture.user),
org.mockito.ArgumentMatchers.any(YamlConfiguration.class), eq("AnySiteRewards"),
org.mockito.ArgumentMatchers.any(RewardOptions.class));
CompletableFuture<Void> result = fixture.user.offVoteWithCapturedTopVoterIgnoreAsync(false).toCompletableFuture();
assertEquals(List.of("crate give 149"), dispatched);
assertEquals(captured, fixture.pending.get());
assertFalse(result.isDone());
verify(fixture.site, never()).giveRewardsAsync(fixture.user, false, false);
ArrayList<String> withArrival = new ArrayList<>(captured);
withArrival.add("Site1");
fixture.queued.set(withArrival);
assertEquals("149", options.get().getPlaceholders().get("votes"));
fixture.anySiteRewards.complete(null);
result.join();
assertEquals(List.of("Site1"), fixture.queued.get());
assertTrue(fixture.pending.get().isEmpty());
verify(fixture.site, org.mockito.Mockito.times(149)).giveRewardsAsync(fixture.user, false, false);
}

@Test
void immediateAnySiteCountIsOneWithoutChangingOnlineFlag() {
AsyncReplayFixture fixture = asyncFixture();
fixture.user.sendVoteEffects(true);
org.mockito.ArgumentCaptor<RewardOptions> options = org.mockito.ArgumentCaptor.forClass(RewardOptions.class);
verify(fixture.plugin.getRewardHandler()).giveReward(eq(fixture.user),
org.mockito.ArgumentMatchers.any(YamlConfiguration.class), eq("AnySiteRewards"), options.capture());
assertEquals("1", options.getValue().getPlaceholders().get("votes"));
assertTrue(options.getValue().isOnline());
}

@Test
void emptyQueueDoesNotEvaluateAnySite() {
AsyncReplayFixture fixture = asyncFixture();
fixture.queued.set(new ArrayList<>());
fixture.user.offVoteWithCapturedTopVoterIgnoreAsync(false).toCompletableFuture().join();
verify(fixture.plugin.getRewardHandler(), never()).giveRewardAsync(eq(fixture.user),
org.mockito.ArgumentMatchers.any(YamlConfiguration.class), eq("AnySiteRewards"),
org.mockito.ArgumentMatchers.any(RewardOptions.class));
}

@Test
void legacyEntryRetainsQueueAndPendingMarkerWhenRewardDeliveryFails() {
AsyncReplayFixture fixture = asyncFixture();
Expand Down
26 changes: 26 additions & 0 deletions docs/anysite-vote-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# AnySite reward vote count

In Bukkit/Paper/Folia AnySite rewards, `%votes%` is the number of vote entries represented by that invocation:

- An ordinary immediate AnySite invocation receives `1`.
- A nonempty queued offline-vote batch receives the size of its captured queue, across all sites. The player receiving this batch may now be online. Later arrivals belong to a subsequent batch.
- Empty queues do not invoke AnySite. Grouped immediate vote processing retains its existing rule of invoking AnySite only when `voteNumber == 1`; this placeholder does not change that rule.

For example, configure an explicitly supported quantity command in `SpecialRewards.yml`:

```yaml
AnySiteRewards:
Commands:
Console:
- 'crazycrates give virtual Vote %votes% %player%'
```

Confirm the command syntax and quantity limits for your installed recipient plugin. With 149 captured entries, this requests 149 keys through one command. It does not automatically combine other commands or verify that the recipient plugin delivered or persisted the keys.

Move the equivalent uniform grant out of `EverySiteReward` and individual site rewards to avoid duplicate grants. Existing configurations and per-site commands remain unchanged unless you explicitly edit them.

AnySite conditions and random rolls still evaluate once for that AnySite invocation, not once per captured vote. Its count is the captured input, not the number of condition-qualified rewards, successful commands or votes at a particular site. Even an entry whose site no longer resolves is included. Keep site-specific and independently randomized rewards in their existing per-vote paths.

The queued AnySite reward still finishes before the sequential site rewards. The queue is committed only after the existing asynchronous reward chain completes. A denied/cancelled AnySite reward may complete without granting anything, under existing reward rules. Failed or ambiguous delivery retains the existing pending recovery fence; this placeholder adds no automatic retry or recovery guarantee. A crash after a command effect but before completion storage can still require audited reconciliation.

The value is local to the reward options for this invocation; it is not a live queue lookup or a global PlaceholderAPI vote total. Existing top-voter, VoteParty and GUI uses of `%votes%` retain their own meanings. No claim is made for separate proxy/native-loader reward engines or external calls constructing unrelated reward options.
Loading