Skip to content
Merged
Changes from 1 commit
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 @@ -22,6 +22,7 @@ public class VotePlaceholderProvider implements PlaceholderProvider, Runnable, L
private final Map<Integer, VoteSite> voteSites = new HashMap<>();
private final Map<String, VoteUser> users = new HashMap<>();
private final List<TopVoteUser> topVotes = new ArrayList<>();
private volatile VoteGoal goal;

private volatile boolean pendingRefresh = true;
private volatile Instant lastUpdate = Instant.MIN;
Expand Down Expand Up @@ -64,7 +65,9 @@ public List<String> availablePlaceholders() {
"%azlink_vote_sites_[id]_name%",
"%azlink_vote_sites_[id]_url%",
"%azlink_vote_top_[position]_name%",
"%azlink_vote_top_[position]_votes%"
"%azlink_vote_top_[position]_votes%",
"%azlink_vote_goal_target%",
"%azlink_vote_goal_progress%"
);
}

Expand Down Expand Up @@ -94,6 +97,8 @@ public String evaluatePlaceholder(String[] parts, OfflinePlayer player) {
return topPlaceholder(parts);
case "sites":
return sitePlaceholder(parts);
case "goal":
return goalPlaceholder(parts);
default:
return null;
}
Expand Down Expand Up @@ -134,6 +139,23 @@ private String userCanPlaceholder(String[] parts, OfflinePlayer player) throws N
return null;
}

private String goalPlaceholder(String[] parts) throws NumberFormatException {
VoteGoal currentGoal = this.goal;

if (currentGoal == null) {
return "0";
}

switch (parts[1]) {
case "target":
return Integer.toString(currentGoal.target);
case "progress":
return Integer.toString(currentGoal.progress);
Comment thread
MrMicky-FR marked this conversation as resolved.
Outdated
default:
return null;
}
}

private String sitePlaceholder(String[] parts) throws NumberFormatException {
if (parts[1].equals("count")) {
return Integer.toString(voteSites.size());
Expand Down Expand Up @@ -229,6 +251,7 @@ private void refreshData() {
this.voteSites.clear();
this.users.clear();
this.topVotes.clear();
this.goal = response.goal;

Comment thread
MrMicky-FR marked this conversation as resolved.
for (VoteSite site : response.sites) {
this.voteSites.put(site.id, site);
Expand Down Expand Up @@ -260,6 +283,12 @@ public static class VoteResponse {
public List<VoteUser> users = new ArrayList<>();
@SerializedName("top_votes")
public List<TopVoteUser> topVotes = new ArrayList<>();
public VoteGoal goal;
}

public static class VoteGoal {
public int target;
public int progress;
}

public static class VoteUser {
Expand Down
Loading