Skip to content

Commit 73bba25

Browse files
committed
Implement VoteMilestones system with configuration and logging support
1 parent 83ca134 commit 73bba25

30 files changed

+3374
-328
lines changed

VotingPlugin/src/main/java/com/bencodez/votingplugin/VotingPluginMain.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import com.bencodez.votingplugin.servicesites.ServiceSiteHandler;
9191
import com.bencodez.votingplugin.signs.Signs;
9292
import com.bencodez.votingplugin.specialrewards.SpecialRewards;
93+
import com.bencodez.votingplugin.specialrewards.votemilestones.VoteMilestonesManager;
9394
import com.bencodez.votingplugin.test.VoteTester;
9495
import com.bencodez.votingplugin.timequeue.TimeQueueHandler;
9596
import com.bencodez.votingplugin.topvoter.TopVoter;
@@ -101,6 +102,7 @@
101102
import com.bencodez.votingplugin.votelog.VoteLogMysqlTable;
102103
import com.bencodez.votingplugin.votelog.listeners.PlayerPostVoteLoggerListener;
103104
import com.bencodez.votingplugin.votelog.listeners.PlayerSpecialRewardLoggerListener;
105+
import com.bencodez.votingplugin.votelog.listeners.VoteMilestoneVoteLogListener;
104106
import com.bencodez.votingplugin.votelog.listeners.VoteShopPurchaseLoggerListener;
105107
import com.bencodez.votingplugin.voteparty.VoteParty;
106108
import com.bencodez.votingplugin.votereminding.VoteReminding;
@@ -875,6 +877,39 @@ public void save() {
875877
}
876878
}
877879

