-
-
Notifications
You must be signed in to change notification settings - Fork 22
Add vote_goal placeholders #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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%" | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
| } | ||
|
|
@@ -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); | ||
| default: | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private String sitePlaceholder(String[] parts) throws NumberFormatException { | ||
| if (parts[1].equals("count")) { | ||
| return Integer.toString(voteSites.size()); | ||
|
|
@@ -229,6 +251,7 @@ private void refreshData() { | |
| this.voteSites.clear(); | ||
| this.users.clear(); | ||
| this.topVotes.clear(); | ||
| this.goal = response.goal; | ||
|
|
||
|
Comment on lines
245
to
255
|
||
| for (VoteSite site : response.sites) { | ||
| this.voteSites.put(site.id, site); | ||
|
|
@@ -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 { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goalPlaceholder returns "0" whenever goal is null, even if the requested sub-key is invalid (e.g., %azlink_vote_goal_typo% would yield 0 instead of returning null). This makes invalid placeholders harder to detect and is inconsistent with other placeholder handlers. Consider switching on parts[1] first and only returning "0" for the known keys (target/progress) when goal is missing, while still returning null for unknown keys.