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 @@ -177,6 +177,9 @@ public File getLoadedPluginJarFile() {
@Getter
private BroadcastHandler broadcastHandler;

@Getter
private com.bencodez.votingplugin.streaks.VoteStreaksMenu voteStreaksMenu;

@Getter
private BackendProxyHandler backendProxyHandler;
private ProcessedVoteCache backendProcessedVoteCache;
Expand Down Expand Up @@ -1995,6 +1998,7 @@ private void shutdownVoteReminders() {

@Override
public void onUnLoad() {
if (voteStreaksMenu != null) voteStreaksMenu.close();
stopAutoCreateVoteSitesSetupReminder();
placeholderPlayerPresence.clear();
stopBackendHostedControlLifecycle();
Expand Down Expand Up @@ -2080,6 +2084,8 @@ private void registerCommands() {
* Register events.
*/
private void registerEvents() {
voteStreaksMenu = new com.bencodez.votingplugin.streaks.VoteStreaksMenu(this);
getServer().getPluginManager().registerEvents(voteStreaksMenu, this);
PluginManager pm = getServer().getPluginManager();

pm.registerEvents(new PlayerJoinEvent(this), this);
Expand Down Expand Up @@ -2160,6 +2166,7 @@ private void reloadPlugin(boolean userStorage, boolean reconcileHostedControl,
boolean updateActiveBackendRuntime) {
if (offlineVoteOwnerHandoffs != null) offlineVoteOwnerHandoffs.pause();
try {
if (voteStreaksMenu != null) voteStreaksMenu.suspend();
configFile.reloadData();
configFile.loadValues();
AutoCreateVoteSitesReminderService setupReminder = autoCreateVoteSitesSetupReminder;
Expand Down Expand Up @@ -2213,6 +2220,7 @@ private void reloadPlugin(boolean userStorage, boolean reconcileHostedControl,

setUpdate(true);
} finally {
if (voteStreaksMenu != null) voteStreaksMenu.resume();
if (offlineVoteOwnerHandoffs != null) offlineVoteOwnerHandoffs.resume();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4069,6 +4069,9 @@ public void run() {
}
}

// Preserve administrator-defined matches ahead of this new fallback.
com.bencodez.votingplugin.streaks.VoteStreaksCommand.register(plugin);

ArrayList<CommandHandler> avCommands = com.bencodez.advancedcore.command.CommandLoader.getInstance()
.getBasicCommands("VotingPlugin");
for (CommandHandler cmd : avCommands) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
*/
public class GUI extends YMLFile {

@ConfigDataString(path = "CHEST.VoteStreaks.Name")
@Getter
private String chestVoteStreaksName = "&6Vote streaks";

@ConfigDataString(path = "BOOK.VoteURLBookGUI.AlreadyVotedColor")
@Getter
private String bookVoteURLBookGUIAlreadyVotedColor = "RED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class VoteStreakHandler {
private final Map<String, VoteStreakDefinition> byId = new LinkedHashMap<>();
private final Map<String, VoteStreakDefinition> byProgressGroup = new LinkedHashMap<>();
private final List<VoteStreakDefinition> ordered = new ArrayList<>();
private volatile List<VoteStreakDefinition> displayDefinitions = List.of();

public VoteStreakHandler(VotingPluginMain plugin) {
this.plugin = plugin;
Expand All @@ -56,6 +57,26 @@ public void reload() {
// VoteStreak definitions live in specialrewards.yml now (Option B)
ConfigurationSection root = plugin.getSpecialRewardsConfig().getData();
new VoteStreakConfigLoader().load(root);
displayDefinitions = ordered.stream().filter(VoteStreakDefinition::isEnabled).toList();
}

/** Worker-only, observational view. Does not advance periods, save state or execute rewards. */
public com.bencodez.votingplugin.streaks.VoteStreaksSnapshot snapshotForDisplay(VotingPluginUser user) {
var definitions = displayDefinitions;
var periods = List.of(
new com.bencodez.votingplugin.streaks.VoteStreaksSnapshot.Period(VoteStreakType.DAILY, user.getDayVoteStreak(), user.getBestDayVoteStreak()),
new com.bencodez.votingplugin.streaks.VoteStreaksSnapshot.Period(VoteStreakType.WEEKLY, user.getWeekVoteStreak(), user.getBestWeekVoteStreak()),
new com.bencodez.votingplugin.streaks.VoteStreaksSnapshot.Period(VoteStreakType.MONTHLY, user.getMonthVoteStreak(), user.getBestMonthVoteStreak()));
var states = new LinkedHashMap<String, StreakState>();
var rows = new ArrayList<com.bencodez.votingplugin.streaks.VoteStreaksSnapshot.Milestone>();
for (var definition : definitions) {
if (rows.size() >= com.bencodez.votingplugin.streaks.VoteStreaksSnapshot.MAX_MILESTONES) break;
var state = states.computeIfAbsent(getColumnName(definition), ignored -> readState(user, definition));
String label = definition.getId().codePoints().limit(80).collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();
rows.add(new com.bencodez.votingplugin.streaks.VoteStreaksSnapshot.Milestone(label, definition.getType(), state.streakCount,
state.bestStreakCount, definition.getRequiredAmount(), definition.getVotesRequired(), definition.isRecurring()));
}
return new com.bencodez.votingplugin.streaks.VoteStreaksSnapshot(periods, rows, definitions.size() > rows.size());
}

public List<VoteStreakDefinition> getDefinitions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bencodez.votingplugin.streaks;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.bencodez.advancedcore.api.command.CommandHandler;
import com.bencodez.votingplugin.VotingPluginMain;

public final class VoteStreaksCommand {
private VoteStreaksCommand() { }
public static void register(VotingPluginMain plugin) {
plugin.getVoteCommand().add(new CommandHandler(plugin, new String[] { "Streaks" },
VoteStreaksMenu.PERMISSION + "|VotingPlugin.Player", "View your vote streak progression", false) {
@Override public void execute(CommandSender sender, String[] args) {
if (sender instanceof Player player && plugin.getVoteStreaksMenu() != null) {
plugin.getVoteStreaksMenu().open(player);
}
}
});
}
}
Loading
Loading