880+
// VoteMilestones (NEW system)
881+
ConfigurationSection voteMilestonesSection = plugin.getSpecialRewardsConfig().getData()
882+
.getConfigurationSection("VoteMilestones");
883+
884+
if (voteMilestonesSection != null) {
885+
for (String milestoneId : voteMilestonesSection.getKeys(false)) {
886+
887+
// Direct edit path: VoteMilestones.<id>.Rewards
888+
addDirectlyDefinedRewards(new DirectlyDefinedReward("VoteMilestones." + milestoneId + ".Rewards") {
889+
890+
@Override
891+
public void setData(String path, Object value) {
892+
plugin.getSpecialRewardsConfig().getData().set(path, value);
893+
}
894+
895+
@Override
896+
public void createSection(String key) {
897+
plugin.getSpecialRewardsConfig().getData().createSection(key);
898+
}
899+
900+
@Override
901+
public ConfigurationSection getFileData() {
902+
return plugin.getSpecialRewardsConfig().getData();
903+
}
904+
905+
@Override
906+
public void save() {
907+
plugin.getSpecialRewardsConfig().saveData();
908+
}
909+
});
910+
}
911+
}
912+
878913
// vote streaks, old way
879914
String[] types = new String[] { "Day", "Week", "Month" };
880915
for (String type : types) {
@@ -1180,6 +1215,8 @@ public void run() {
11801215

11811216
topVoterHandler.register();
11821217

1218+
voteMilestonesManager = new VoteMilestonesManager(this);
1219+
11831220
plugin.getBukkitScheduler().runTaskAsynchronously(plugin, new Runnable() {
11841221

11851222
@Override
@@ -1522,6 +1559,7 @@ private void registerEvents() {
15221559
pm.registerEvents(new PlayerPostVoteLoggerListener(this), this);
15231560
pm.registerEvents(new PlayerSpecialRewardLoggerListener(this), this);
15241561
pm.registerEvents(new VoteShopPurchaseLoggerListener(this), this);
1562+
pm.registerEvents(new VoteMilestoneVoteLogListener(this), this);
15251563
pm.registerEvents(new SignChange(this), this);
15261564
pm.registerEvents(new BlockBreak(this), this);
15271565
if (!plugin.getConfigFile().isDisableInteractEvent()) {
@@ -1566,6 +1604,8 @@ private void reloadPlugin(boolean userStorage) {
15661604

15671605
specialRewardsConfig.reloadData();
15681606

1607+
voteMilestonesManager.reload();
1608+
15691609
gui.reloadData();
15701610
shopFile.reloadData();
15711611

@@ -1796,6 +1836,9 @@ public synchronized void update() {
17961836
@Getter
17971837
private VoteLogMysqlTable voteLogMysqlTable;
17981838

1839+
@Getter
1840+
private VoteMilestonesManager voteMilestonesManager;
1841+
17991842
public void loadVoteLoggingMySQL() {
18001843
if (getConfigFile().isVoteLoggingEnabled()) {
18011844
if (getConfigFile().isVoteLoggingUseMainMySQL()) {
@@ -1804,12 +1847,12 @@ public void loadVoteLoggingMySQL() {
18041847
getOptions().getDebug().isDebug()) {
18051848

18061849
@Override
1807-
public void logSevere1(String string) {
1850+
public void logSevere(String string) {
18081851
plugin.getLogger().severe(string);
18091852
}
18101853

18111854
@Override
1812-
public void logInfo1(String string) {
1855+
public void logInfo(String string) {
18131856
plugin.getLogger().info(string);
18141857
}
18151858

@@ -1835,12 +1878,12 @@ public void debug(Throwable t) {
18351878
getOptions().getDebug().isDebug()) {
18361879

18371880
@Override
1838-
public void logSevere1(String string) {
1881+
public void logSevere(String string) {
18391882
plugin.getLogger().severe(string);
18401883
}
18411884

18421885
@Override
1843-
public void logInfo1(String string) {
1886+
public void logInfo(String string) {
18441887
plugin.getLogger().info(string);
18451888
}
18461889

VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/admin/votelog/AdminVoteLogHelpers.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@ public static Material getMaterialForEvent(VoteLogMysqlTable.VoteLogEvent event,
2222
case VOTE_RECEIVED:
2323
return Material.EMERALD;
2424

25-
// Reward triggers
26-
case ALL_SITES_REWARD:
27-
return Material.DIAMOND;
28-
29-
case ALMOST_ALL_SITES_REWARD:
30-
return Material.LAPIS_LAZULI;
31-
32-
case FIRST_VOTE_REWARD:
33-
return Material.NETHER_STAR;
34-
35-
case FIRST_VOTE_TODAY_REWARD:
36-
return Material.SUNFLOWER;
37-
38-
case CUMULATIVE_REWARD:
39-
return Material.GOLD_INGOT;
40-
41-
case MILESTONE_REWARD:
25+
case VOTEMILESTONE:
4226
return Material.ANVIL;
4327

4428
case VOTE_STREAK_REWARD:
@@ -60,17 +44,7 @@ public static String getEventColor(VoteLogMysqlTable.VoteLogEvent event) {
6044
switch (event) {
6145
case VOTE_RECEIVED:
6246
return "&a";
63-
64-
case ALL_SITES_REWARD:
65-
case ALMOST_ALL_SITES_REWARD:
66-
return "&b";
67-
68-
case FIRST_VOTE_REWARD:
69-
case FIRST_VOTE_TODAY_REWARD:
70-
return "&e";
71-
72-
case CUMULATIVE_REWARD:
73-
case MILESTONE_REWARD:
47+
case VOTEMILESTONE:
7448
return "&6";
7549

7650
case VOTE_STREAK_REWARD:

VotingPlugin/src/main/java/com/bencodez/votingplugin/events/SpecialRewardType.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import lombok.Getter;
44

55
public enum SpecialRewardType {
6-
ALLSITE, CUMMULATIVE, FIRSTVOTE, FIRSTVOTETODAY, MILESTONE, VOTESTREAK, ALMOSTALLSITES, TOPVOTER, VOTESTREAKS;
6+
@Deprecated
7+
ALLSITE, @Deprecated
8+
CUMMULATIVE, @Deprecated
9+
FIRSTVOTE, @Deprecated
10+
FIRSTVOTETODAY, @Deprecated
11+
MILESTONE, VOTESTREAK, @Deprecated
12+
ALMOSTALLSITES, TOPVOTER, VOTESTREAKS;
713

814
@Getter
915
private int amount = -1;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.bencodez.votingplugin.events;
2+
3+
import java.util.Collections;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import java.util.UUID;
7+
8+
import org.bukkit.event.Event;
9+
import org.bukkit.event.HandlerList;
10+
11+
import com.bencodez.votingplugin.specialrewards.votemilestones.VoteMilestone;
12+
import com.bencodez.votingplugin.user.VotingPluginUser;
13+
14+
import lombok.Getter;
15+
16+
/**
17+
* Fired after a VoteMilestone reward has been executed successfully.
18+
*/
19+
public class VoteMilestoneRewardEvent extends Event {
20+
21+
private static final HandlerList HANDLERS = new HandlerList();
22+
23+
private final VotingPluginUser user;
24+
private final UUID uuid;
25+
private final String playerName;
26+
27+
private final VoteMilestone milestone;
28+
private final long value;
29+
30+
private final String groupId;
31+
private final String rewardPath;
32+
@Getter
33+
private final UUID voteUUID;
34+
private final Map<String, String> placeholders;
35+
36+
/**
37+
* Constructs a new VoteMilestoneRewardEvent.
38+
*
39+
* @param user VotingPluginUser who received the reward
40+
* @param milestone milestone that triggered
41+
* @param value resolved total value used for matching
42+
* @param groupId resolved group id used for selection
43+
* @param rewardPath path used to execute rewards
44+
* @param placeholders placeholders passed to the reward handler
45+
* @param voteUUID UUID of the vote that triggered this reward (may be null)
46+
*/
47+
public VoteMilestoneRewardEvent(VotingPluginUser user, VoteMilestone milestone, long value, String groupId,
48+
String rewardPath, Map<String, String> placeholders, UUID voteUUID) {
49+
super(true);
50+
this.user = user;
51+
this.uuid = user == null ? null : user.getJavaUUID();
52+
this.playerName = user == null ? null : user.getPlayerName();
53+
this.milestone = milestone;
54+
this.value = value;
55+
this.groupId = groupId;
56+
this.rewardPath = rewardPath;
57+
this.voteUUID = voteUUID;
58+
if (placeholders == null || placeholders.isEmpty()) {
59+
this.placeholders = Collections.emptyMap();
60+
} else {
61+
this.placeholders = Collections.unmodifiableMap(new HashMap<>(placeholders));
62+
}
63+
}
64+
65+
public VotingPluginUser getUser() {
66+
return user;
67+
}
68+
69+
public UUID getUuid() {
70+
return uuid;
71+
}
72+
73+
public String getPlayerName() {
74+
return playerName;
75+
}
76+
77+
public VoteMilestone getMilestone() {
78+
return milestone;
79+
}
80+
81+
public String getMilestoneId() {
82+
return milestone == null ? null : milestone.getId();
83+
}
84+
85+
public long getValue() {
86+
return value;
87+
}
88+
89+
public String getGroupId() {
90+
return groupId;
91+
}
92+
93+
public String getRewardPath() {
94+
return rewardPath;
95+
}
96+
97+
public Map<String, String> getPlaceholders() {
98+
return placeholders;
99+
}
100+
101+
@Override
102+
public HandlerList getHandlers() {
103+
return HANDLERS;
104+
}
105+
106+
public static HandlerList getHandlerList() {
107+
return HANDLERS;
108+
}
109+
}

VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/PlayerVoteListener.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.time.LocalDateTime;
44
import java.time.ZoneId;
55
import java.util.ArrayList;
6+
import java.util.HashMap;
67
import java.util.UUID;
78

89
import org.bukkit.Bukkit;
@@ -189,8 +190,10 @@ public void onplayerVote(PlayerVoteEvent event) {
189190
}
190191

191192
// check first vote rewards
192-
plugin.getSpecialRewards().checkFirstVote(voteUUID, user, event.isForceBungee());
193-
plugin.getSpecialRewards().checkFirstVoteToday(voteUUID, user, event.isForceBungee());
193+
// plugin.getSpecialRewards().checkFirstVote(voteUUID, user,
194+
// event.isForceBungee());
195+
// plugin.getSpecialRewards().checkFirstVoteToday(voteUUID, user,
196+
// event.isForceBungee());
194197

195198
if (user.isReminded() && plugin.getConfigFile().isVoteRemindingRemindOnlyOnce()) {
196199
user.setReminded(false);
@@ -253,12 +256,19 @@ public void onplayerVote(PlayerVoteEvent event) {
253256
}
254257
}
255258

259+
plugin.getVoteMilestonesManager().handleVote(user, event.getBungeeTextTotals(), event.isForceBungee(), voteUUID,
260+
new HashMap<String, String>());
261+
256262
// other rewards
257-
plugin.getSpecialRewards().checkAllSites(voteUUID, user, event.isForceBungee());
258-
plugin.getSpecialRewards().checkAlmostAllSites(voteUUID, user, event.isForceBungee());
259-
plugin.getSpecialRewards().checkCumualativeVotes(voteUUID, user, event.getBungeeTextTotals(),
260-
event.isForceBungee());
261-
plugin.getSpecialRewards().checkMilestone(voteUUID, user, event.getBungeeTextTotals(), event.isForceBungee());
263+
// plugin.getSpecialRewards().checkAllSites(voteUUID, user,
264+
// event.isForceBungee());
265+
// plugin.getSpecialRewards().checkAlmostAllSites(voteUUID, user,
266+
// event.isForceBungee());
267+
// plugin.getSpecialRewards().checkCumualativeVotes(voteUUID, user,
268+
// event.getBungeeTextTotals(),
269+
// event.isForceBungee());
270+
// plugin.getSpecialRewards().checkMilestone(voteUUID, user,
271+
// event.getBungeeTextTotals(), event.isForceBungee());
262272
plugin.getCoolDownCheck().vote(user, voteSite);
263273

264274
plugin.getVoteStreakHandler().processVote(user, voteTime, voteUUID);

0 commit comments

Comments
 (0)