Skip to content

Developer API

xVote’s API is in the xvote-api artifact, which xVote ships inside its own jar. Compile against it, and add xVote to your plugin’s depend or softdepend.

dependencies {
compileOnly("co.xenastudios.xvote:xvote-api:1.0.0")
}

Until it’s on Maven Central, build it from the repo with ./gradlew :xvote:api:publishToMavenLocal and add mavenLocal().

XVoteApi votes = XVoteApi.get();
VoterStats stats = votes.stats(player.getUniqueId());
int month = stats.month();
List<TopVoter> top = votes.top(Period.WEEK, 10);
PartyProgress party = votes.party();

Every read answers from memory and returns at once, on any thread.

Add a reward that server owners can use in xVote’s config:

XVoteApi.get().registerRewardType(this, "cratekey", (player, argument) -> giveKey(player, argument));

A reward with custom: ["cratekey vote 1"] then calls it with vote 1, on the player’s own thread, while they’re online.

A website’s webhook or a Discord bot can send votes through the same ledger, checks and rewards:

XVoteApi.get().submitVote("MyWebsite", "Steve", "").thenAccept(result -> ...);

The future completes off the server’s threads with what happened: COUNTED, WAITING (no player with that name has joined yet), DUPLICATE, INVALID, CANCELLED or FAILED.

Event Fired Cancelling it
VoteReceivedEvent Off the server’s threads, before a vote is stored Drops the vote.
VoteRewardEvent On the player’s thread, before rewards are given Gives nothing for that vote; it still counts. getRewards() can leave some out.
VotePartyEvent On the global thread of each server, before the party’s rewards Gives this server’s players nothing.

Each is only made when something listens for it.