diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/BungeeHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/BungeeHandler.java index c5b178483..bd8bae272 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/BungeeHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/BungeeHandler.java @@ -47,6 +47,9 @@ import lombok.Getter; +/** + * Handler for Bungee/proxy server integration. + */ public class BungeeHandler implements Listener { @Getter private ClientHandler clientHandler; @@ -86,10 +89,18 @@ public class BungeeHandler implements Listener { @Getter private MqttHandler mqttHandler; + /** + * Constructs a new BungeeHandler. + * + * @param plugin the main plugin instance + */ public BungeeHandler(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Checks and processes global data from the global data handler. + */ public void checkGlobalData() { HashMap data = globalDataHandler.getExact(plugin.getBungeeSettings().getServer()); @@ -126,6 +137,13 @@ public void checkGlobalData() { } } + /** + * Checks global data for a time type change. + * + * @param type the time type to check + * @param data the global data map + * @return true if currently processing a time change + */ public boolean checkGlobalDataTime(TimeType type, HashMap data) { boolean isProcessing = false; if (data.containsKey(type.toString())) { @@ -157,6 +175,12 @@ public boolean checkGlobalDataTime(TimeType type, HashMap dat return isProcessing; } + /** + * Checks and extracts the boolean value from a DataValue. + * + * @param data the data value + * @return the boolean value + */ public boolean checkGlobalDataTimeValue(DataValue data) { if (data.isBoolean()) { return data.getBoolean(); @@ -164,6 +188,9 @@ public boolean checkGlobalDataTimeValue(DataValue data) { return Boolean.valueOf(data.getString()); } + /** + * Closes and cleans up all handlers and connections. + */ public void close() { if (backendMysqlMessenger != null) { backendMysqlMessenger.shutdown(); @@ -182,6 +209,9 @@ public void close() { } } + /** + * Loads and initializes the bungee handler with the configured method. + */ public void load() { plugin.debug("Loading bungee handler"); @@ -576,6 +606,9 @@ private void handleWireVote(JsonEnvelope msg) { int _ignored = v.numberOfVotes; } + /** + * Loads the global MySQL handler for cross-server data synchronization. + */ public void loadGlobalMysql() { if (plugin.getBungeeSettings().isGloblalDataEnabled()) { if (timer != null) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastHandler.java index 5de90560f..985374b24 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastHandler.java @@ -58,6 +58,13 @@ public final class BroadcastHandler { private final ConcurrentHashMap> intervalSites = new ConcurrentHashMap>(); private volatile BukkitTask intervalTask; + /** + * Constructs a new BroadcastHandler. + * + * @param plugin the main plugin instance + * @param settings the broadcast settings + * @param zoneId the time zone ID, or null to use system default + */ public BroadcastHandler(VotingPluginMain plugin, BroadcastSettings settings, ZoneId zoneId) { this.plugin = plugin; this.settings = settings; @@ -66,6 +73,11 @@ public BroadcastHandler(VotingPluginMain plugin, BroadcastSettings settings, Zon rescheduleIntervalIfNeeded(); } + /** + * Updates the broadcast settings and reschedules interval task if needed. + * + * @param settings the new broadcast settings + */ public void setSettings(BroadcastSettings settings) { this.settings = settings; rescheduleIntervalIfNeeded(); @@ -77,6 +89,7 @@ public void setSettings(BroadcastSettings settings) { * @param uuid player's uuid * @param playerName player name (optional; if null/empty, resolved from Bukkit) * @param siteName vote site name (display name) + * @param wasOnline whether the player was online when the vote was received */ public void broadcastVote(UUID uuid, String playerName, String siteName, boolean wasOnline) { BroadcastSettings s = settings; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastSettings.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastSettings.java index b2ce783d0..44dcde8ed 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastSettings.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/BroadcastSettings.java @@ -18,6 +18,14 @@ public final class BroadcastSettings { private final int maxSitesListed; private final BroadcastFormat format; + /** + * Constructs a BroadcastSettings with the specified parameters. + * + * @param type the broadcast type + * @param duration the broadcast duration + * @param maxSitesListed the maximum number of sites to list + * @param format the broadcast format + */ public BroadcastSettings(VoteBroadcastType type, ParsedDuration duration, int maxSitesListed, BroadcastFormat format) { this.type = type == null ? VoteBroadcastType.NONE : type; @@ -26,22 +34,47 @@ public BroadcastSettings(VoteBroadcastType type, ParsedDuration duration, int ma this.format = format == null ? new BroadcastFormat("", "", "") : format; } + /** + * Returns the broadcast type. + * + * @return the broadcast type + */ public VoteBroadcastType getType() { return type; } + /** + * Returns the broadcast duration. + * + * @return the broadcast duration + */ public ParsedDuration getDuration() { return duration; } + /** + * Returns the maximum number of sites to list. + * + * @return the maximum number of sites to list + */ public int getMaxSitesListed() { return maxSitesListed; } + /** + * Returns the broadcast format. + * + * @return the broadcast format + */ public BroadcastFormat getFormat() { return format; } + /** + * Returns whether broadcasting is disabled. + * + * @return true if broadcasting is disabled + */ public boolean isDisabled() { return type == VoteBroadcastType.NONE; } @@ -51,6 +84,9 @@ public boolean isDisabled() { * * Expected structure: VoteBroadcast: Type: EVERY_VOTE Duration: 2m * MaxSitesListed: 0 Format: BroadcastMsg: '...' Header: '...' ListLine: '...' + * + * @param sec the configuration section to load from + * @return the loaded broadcast settings */ public static BroadcastSettings load(ConfigurationSection sec) { VoteBroadcastType type = VoteBroadcastType.parse(sec == null ? null : sec.getString("Type"), diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/VoteBroadcastType.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/VoteBroadcastType.java index 6b251890a..8c65b45bf 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/VoteBroadcastType.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/broadcast/VoteBroadcastType.java @@ -9,6 +9,9 @@ */ public enum VoteBroadcastType { + /** + * No vote broadcasting. + */ NONE, /** @@ -47,6 +50,12 @@ public enum VoteBroadcastType { */ INTERVAL_SUMMARY_GLOBAL; + /** + * Parses a vote broadcast type from a string. + * @param s the string to parse + * @param def the default value if parsing fails + * @return the parsed broadcast type or default + */ public static VoteBroadcastType parse(String s, VoteBroadcastType def) { if (s == null || s.trim().isEmpty()) { return def; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/CommandLoader.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/CommandLoader.java index de36f660d..5562afb66 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/CommandLoader.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/CommandLoader.java @@ -101,6 +101,11 @@ public class CommandLoader { private VotingPluginMain plugin; + /** + * Constructs a new CommandLoader. + * + * @param plugin the main plugin instance + */ public CommandLoader(VotingPluginMain plugin) { this.plugin = plugin; } @@ -112,6 +117,12 @@ public String getAdminPerm() { return adminPerm; } + /** + * Gets the back button for inventory navigation. + * + * @param user the voting plugin user + * @return the back button + */ public BInventoryButton getBackButton(VotingPluginUser user) { ConfigurationSection sec = plugin.getGui().getCHESTBackButton(); boolean a = false; @@ -181,6 +192,13 @@ public String getPlayerPerm() { return playerPerm; } + /** + * Checks if a player has permission for a command. + * + * @param player the player + * @param cmd the command + * @return true if player has permission + */ public boolean hasPermission(Player player, String cmd) { if (cmd.startsWith("votingplugin:")) { cmd = cmd.substring("votingplugin:".length()); @@ -230,6 +248,13 @@ public boolean hasPermission(Player player, String cmd) { return false; } + /** + * Checks if a command belongs to the VotingPlugin. + * + * @param player the player + * @param cmd the command + * @return true if it's a VotingPlugin command + */ public boolean isVotingPluginCommand(Player player, String cmd) { if (plugin.getCommand(cmd) != null || cmd.startsWith("votingplugin")) { return true; @@ -2321,6 +2346,11 @@ public void execute(CommandSender sender, String[] args) { private final Set aliasCommandNames = new HashSet<>(); + /** + * Gets the set of alias command names. + * + * @return set of alias command names + */ public Set getAliasCommandNames() { return aliasCommandNames; } @@ -3300,6 +3330,13 @@ public void run() { } } + /** + * Processes a slot click action from a GUI. + * + * @param player the player + * @param user the voting plugin user + * @param slot the slot identifier + */ public void processSlotClick(Player player, VotingPluginUser user, String slot) { if (MessageAPI.startsWithIgnoreCase(slot, "url")) { new VoteURL(plugin, player, user, true).open(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAdminVote.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAdminVote.java index 0712453a7..548c69e68 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAdminVote.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAdminVote.java @@ -16,6 +16,11 @@ public class CommandAdminVote implements CommandExecutor { private VotingPluginMain plugin; + /** + * Constructs a new CommandAdminVote instance. + * + * @param plugin the main plugin instance + */ public CommandAdminVote(VotingPluginMain plugin) { this.plugin = plugin; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAliases.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAliases.java index aed501d71..032c86dd1 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAliases.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/executers/CommandAliases.java @@ -25,6 +25,12 @@ public class CommandAliases implements CommandExecutor { /** The plugin. */ private VotingPluginMain plugin = VotingPluginMain.plugin; + /** + * Constructs a new CommandAliases instance. + * + * @param cmdHandle the command handler + * @param adminCommand whether this is an admin command + */ public CommandAliases(CommandHandler cmdHandle, boolean adminCommand) { this.cmdHandle = cmdHandle; this.adminCommand = adminCommand; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteBest.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteBest.java index c0c2ef279..a656a7f18 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteBest.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteBest.java @@ -18,11 +18,20 @@ import com.bencodez.votingplugin.VotingPluginMain; import com.bencodez.votingplugin.user.VotingPluginUser; +/** + * GUI handler for vote best/streak display. + */ public class VoteBest extends GUIHandler { private VotingPluginMain plugin; private VotingPluginUser user; + /** + * Constructs a new vote best GUI. + * @param plugin the plugin instance + * @param player the command sender + * @param user the voting plugin user + */ public VoteBest(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) { super(plugin, player); this.plugin = plugin; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteGUI.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteGUI.java index af18f7053..c2bccf28d 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteGUI.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteGUI.java @@ -19,11 +19,20 @@ import com.bencodez.votingplugin.VotingPluginMain; import com.bencodez.votingplugin.user.VotingPluginUser; +/** + * GUI handler for vote interface. + */ public class VoteGUI extends GUIHandler { private VotingPluginMain plugin; private VotingPluginUser user; + /** + * Constructs a new vote GUI. + * @param plugin the plugin instance + * @param player the command sender + * @param user the voting plugin user + */ public VoteGUI(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) { super(plugin, player); this.plugin = plugin; @@ -35,6 +44,12 @@ public ArrayList getChat(CommandSender arg0) { return null; } + /** + * Gets the item for a specific GUI slot. + * @param slot the slot name + * @param player the player + * @return the item builder for the slot + */ private ItemBuilder getItemSlot(String slot, Player player) { ItemBuilder builder = new ItemBuilder(plugin.getGui().getChestVoteGUISlotSection(slot)); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteHelp.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteHelp.java index 7729f9404..6240302fe 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteHelp.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteHelp.java @@ -17,11 +17,20 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; +/** + * GUI handler for vote help display. + */ public class VoteHelp extends GUIHandler { private int page; private VotingPluginMain plugin; + /** + * Constructs a new vote help GUI. + * @param plugin the plugin instance + * @param player the command sender + * @param page the page number + */ public VoteHelp(VotingPluginMain plugin, CommandSender player, int page) { super(plugin, player); this.plugin = plugin; @@ -33,6 +42,11 @@ public ArrayList getChat(CommandSender sender) { return null; } + /** + * Generates help text with hover support. + * @param sender the command sender + * @return list of text components for help + */ public ArrayList helpText(CommandSender sender) { ArrayList msg = new ArrayList<>(); HashMap unsorted = new HashMap<>(); @@ -64,6 +78,11 @@ public ArrayList helpText(CommandSender sender) { return msg; } + /** + * Generates legacy help text without hover support. + * @param sender the command sender + * @return list of text components for help + */ public ArrayList helpTextLegacy(CommandSender sender) { ArrayList msg = new ArrayList<>(); HashMap unsorted = new HashMap<>(); @@ -106,6 +125,11 @@ public void open() { open(GUIMethod.CHAT); } + /** + * Generates vote help text with pagination. + * @param sender the command sender + * @return list of text components for help + */ public ArrayList voteHelpText(CommandSender sender) { int pagesize = plugin.getConfigFile().getFormatPageSize(); ArrayList msg = new ArrayList<>(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteLast.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteLast.java index 06887a77f..7a693b338 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteLast.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteLast.java @@ -20,11 +20,21 @@ import com.bencodez.votingplugin.user.VotingPluginUser; import com.bencodez.votingplugin.votesites.VoteSite; +/** + * GUI handler for displaying last vote information. + */ public class VoteLast extends GUIHandler { private VotingPluginMain plugin; private VotingPluginUser user; + /** + * Constructs a new VoteLast GUI handler. + * + * @param plugin the main plugin instance + * @param player the command sender + * @param user the voting plugin user + */ public VoteLast(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) { super(plugin, player); this.plugin = plugin; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteNext.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteNext.java index fff70019d..3a6884259 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteNext.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/commands/gui/player/VoteNext.java @@ -24,11 +24,21 @@ import xyz.upperlevel.spigot.book.BookUtil; +/** + * GUI handler for displaying next vote information. + */ public class VoteNext extends GUIHandler { private VotingPluginMain plugin; private VotingPluginUser user; + /** + * Constructs a new VoteNext GUI handler. + * + * @param plugin the main plugin instance + * @param player the command sender + * @param user the voting plugin user + */ public VoteNext(VotingPluginMain plugin, CommandSender player, VotingPluginUser user) { super(plugin, player); this.plugin = plugin; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/BungeeSettings.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/BungeeSettings.java index 6dbee0d88..34c308b05 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/BungeeSettings.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/BungeeSettings.java @@ -13,6 +13,9 @@ import lombok.Getter; +/** + * Configuration file for Bungee/proxy settings. + */ public class BungeeSettings extends YMLFile { @ConfigDataBoolean(path = "BungeeDebug") @@ -135,11 +138,21 @@ public class BungeeSettings extends YMLFile { @Getter private ArrayList bungeeVotePartyGlobalCommands = new ArrayList<>(); + /** + * Constructs a new BungeeSettings. + * + * @param plugin the main plugin instance + */ public BungeeSettings(VotingPluginMain plugin) { super(plugin, new File(plugin.getDataFolder(), "BungeeSettings.yml")); setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles()); } + /** + * Gets the server name formatted for storage. + * + * @return the formatted server name + */ public String getServerNameStorage() { return getServer().replace("-", "_"); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/Config.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/Config.java index 0b9b1a6ae..9ee64bb1c 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/Config.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/Config.java @@ -52,6 +52,7 @@ public class Config extends YMLFile { @Getter private int limitVotePoints = -1; + /** Whether YAML files should be case insensitive. */ @ConfigDataBoolean(path = "CaseInsensitiveYMLFiles") @Getter public boolean caseInsensitiveYMLFiles = false; @@ -169,6 +170,11 @@ public class Config extends YMLFile { @Getter private boolean voteLoggingUseMainMySQL = true; + /** + * Gets the vote logging configuration section. + * + * @return the vote logging configuration section + */ public ConfigurationSection getVoteLoggingSection() { if (!getData().isConfigurationSection("VoteLogging")) { getData().createSection("VoteLogging"); @@ -176,6 +182,12 @@ public ConfigurationSection getVoteLoggingSection() { return getData().getConfigurationSection("VoteLogging"); } + /** + * Checks if DiscordSRV top voter is enabled. + * + * @param topVoter the top voter type + * @return true if enabled + */ public boolean isDiscordSRVTopVoterEnabled(TopVoter topVoter) { switch (topVoter) { case AllTime: @@ -191,6 +203,12 @@ public boolean isDiscordSRVTopVoterEnabled(TopVoter topVoter) { } } + /** + * Checks if DiscordSRV top voter should send a new message on update. + * + * @param topVoter the top voter type + * @return true if new message should be sent + */ public boolean isDiscordSRVTopVoterNewMessageOnUpdate(TopVoter topVoter) { switch (topVoter) { case AllTime: @@ -206,6 +224,12 @@ public boolean isDiscordSRVTopVoterNewMessageOnUpdate(TopVoter topVoter) { } } + /** + * Gets the DiscordSRV top voter channel ID. + * + * @param topVoter the top voter type + * @return the channel ID + */ public long getDiscordSRVTopVoterChannel(TopVoter topVoter) { switch (topVoter) { case AllTime: @@ -221,6 +245,12 @@ public long getDiscordSRVTopVoterChannel(TopVoter topVoter) { } } + /** + * Gets the DiscordSRV top voter title. + * + * @param topVoter the top voter type + * @return the title + */ public String getDiscordSRVTopVoterTitle(TopVoter topVoter) { switch (topVoter) { case AllTime: @@ -236,6 +266,12 @@ public String getDiscordSRVTopVoterTitle(TopVoter topVoter) { } } + /** + * Gets the DiscordSRV top voter rank display format. + * + * @param topVoter the top voter type + * @return the rank display format + */ public String getDiscordSRVTopVoterRankDisplay(TopVoter topVoter) { switch (topVoter) { case AllTime: @@ -737,6 +773,11 @@ public String getDiscordSRVTopVoterRankDisplay(TopVoter topVoter) { @Getter private boolean alwaysProcessAsyncPlaceholders = false; + /** + * Constructs a new Config. + * + * @param plugin the main plugin instance + */ public Config(VotingPluginMain plugin) { super(plugin, new File(plugin.getDataFolder(), "Config.yml")); setIgnoreCase(true); @@ -752,10 +793,22 @@ public ArrayList getBlackList() { return (ArrayList) getData().getList("BlackList", new ArrayList<>()); } + /** + * Gets the custom commands configuration section. + * + * @param ident the command identifier + * @return the configuration section + */ public ConfigurationSection getCustomCommands(String ident) { return getData().getConfigurationSection("CustomCommands." + ident); } + /** + * Gets the custom placeholder return keys. + * + * @param placeholder the placeholder name + * @return set of return keys + */ public Set getCustomPlaceholderReturns(String placeholder) { Set str = getData().getConfigurationSection("CustomPlaceholderReturns." + placeholder).getKeys(false); if (str == null) { @@ -764,6 +817,13 @@ public Set getCustomPlaceholderReturns(String placeholder) { return str; } + /** + * Gets a custom placeholder return value. + * + * @param placeholder the placeholder name + * @param returnString the return key + * @return the return value + */ public String getCustomPlaceholderReturns(String placeholder, String returnString) { return getData().getString("CustomPlaceholderReturns." + placeholder + "." + returnString, ""); } @@ -781,6 +841,11 @@ public ArrayList getFormatCommandsVoteParty() { } + /** + * Gets the vote streak lines format. + * + * @return list of format lines + */ @SuppressWarnings("unchecked") public ArrayList getFormatCommandsVoteStreakLines() { return (ArrayList) getData().getList("Format.Commands.Vote.Streak.Lines", new ArrayList<>()); @@ -798,6 +863,11 @@ public ArrayList getFormatCommandsVoteText() { return (ArrayList) getData().getList("Format.Commands.Vote.Text", str); } + /** + * Gets the vote total format lines. + * + * @return list of format lines + */ @SuppressWarnings("unchecked") public ArrayList getFormatCommandsVoteTotal() { ArrayList list = (ArrayList) getData().getList("Format.Commands.Vote.Total", new ArrayList<>()); @@ -811,6 +881,11 @@ public ArrayList getFormatCommandsVoteTotal() { return list; } + /** + * Gets the vote total all format lines. + * + * @return list of format lines + */ @SuppressWarnings("unchecked") public ArrayList getFormatCommandsVoteTotalAll() { @@ -836,6 +911,12 @@ public ArrayList getFormatVoteHelp() { return (ArrayList) getData().getList("Format.Commands.Vote.Help.Lines", new ArrayList<>()); } + /** + * Checks if a top voter type should be loaded. + * + * @param top the top voter type + * @return true if should be loaded + */ public boolean getLoadTopVoter(TopVoter top) { switch (top) { case AllTime: @@ -851,6 +932,11 @@ public boolean getLoadTopVoter(TopVoter top) { } } + /** + * Gets the placeholder cache level. + * + * @return the cache level + */ public PlaceholderCacheLevel getPlaceholderCacheLevel() { return PlaceholderCacheLevel.getCache(getPlaceholderCacheLevelString()); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ConfigVoteSites.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ConfigVoteSites.java index c100bb8b4..a0357637b 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ConfigVoteSites.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ConfigVoteSites.java @@ -30,6 +30,11 @@ public class ConfigVoteSites extends YMLFile { private VotingPluginMain plugin; + /** + * Constructs a new ConfigVoteSites. + * + * @param plugin the plugin instance + */ public ConfigVoteSites(VotingPluginMain plugin) { super(plugin, new File(plugin.getDataFolder(), "VoteSites.yml")); setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles()); @@ -126,14 +131,31 @@ public ConfigurationSection getData(String siteName) { return getData().getConfigurationSection("VoteSites." + siteName); } + /** + * Gets the display name for a site. + * + * @param site the site name + * @return the display name + */ public String getDisplayName(String site) { return getData(site).getString("Name"); } + /** + * Gets the path to the every site reward. + * + * @return the every site reward path + */ public String getEverySiteRewardPath() { return "EverySiteReward"; } + /** + * Gets the item configuration for a site. + * + * @param site the site name + * @return the item configuration + */ public ConfigurationSection getItem(String site) { if (getData(site).isConfigurationSection("DisplayItem")) { return getData(site).getConfigurationSection("DisplayItem"); @@ -141,6 +163,12 @@ public ConfigurationSection getItem(String site) { return getData(site).getConfigurationSection("Item"); } + /** + * Gets the permission required to view a site. + * + * @param siteName the site name + * @return the permission to view + */ public String getPermissionToView(String siteName) { return getData(siteName).getString("PermissionToView", ""); } @@ -175,6 +203,12 @@ public String getServiceSite(String siteName) { return getData(siteName).getString("ServiceSite"); } + /** + * Gets the vote delay for a site. + * + * @param site the site name + * @return the vote delay + */ public ParsedDuration getVoteDelay(String site) { ConfigurationSection sec = getData(site); @@ -192,6 +226,12 @@ public ParsedDuration getVoteDelay(String site) { return ParsedDuration.ofMillis(millis); } + /** + * Gets the vote delay daily hour for a site. + * + * @param siteName the site name + * @return the vote delay daily hour + */ public int getVoteDelayDailyHour(String siteName) { return getData(siteName).getInt("VoteDelayDailyHour", 0); } @@ -227,18 +267,42 @@ public File getVoteSiteFile(String siteName) { } + /** + * Gets whether to give rewards offline for a site. + * + * @param site the site name + * @return true if rewards should be given offline + */ public boolean getVoteSiteGiveOffline(String site) { return getData(site).getBoolean("ForceOffline", getData(site).getBoolean("GiveOffline")); } + /** + * Gets whether a site is hidden. + * + * @param siteName the site name + * @return true if the site is hidden + */ public boolean getVoteSiteHidden(String siteName) { return getData(siteName).getBoolean("Hidden"); } + /** + * Gets whether to ignore can vote check for a site. + * + * @param siteName the site name + * @return true if can vote check should be ignored + */ public boolean getVoteSiteIgnoreCanVote(String siteName) { return getData(siteName).getBoolean("IgnoreCanVote"); } + /** + * Gets whether vote delay resets daily for a site. + * + * @param siteName the site name + * @return true if vote delay resets daily + */ public boolean getVoteSiteResetVoteDelayDaily(String siteName) { return getData(siteName).getBoolean("VoteDelayDaily"); } @@ -285,6 +349,12 @@ public int compare(VoteSite v1, VoteSite v2) { return voteSites; } + /** + * Gets the names of vote sites. + * + * @param checkEnabled whether to check if sites are enabled + * @return the list of vote site names + */ public ArrayList getVoteSitesNames(boolean checkEnabled) { ArrayList siteNames = new ArrayList<>(); if (getData().isConfigurationSection("VoteSites")) { @@ -318,6 +388,12 @@ public String getVoteURL(String siteName) { return getData(siteName).getString("VoteURL", ""); } + /** + * Gets whether to wait until vote delay for a site. + * + * @param siteName the site name + * @return true if should wait until vote delay + */ public boolean getWaitUntilVoteDelay(String siteName) { return getData(siteName).getBoolean("WaitUntilVoteDelay", false); } @@ -394,10 +470,22 @@ public void setCumulativeRewards(String siteName, ArrayList value) { set(siteName, "Cumulative.Rewards", value); } + /** + * Sets the cumulative votes for a site. + * + * @param siteName the site name + * @param value the value + */ public void setCumulativeVotes(String siteName, int value) { set(siteName, "Cumulative.Votes", value); } + /** + * Sets the display name for a site. + * + * @param siteName the site name + * @param value the value + */ public void setDisplayName(String siteName, String value) { set(siteName, "Name", value); } @@ -412,6 +500,12 @@ public void setEnabled(String siteName, boolean disabled) { set(siteName, "Enabled", disabled); } + /** + * Sets whether to force offline for a site. + * + * @param siteName the site name + * @param value the value + */ public void setForceOffline(String siteName, boolean value) { set(siteName, "ForceOffline", value); @@ -485,10 +579,22 @@ public boolean siteCheck(String siteName) { return pass; } + /** + * Sets the vote delay daily hour for a site. + * + * @param siteName the site name + * @param intValue the value + */ public void setVoteDelayDailyHour(String siteName, int intValue) { set(siteName, "VoteDelayDailyHour", intValue); } + /** + * Sets whether vote delay is daily for a site. + * + * @param siteName the site name + * @param value the value + */ public void setVoteDelayDaily(String siteName, boolean value) { set(siteName, "VoteDelayDaily", value); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/GUI.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/GUI.java index 9f703311d..28235ee52 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/GUI.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/GUI.java @@ -21,6 +21,9 @@ import lombok.Getter; +/** + * GUI configuration. + */ public class GUI extends YMLFile { @ConfigDataString(path = "BOOK.VoteURLBookGUI.AlreadyVotedColor") @@ -358,12 +361,23 @@ public class GUI extends YMLFile { @Getter private boolean chestVoteURLViewAllUrlsButtonEnabled = false; + /** + * Constructs a new GUI configuration. + * + * @param plugin the plugin instance + */ public GUI(VotingPluginMain plugin) { super(plugin, new File(plugin.getDataFolder(), "GUI.yml")); setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles()); this.plugin = plugin; } + /** + * Gets the extra items for a chest GUI. + * + * @param gui the GUI name + * @return the extra items + */ public Set getChestGUIExtraItems(String gui) { if (getData().isConfigurationSection("CHEST." + gui + ".ExtraItems")) { return getData().getConfigurationSection("CHEST." + gui + ".ExtraItems").getKeys(false); @@ -371,6 +385,13 @@ public Set getChestGUIExtraItems(String gui) { return new HashSet<>(); } + /** + * Gets an extra item configuration for a chest GUI. + * + * @param gui the GUI name + * @param item the item name + * @return the item configuration + */ public ConfigurationSection getChestGUIExtraItemsItem(String gui, String item) { return getData().getConfigurationSection("CHEST." + gui + ".ExtraItems." + item); } @@ -397,10 +418,23 @@ public ArrayList getChestVoteGUISlotLore(String slot) { return (ArrayList) getData().getList("CHEST.VoteGUI." + slot + ".Item.Lore", new ArrayList<>()); } + /** + * Gets the rewards path for a chest vote GUI slot. + * + * @param slot the slot + * @param lastPath the last path segment + * @return the rewards path + */ public String getChestVoteGUISlotRewardsPath(String slot, String lastPath) { return "CHEST.VoteGUI." + slot + "." + lastPath; } + /** + * Gets the configuration section for a chest vote GUI slot. + * + * @param slot the slot + * @return the configuration section + */ public ConfigurationSection getChestVoteGUISlotSection(String slot) { return getData().getConfigurationSection("CHEST.VoteGUI." + slot + ".Item"); } @@ -415,10 +449,22 @@ public int getChestVoteGUISlotSlot(String slot) { return getData().getInt("CHEST.VoteGUI." + slot + ".Slot", -1); } + /** + * Gets the custom site name display for a vote next GUI. + * + * @param site the site name + * @return the custom display name + */ public String getChestVoteNextCustomSiteNamesDisplays(String site) { return getData().getString("CHEST.VoteNext.CustomSiteNamesDisplays." + site, ""); } + /** + * Gets the total item configuration for a top voter. + * + * @param top the top voter + * @return the item configuration + */ public ConfigurationSection getChestVoteTotalItem(TopVoter top) { switch (top) { case AllTime: @@ -435,6 +481,12 @@ public ConfigurationSection getChestVoteTotalItem(TopVoter top) { } } + /** + * Gets an extra item configuration for a vote URL GUI. + * + * @param item the item name + * @return the item configuration + */ public ConfigurationSection getChestVoteURLExtraItemsItem(String item) { return getData().getConfigurationSection("CHEST.VoteURL.ExtraItems." + item); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ShopFile.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ShopFile.java index 309723628..e48df68f2 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ShopFile.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/ShopFile.java @@ -16,6 +16,9 @@ import lombok.Getter; +/** + * The ShopFile class manages the vote shop configuration. + */ public class ShopFile extends YMLFile { @Getter @@ -68,12 +71,20 @@ public class ShopFile extends YMLFile { @Getter private Set voteShopExtraItems = new HashSet<>(); + /** + * Constructs a new ShopFile. + * + * @param plugin the main plugin instance + */ public ShopFile(VotingPluginMain plugin) { super(plugin, new File(plugin.getDataFolder(), "Shop.yml")); setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles()); this.plugin = plugin; } + /** + * Converts vote shop data from the GUI file to this shop file. + */ public void convertFromGUIFile() { // booleans setValue("VoteShop.Enabled", plugin.getGui().getData().getBoolean("CHEST.VoteShopEnabled")); @@ -97,6 +108,11 @@ public void convertFromGUIFile() { } + /** + * Creates a new shop item with default values. + * + * @param value the shop identifier + */ public void createShop(String value) { ConfigurationSection shopData = getData().createSection("Shop." + value); shopData.set("Identifier_Name", value); @@ -113,26 +129,61 @@ public void createShop(String value) { saveData(); } + /** + * Gets the configuration for a vote shop extra item. + * + * @param item the item identifier + * @return the configuration section + */ public ConfigurationSection getGUIVoteShopExtraItems(String item) { return getData().getConfigurationSection("ExtraItems." + item); } + /** + * Gets the cost of a shop item. + * + * @param identifier the shop identifier + * @return the cost + */ public int getShopIdentifierCost(String identifier) { return getData().getInt("Shop." + identifier + ".Cost"); } + /** + * Gets the identifier name for a shop item. + * + * @param identifier the shop identifier + * @return the identifier name + */ public String getShopIdentifierIdentifierName(String identifier) { return getData().getString("Shop." + identifier + ".Identifier_Name", identifier); } + /** + * Gets the purchase limit for a shop item. + * + * @param identifier the shop identifier + * @return the purchase limit + */ public int getShopIdentifierLimit(String identifier) { return getData().getInt("Shop." + identifier + ".Limit", -1); } + /** + * Gets the rewards path for a shop item. + * + * @param identifier the shop identifier + * @return the rewards path + */ public String getShopIdentifierRewardsPath(String identifier) { return "Shop." + identifier + ".Rewards"; } + /** + * Gets all shop identifiers. + * + * @return the set of shop identifiers + */ public Set getShopIdentifiers() { ConfigurationSection shop = getData().getConfigurationSection("Shop"); if (shop != null) { @@ -141,43 +192,103 @@ public Set getShopIdentifiers() { return new HashSet<>(); } + /** + * Gets the configuration section for a shop item. + * + * @param identifier the shop identifier + * @return the configuration section + */ public ConfigurationSection getShopIdentifierSection(String identifier) { return getData().getConfigurationSection("Shop." + identifier); } + /** + * Checks if the GUI should close on purchase. + * + * @param shop the shop identifier + * @return true if GUI should close + */ public boolean getVoteShopCloseGUI(String shop) { return getData().getBoolean("Shop." + shop + ".CloseGUI", true); } + /** + * Checks if the shop item should be hidden when player has no permission. + * + * @param shop the shop identifier + * @return true if should hide + */ public boolean getVoteShopHideOnNoPermission(String shop) { return getData().getBoolean("Shop." + shop + ".HideOnNoPermission", true); } + /** + * Checks if the shop item is not buyable. + * + * @param shop the shop identifier + * @return true if not buyable + */ public boolean getVoteShopNotBuyable(String shop) { return getData().getBoolean("Shop." + shop + ".NotBuyable", false); } + /** + * Gets the permission required for a shop item. + * + * @param ident the shop identifier + * @return the permission + */ public String getVoteShopPermission(String ident) { return getData().getString("Shop." + ident + ".Permission", ""); } + /** + * Gets the purchase message for a shop item. + * + * @param identifier the shop identifier + * @return the purchase message + */ public String getVoteShopPurchase(String identifier) { return getData().getString("Shop." + identifier + ".PurchaseMessage", plugin.getConfigFile().getFormatShopPurchaseMsg()); } + /** + * Checks if the shop item resets daily. + * + * @param shop the shop identifier + * @return true if resets daily + */ public boolean getVoteShopResetDaily(String shop) { return getData().getBoolean("Shop." + shop + ".Reset.Daily", false); } + /** + * Checks if the shop item resets monthly. + * + * @param shop the shop identifier + * @return true if resets monthly + */ public boolean getVoteShopResetMonthly(String shop) { return getData().getBoolean("Shop." + shop + ".Reset.Monthly", false); } + /** + * Checks if the shop item resets weekly. + * + * @param shop the shop identifier + * @return true if resets weekly + */ public boolean getVoteShopResetWeekly(String shop) { return getData().getBoolean("Shop." + shop + ".Reset.Weekly", false); } + /** + * Checks if the shop item requires purchase confirmation. + * + * @param identifier the shop identifier + * @return true if requires confirmation + */ public boolean isVoteShopRequireConfirmation(String identifier) { return getData().getBoolean("Shop." + identifier + ".RequireConfirmation", isVoteShopRequireConfirmation()); } @@ -192,6 +303,11 @@ public void onFileCreation() { plugin.saveResource("Shop.yml", true); } + /** + * Removes a shop item. + * + * @param value the shop identifier + */ public void removeShop(String value) { getData().set("Shop." + value, null); saveData(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/SpecialRewardsConfig.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/SpecialRewardsConfig.java index ecba5d63e..c0fef827e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/SpecialRewardsConfig.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/config/SpecialRewardsConfig.java @@ -18,6 +18,9 @@ import lombok.Getter; +/** + * The SpecialRewardsConfig class manages special rewards configuration. + */ public class SpecialRewardsConfig extends YMLFile { @Getter @@ -153,16 +156,33 @@ public class SpecialRewardsConfig extends YMLFile { @Getter private Set weeklyPossibleRewardPlaces = new HashSet<>(); + /** + * Constructs a new SpecialRewardsConfig. + * + * @param plugin the main plugin instance + */ public SpecialRewardsConfig(VotingPluginMain plugin) { super(plugin, new File(plugin.getDataFolder(), "SpecialRewards.yml")); setIgnoreCase(plugin.getConfigFile().isCaseInsensitiveYMLFiles()); this.plugin = plugin; } + /** + * Gets the rewards path for a daily award. + * + * @param path the award path + * @return the daily award rewards path + */ public String getDailyAwardRewardsPath(String path) { return "DailyAwards." + path + ".Rewards"; } + /** + * Gets the rewards path for a monthly award. + * + * @param path the award path + * @return the monthly award rewards path + */ public String getMonthlyAwardRewardsPath(String path) { return "MonthlyAwards." + path + ".Rewards"; } @@ -180,6 +200,12 @@ public Set getMonthlyPossibleRewardPlaces() { } } + /** + * Gets the increase votes required with the old typo field. + * + * @return the increase votes required + * @deprecated Use getVotePartyIncreaseVotesRequired instead + */ public int getVotePartyIncreaseVotesRequiredWithTypo() { int increase = getVotePartyIncreaseVotesRequired(); if (increase > 0) { @@ -188,14 +214,34 @@ public int getVotePartyIncreaseVotesRequiredWithTypo() { return getVotePartyIncreaseVotesRquired(); } + /** + * Checks if a vote streak reward is enabled. + * + * @param type the streak type + * @param s the streak value + * @return true if enabled + */ public boolean getVoteStreakRewardEnabled(String type, String s) { return getData().getBoolean("VoteStreak." + type + "." + s + ".Enabled"); } + /** + * Gets the rewards path for a vote streak. + * + * @param type the streak type + * @param string the streak value + * @return the vote streak rewards path + */ public String getVoteStreakRewardsPath(String type, String string) { return "VoteStreak." + type + "." + string + ".Rewards"; } + /** + * Gets all vote streak values for a type. + * + * @param type the streak type + * @return the set of vote streak values + */ public Set getVoteStreakVotes(String type) { try { Set set = getData().getConfigurationSection("VoteStreak." + type).getKeys(false); @@ -208,6 +254,12 @@ public Set getVoteStreakVotes(String type) { } } + /** + * Gets the rewards path for a weekly award. + * + * @param path the award path + * @return the weekly award rewards path + */ public String getWeeklyAwardRewardsPath(String path) { return "WeeklyAwards." + path + ".Rewards"; } @@ -222,11 +274,21 @@ public void onFileCreation() { plugin.saveResource("SpecialRewards.yml", true); } + /** + * Removes a vote milestone. + * + * @param votes the milestone votes value + */ public void removeVoteMilestone(String votes) { getData().set("VoteMilestones." + votes, null); saveData(); } + /** + * Sets a vote milestone with default values. + * + * @param intValue the milestone votes value + */ public void setVoteMilestone(int intValue) { getData().set("VoteMilestones." + intValue + ".Enabled", true); getData().set("VoteMilestones." + intValue + ".Rewards.Messages.Player", diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/cooldown/CoolDownCheck.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/cooldown/CoolDownCheck.java index 664f3c85b..de0140bc0 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/cooldown/CoolDownCheck.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/cooldown/CoolDownCheck.java @@ -28,6 +28,9 @@ import lombok.Getter; +/** + * Manages cooldown checks for vote rewards. + */ public class CoolDownCheck implements Listener { private final VotingPluginMain plugin; @@ -40,6 +43,11 @@ public class CoolDownCheck implements Listener { private volatile boolean cooldownCheckEnabled = false; + /** + * Constructs a new cooldown check manager. + * + * @param plugin the plugin instance + */ public CoolDownCheck(VotingPluginMain plugin) { this.plugin = plugin; @@ -49,6 +57,11 @@ public CoolDownCheck(VotingPluginMain plugin) { this.timer = exec; } + /** + * Checks the cooldown for a player by UUID. + * + * @param uuid the player UUID + */ public void check(UUID uuid) { VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(uuid); if (!user.isOnline()) { @@ -57,6 +70,9 @@ public void check(UUID uuid) { check(user); } + /** + * Shuts down the cooldown check timer. + */ public void shutdown() { timer.shutdownNow(); @@ -75,6 +91,11 @@ public void shutdown() { allSiteTasks.clear(); } + /** + * Checks the cooldown for a user. + * + * @param user the voting plugin user + */ public synchronized void check(VotingPluginUser user) { if (!user.getCoolDownCheck()) { return; @@ -99,6 +120,8 @@ public synchronized void check(VotingPluginUser user) { /** * Check ONLY a specific votesite for all users (uses streaming keys/cols). + * + * @param site the vote site to check */ public void checkAllVoteSite(VoteSite site) { if (site == null) { @@ -133,12 +156,20 @@ public void checkAllVoteSite(VoteSite site) { + " (processed: " + count + ")")); } + /** + * Checks if cooldown check is enabled. + */ public void checkEnabled() { cooldownCheckEnabled = !plugin.getConfigFile().isDisableCoolDownCheck() && plugin.getRewardHandler().hasRewards(plugin.getSpecialRewardsConfig().getData(), "VoteCoolDownEndedReward"); } + /** + * Checks per-site cooldown for a player by UUID. + * + * @param uuid the player UUID + */ public void checkPerSite(UUID uuid) { VotingPluginUser user = plugin.getVotingPluginUserManager().getVotingPluginUser(uuid); if (!user.isOnline()) { @@ -147,6 +178,11 @@ public void checkPerSite(UUID uuid) { checkPerSite(user); } + /** + * Checks per-site cooldown for a user. + * + * @param user the voting plugin user + */ public synchronized void checkPerSite(VotingPluginUser user) { if (!plugin.getConfigFile().isPerSiteCoolDownEvents()) { return; @@ -203,6 +239,9 @@ private void checkPerSite(VoteSite site, VotingPluginUser user) { } } + /** + * Loads the cooldown check system. + */ public void load() { plugin.addUserStartup(new UserStartup() { @@ -221,12 +260,22 @@ public void onStartUp(AdvancedCoreUser advancedcoreUser) { }); } + /** + * Handles the cooldown end event. + * + * @param event the cooldown end event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCoolDownEnd(PlayerVoteCoolDownEndEvent event) { plugin.getRewardHandler().giveReward(event.getPlayer(), plugin.getSpecialRewardsConfig().getData(), "VoteCoolDownEndedReward", new RewardOptions()); } + /** + * Handles the per-site cooldown end event. + * + * @param event the per-site cooldown end event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCoolDownEnd(PlayerVoteSiteCoolDownEndEvent event) { plugin.getRewardHandler().giveReward(event.getPlayer(), event.getSite().getSiteData(), "CoolDownEndRewards", @@ -234,6 +283,12 @@ public void onCoolDownEnd(PlayerVoteSiteCoolDownEndEvent event) { .addPlaceholder("url", event.getSite().getVoteURL(false))); } + /** + * Schedules a cooldown check for a user. + * + * @param user the voting plugin user + * @param force whether to force the schedule + */ public void schedule(VotingPluginUser user, boolean force) { if (user.getSitesVotedOn() <= 0 && !force) { return; @@ -262,6 +317,12 @@ public void schedule(VotingPluginUser user, boolean force) { }); } + /** + * Schedules per-site cooldown checks for a user. + * + * @param user the voting plugin user + * @param force whether to force the schedule + */ public void schedulePerSite(VotingPluginUser user, boolean force) { if (!plugin.getConfigFile().isPerSiteCoolDownEvents()) { return; @@ -303,6 +364,12 @@ public void schedulePerSite(VotingPluginUser user, boolean force) { }); } + /** + * Handles a vote event for cooldown scheduling. + * + * @param user the voting plugin user + * @param site the vote site + */ public void vote(VotingPluginUser user, VoteSite site) { if (cooldownCheckEnabled) { schedule(user, true); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/data/ServerData.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/data/ServerData.java index 47f9ab3e3..a93b90649 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/data/ServerData.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/data/ServerData.java @@ -26,10 +26,20 @@ public class ServerData { private VotingPluginMain plugin = VotingPluginMain.plugin; + /** + * Constructs a new ServerData. + * + * @param plugin the main plugin instance + */ public ServerData(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Adds an auto-cached placeholder. + * + * @param placeholder the placeholder to add + */ public void addAutoCachedPlaceholder(String placeholder) { List p = getAutoCachedPlaceholder(); @@ -39,6 +49,11 @@ public void addAutoCachedPlaceholder(String placeholder) { } } + /** + * Adds a service site to the list. + * + * @param site the service site to add + */ public synchronized void addServiceSite(String site) { ArrayList l = getServiceSites(); if (!getServiceSites().contains(site)) { @@ -69,6 +84,12 @@ public void addSign(Location location, String data, int position) { getSignSkullLocation("" + count), getSignData("" + count), getSignPosition("" + count))); } + /** + * Adds a timed vote to the cache. + * + * @param num the vote number + * @param vote the vote time queue entry + */ public void addTimeVoted(int num, VoteTimeQueue vote) { getData().set("TimedVoteCache." + num + ".Name", vote.getName()); getData().set("TimedVoteCache." + num + ".Service", vote.getService()); @@ -76,23 +97,46 @@ public void addTimeVoted(int num, VoteTimeQueue vote) { saveData(); } + /** + * Adds a vote shop purchase for the specified identifier. + * + * @param ident the vote shop identifier + */ public void addVoteShopPurchase(String ident) { setVoteShopPurchases(ident, (getVoteShopPurchases(ident) + 1)); } + /** + * Clears the timed vote cache. + */ public void clearTimedVoteCache() { getData().set("TimedVoteCache", null); saveData(); } + /** + * Gets the auto cached placeholders. + * + * @return the auto cached placeholder list + */ public List getAutoCachedPlaceholder() { return getData().getStringList("AutoCachePlaceholders"); } + /** + * Gets the current bungee vote party count. + * + * @return the bungee vote party current count + */ public int getBungeeVotePartyCurrent() { return getData().getInt("BungeeVotePartyCurrent"); } + /** + * Gets the required votes for bungee vote party. + * + * @return the bungee vote party required votes + */ public int getBungeeVotePartyRequired() { return getData().getInt("BungeeVotePartyRequired"); } @@ -111,10 +155,20 @@ public ConfigurationSection getData() { return data; } + /** + * Gets the list of disabled reminders. + * + * @return the disabled reminders + */ public List getDisabledReminders() { return getData().getStringList("DisabledReminders"); } + /** + * Gets the service sites list. + * + * @return the service sites + */ @SuppressWarnings("unchecked") public ArrayList getServiceSites() { return (ArrayList) getData().getList("ServiceSites", new ArrayList<>()); @@ -180,6 +234,11 @@ public Location getSignSkullLocation(String sign) { getData().getDouble("Signs." + sign + ".Skull.Z")); } + /** + * Gets the timed vote cache keys. + * + * @return the timed vote cache keys + */ public Set getTimedVoteCacheKeys() { if (getData().isConfigurationSection("TimedVoteCache")) { return getData().getConfigurationSection("TimedVoteCache").getKeys(false); @@ -187,18 +246,40 @@ public Set getTimedVoteCacheKeys() { return new HashSet<>(); } + /** + * Gets the timed vote cache section for the given number. + * + * @param num the cache entry number + * @return the timed vote cache section + */ public ConfigurationSection getTimedVoteCacheSection(String num) { return getData().getConfigurationSection("TimedVoteCache." + num); } + /** + * Gets the extra required votes for vote party. + * + * @return the vote party extra required votes + */ public int getVotePartyExtraRequired() { return getData().getInt("VotePartyExtraRequired", 0); } + /** + * Gets the number of purchases for a vote shop item. + * + * @param ident the vote shop identifier + * @return the vote shop purchases + */ public int getVoteShopPurchases(String ident) { return getData().getInt("VoteShopPurchases." + ident); } + /** + * Checks if the last vote party was on the same day. + * + * @return true if same day + */ public boolean isLastVotePartySameDay() { int num = getData().getInt("LastVoteParty", 0); if (num == plugin.getTimeChecker().getTime().getDayOfYear()) { @@ -207,6 +288,11 @@ public boolean isLastVotePartySameDay() { return false; } + /** + * Checks if the last vote party was in the same week. + * + * @return true if same week + */ public boolean isLastVotePartySameWeek() { int num = getData().getInt("LastVotePartyWeek", -1); if (num == plugin.getTimeChecker().getTime().get(WeekFields.of(Locale.getDefault()).weekOfYear()) @@ -216,6 +302,11 @@ public boolean isLastVotePartySameWeek() { return false; } + /** + * Checks if the vote shop has been converted. + * + * @return true if converted + */ public boolean isVoteShopConverted() { return getData().getBoolean("VoteShopConverted"); } @@ -245,10 +336,22 @@ public void reloadData() { plugin.getServerDataFile().reloadData(); } + /** + * Gets the Discord message ID for the top voter. + * + * @param top the top voter type + * @return the top voter message ID + */ public long getTopVoterMessageId(TopVoter top) { return getData().getLong("DiscordSRV.TopVoterMessageId." + top.toString(), 0); } + /** + * Sets the Discord message ID for the top voter. + * + * @param top the top voter type + * @param messageId the message ID + */ public void setTopVoterMessageId(TopVoter top, long messageId) { getData().set("DiscordSRV.TopVoterMessageId." + top.toString(), messageId); saveData(); @@ -281,6 +384,11 @@ public synchronized void saveData() { plugin.getServerDataFile().saveData(); } + /** + * Saves the disabled reminders list. + * + * @param disabledReminders the list of UUIDs with disabled reminders + */ public void saveDisabledReminders(ArrayList disabledReminders) { ArrayList uuids = new ArrayList<>(); for (UUID uuid : disabledReminders) { @@ -290,31 +398,65 @@ public void saveDisabledReminders(ArrayList disabledReminders) { saveData(); } + /** + * Sets the auto cached placeholders. + * + * @param placeholders the list of placeholders + */ public void setAutoCachedPlaceholder(List placeholders) { getData().set("AutoCachePlaceholders", placeholders); saveData(); } + /** + * Sets the current bungee vote party count. + * + * @param current the current vote count + */ public void setBungeeVotePartyCurrent(int current) { getData().set("BungeeVotePartyCurrent", current); saveData(); } + /** + * Sets the required votes for bungee vote party. + * + * @param required the required vote count + */ public void setBungeeVotePartyRequired(int required) { getData().set("BungeeVotePartyRequired", required); saveData(); } + /** + * Sets the service sites list. + * + * @param list the service sites list + */ public void setServiceSites(ArrayList list) { getData().set("ServiceSites", list); saveData(); } + /** + * Sets the vote shop converted status. + * + * @param value the converted status + */ public void setShopConverted(boolean value) { getData().set("VoteShopConverted", value); saveData(); } + /** + * Sets sign data. + * + * @param count the sign count + * @param location the sign location + * @param skullLocation the skull location + * @param data the sign data + * @param position the sign position + */ public void setSign(String count, Location location, Location skullLocation, String data, int position) { getData().set("Signs." + count + ".World", location.getWorld().getName()); @@ -332,6 +474,12 @@ public void setSign(String count, Location location, Location skullLocation, Str saveData(); } + /** + * Sets the skull location for a sign. + * + * @param count the sign count + * @param skullLocation the skull location + */ public void setSkullLocation(String count, Location skullLocation) { if (skullLocation != null) { getData().set("Signs." + count + ".Skull.World", skullLocation.getWorld().getName()); @@ -349,27 +497,47 @@ public void setVersion() { saveData(); } + /** + * Sets the extra required votes for vote party. + * + * @param value the extra required votes + */ public void setVotePartyExtraRequired(int value) { getData().set("VotePartyExtraRequired", value); saveData(); } + /** + * Sets the number of purchases for a vote shop item. + * + * @param ident the vote shop identifier + * @param amount the purchase amount + */ public void setVoteShopPurchases(String ident, int amount) { getData().set("VoteShopPurchases." + ident, amount); saveData(); } + /** + * Updates the last vote party timestamp to today. + */ public void updateLastVoteParty() { getData().set("LastVoteParty", plugin.getTimeChecker().getTime().getDayOfYear()); saveData(); } + /** + * Updates the last vote party week timestamp to this week. + */ public void updateLastVotePartyWeek() { getData().set("LastVotePartyWeek", plugin.getTimeChecker().getTime().get(WeekFields.of(Locale.getDefault()).weekOfYear())); saveData(); } + /** + * Updates placeholders to lowercase format. + */ public void updatePlaceholders() { boolean data = getData().getBoolean("AutoCacheUpdated", false); if (!data) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/discord/DiscordHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/discord/DiscordHandler.java index 4e8be12fd..0915cc17f 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/discord/DiscordHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/discord/DiscordHandler.java @@ -28,6 +28,9 @@ import github.scarsz.discordsrv.util.DiscordUtil; import lombok.Getter; +/** + * Handler for Discord integration. + */ public class DiscordHandler { private final VotingPluginMain plugin; @@ -35,6 +38,11 @@ public class DiscordHandler { private final HashMap topVoterMessageIds = new HashMap(); private final AtomicBoolean discordReady = new AtomicBoolean(false); + /** + * Constructs a new Discord handler. + * + * @param plugin the plugin instance + */ public DiscordHandler(VotingPluginMain plugin) { this.plugin = plugin; for (TopVoter top : TopVoter.values()) { @@ -101,7 +109,11 @@ public void onFinish() { } - /** Fired once JDA is fully initialized */ + /** + * Fired once JDA is fully initialized. + * + * @param event the Discord ready event + */ @Subscribe public void onDiscordReady(DiscordReadyEvent event) { discordReady.set(true); @@ -126,6 +138,11 @@ public void updateDiscordLeaderboard() { } } + /** + * Updates the top voter message ID for the specified top voter. + * + * @param top the top voter + */ public void updateTopVoterMessageId(TopVoter top) { plugin.extraDebug("Updating Discord Top Voter message for: " + top); @@ -188,6 +205,12 @@ public void updateTopVoterMessageId(TopVoter top) { } } + /** + * Sends a reward message to a Discord channel. + * + * @param message the message to send + * @param channelId the Discord channel ID + */ public void sendRewardMessage(String message, String channelId) { TextChannel channel = DiscordUtil.getJda().getTextChannelById(channelId); if (channel != null) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerPostVoteEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerPostVoteEvent.java index 64587a8b1..7379cd196 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerPostVoteEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerPostVoteEvent.java @@ -81,6 +81,20 @@ public static HandlerList getHandlerList() { @Setter private UUID voteUUID; + /** + * Constructs a new PlayerPostVoteEvent. + * + * @param voteSite the vote site + * @param user the voting plugin user + * @param realVote whether this is a real vote + * @param forceBungee whether to force Bungee processing + * @param voteTime the vote timestamp + * @param cached whether the vote was cached + * @param service the service name + * @param uuid the player UUID + * @param playerName the player name + * @param voteUUID the vote UUID + */ public PlayerPostVoteEvent(VoteSite voteSite, VotingPluginUser user, boolean realVote, boolean forceBungee, long voteTime, boolean cached, String service, UUID uuid, String playerName, UUID voteUUID) { super(true); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerReceivePointsEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerReceivePointsEvent.java index 3123b5a8b..42e1284b3 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerReceivePointsEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerReceivePointsEvent.java @@ -42,6 +42,12 @@ public static HandlerList getHandlerList() { @Setter private String serviceSite = ""; + /** + * Constructs a new PlayerReceivePointsEvent. + * + * @param user the voting plugin user + * @param points the points received + */ public PlayerReceivePointsEvent(VotingPluginUser user, int points) { super(true); this.player = user; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerSpecialRewardEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerSpecialRewardEvent.java index bee995612..d39b80d4c 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerSpecialRewardEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerSpecialRewardEvent.java @@ -44,6 +44,13 @@ public static HandlerList getHandlerList() { @Setter private UUID voteUUID; + /** + * Constructs a new PlayerSpecialRewardEvent. + * + * @param user the voting plugin user + * @param type the special reward type + * @param voteUUID the vote UUID + */ public PlayerSpecialRewardEvent(VotingPluginUser user, SpecialRewardType type, UUID voteUUID) { super(true); this.type = type; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteCoolDownEndEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteCoolDownEndEvent.java index ab633733a..d43d06d71 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteCoolDownEndEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteCoolDownEndEvent.java @@ -34,6 +34,11 @@ public static HandlerList getHandlerList() { @Setter private VotingPluginUser player; + /** + * Constructs a new PlayerVoteCoolDownEndEvent. + * + * @param user the voting plugin user + */ public PlayerVoteCoolDownEndEvent(VotingPluginUser user) { super(true); player = user; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteEvent.java index 603720350..209fa68bb 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteEvent.java @@ -84,6 +84,14 @@ public static HandlerList getHandlerList() { @Setter private int voteNumber = 1; + /** + * Constructs a new PlayerVoteEvent. + * + * @param voteSite the vote site + * @param voteUsername the username of the voter + * @param serviceSite the service site name + * @param realVote whether this is a real vote + */ public PlayerVoteEvent(VoteSite voteSite, String voteUsername, String serviceSite, boolean realVote) { super(true); this.player = voteUsername; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteSiteCoolDownEndEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteSiteCoolDownEndEvent.java index cffdbb29b..11b514993 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteSiteCoolDownEndEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/PlayerVoteSiteCoolDownEndEvent.java @@ -39,6 +39,12 @@ public static HandlerList getHandlerList() { @Setter private VoteSite site; + /** + * Constructs a new PlayerVoteSiteCoolDownEndEvent. + * + * @param user the voting plugin user + * @param site the vote site + */ public PlayerVoteSiteCoolDownEndEvent(VotingPluginUser user, VoteSite site) { super(true); player = user; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/SpecialRewardType.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/SpecialRewardType.java index c1d6aeb4d..06f89ee16 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/SpecialRewardType.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/SpecialRewardType.java @@ -2,14 +2,34 @@ import lombok.Getter; +/** + * Enumeration for different special reward types. + */ public enum SpecialRewardType { + /** @deprecated All site reward. */ @Deprecated - ALLSITE, @Deprecated - CUMMULATIVE, @Deprecated - FIRSTVOTE, @Deprecated - FIRSTVOTETODAY, @Deprecated - MILESTONE, VOTESTREAK, @Deprecated - ALMOSTALLSITES, TOPVOTER, VOTESTREAKS; + ALLSITE, + /** @deprecated Cumulative reward. */ + @Deprecated + CUMMULATIVE, + /** @deprecated First vote reward. */ + @Deprecated + FIRSTVOTE, + /** @deprecated First vote today reward. */ + @Deprecated + FIRSTVOTETODAY, + /** @deprecated Milestone reward. */ + @Deprecated + MILESTONE, + /** Vote streak reward. */ + VOTESTREAK, + /** @deprecated Almost all sites reward. */ + @Deprecated + ALMOSTALLSITES, + /** Top voter reward. */ + TOPVOTER, + /** Vote streaks reward. */ + VOTESTREAKS; @Getter private int amount = -1; @@ -17,11 +37,23 @@ public enum SpecialRewardType { @Getter private String type = ""; + /** + * Sets the amount for this special reward. + * + * @param num the amount + * @return this special reward type + */ public SpecialRewardType setAmount(int num) { amount = num; return this; } + /** + * Sets the type for this special reward. + * + * @param type the type + * @return this special reward type + */ public SpecialRewardType setType(String type) { this.type = type; return this; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VoteMilestoneRewardEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VoteMilestoneRewardEvent.java index 42921ab97..ed2049e7c 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VoteMilestoneRewardEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VoteMilestoneRewardEvent.java @@ -62,38 +62,83 @@ public VoteMilestoneRewardEvent(VotingPluginUser user, VoteMilestone milestone, } } + /** + * Gets the voting plugin user associated with this event. + * + * @return the voting plugin user + */ public VotingPluginUser getUser() { return user; } + /** + * Gets the player UUID. + * + * @return the player UUID + */ public UUID getUuid() { return uuid; } + /** + * Gets the player name. + * + * @return the player name + */ public String getPlayerName() { return playerName; } + /** + * Gets the milestone that triggered this event. + * + * @return milestone instance + */ public VoteMilestone getMilestone() { return milestone; } + /** + * Gets the milestone ID. + * + * @return milestone id string + */ public String getMilestoneId() { return milestone == null ? null : milestone.getId(); } + /** + * Gets the value that triggered the milestone. + * + * @return the milestone value + */ public long getValue() { return value; } + /** + * Gets the group ID used for selection. + * + * @return group id string + */ public String getGroupId() { return groupId; } + /** + * Gets the configuration path for the rewards. + * + * @return the reward path + */ public String getRewardPath() { return rewardPath; } + /** + * Gets the placeholders map for this milestone reward. + * + * @return map of placeholder names to values + */ public Map getPlaceholders() { return placeholders; } @@ -103,6 +148,11 @@ public HandlerList getHandlers() { return HANDLERS; } + /** + * Gets the handler list for this event. + * + * @return handler list + */ public static HandlerList getHandlerList() { return HANDLERS; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VotePartyEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VotePartyEvent.java index bdf8a63e6..76778dc05 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VotePartyEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/events/VotePartyEvent.java @@ -28,6 +28,9 @@ public static HandlerList getHandlerList() { @Setter private boolean cancelled; + /** + * Constructs a new VotePartyEvent. + */ public VotePartyEvent() { super(true); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/BungeeVotifierEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/BungeeVotifierEvent.java index 83dda125d..5a0035b57 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/BungeeVotifierEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/BungeeVotifierEvent.java @@ -5,7 +5,16 @@ import com.vexsoftware.votifier.model.Vote; import com.vexsoftware.votifier.model.VotifierEvent; +/** + * Handler for triggering Bungee Votifier events. + */ public class BungeeVotifierEvent { + /** + * Sends a Votifier event for a player vote. + * + * @param plugin the main plugin instance + * @param event the player vote event + */ public void send(VotingPluginMain plugin, PlayerVoteEvent event) { plugin.debug("Triggering vote event"); plugin.getBukkitScheduler().runTask(plugin, new Runnable() { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/PlayerJoinEvent.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/PlayerJoinEvent.java index a7237dcd3..8d0ca4f2d 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/PlayerJoinEvent.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/listeners/PlayerJoinEvent.java @@ -84,6 +84,11 @@ public void onPlayerLogin(AdvancedCoreLoginEvent event) { } } + /** + * Handles player quit events. + * + * @param event the player quit event + */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerQuit(PlayerQuitEvent event) { if (plugin == null || !plugin.isEnabled() || event == null) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/MVdWPlaceholders.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/MVdWPlaceholders.java index 417a0ddcb..2f68ca7dd 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/MVdWPlaceholders.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/MVdWPlaceholders.java @@ -29,6 +29,9 @@ public MVdWPlaceholders(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Loads MVdW placeholders if the MVdWPlaceholderAPI plugin is enabled. + */ public void loadMVdWPlaceholders() { if (Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) { // The plugin is enabled diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceHolders.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceHolders.java index 8bd1dea53..e1089585a 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceHolders.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceHolders.java @@ -57,11 +57,18 @@ public class PlaceHolders { @Getter private PlaceholderCacheLevel cacheLevel; + /** + * Constructor for PlaceHolders. + * @param plugin the voting plugin instance + */ public PlaceHolders(VotingPluginMain plugin) { this.plugin = plugin; cacheLevel = plugin.getConfigFile().getPlaceholderCacheLevel(); } + /** + * Check for placeholders that need caching. + */ public void checkNonCachedPlaceholders() { while (!placeholdersToSetCacheOn.isEmpty()) { String toCache = placeholdersToSetCacheOn.poll().toLowerCase(); @@ -89,10 +96,23 @@ public void checkNonCachedPlaceholders() { } } + /** + * Get placeholder value for offline player. + * @param p the offline player + * @param identifier the placeholder identifier + * @return the placeholder value + */ public String getPlaceHolder(OfflinePlayer p, String identifier) { return getPlaceHolder(p, identifier, true); } + /** + * Get placeholder value for offline player with javascript support. + * @param p the offline player + * @param identifier1 the placeholder identifier + * @param javascript enable javascript processing + * @return the placeholder value + */ public String getPlaceHolder(OfflinePlayer p, String identifier1, boolean javascript) { boolean forceProcess = false; boolean useCache = true; @@ -128,6 +148,12 @@ public String getPlaceHolder(OfflinePlayer p, String identifier1, boolean javasc } + /** + * Get placeholder value for online player. + * @param p the player + * @param identifier the placeholder identifier + * @return the placeholder value + */ public String getPlaceHolder(Player p, String identifier) { if (plugin.getConfigFile().isUseJavascriptPlaceholders()) { identifier = PlaceholderUtils.replaceJavascript(p, identifier); @@ -135,6 +161,15 @@ public String getPlaceHolder(Player p, String identifier) { return getPlaceHolder(p, identifier, false); } + /** + * Get placeholder value with options. + * @param p the offline player + * @param identifier the placeholder identifier + * @param javascript enable javascript processing + * @param forceProcess force processing of placeholder + * @param useCache use cached value if available + * @return the placeholder value + */ public String getPlaceholderValue(OfflinePlayer p, String identifier, boolean javascript, boolean forceProcess, boolean useCache) { if (plugin.getConfigFile().isUseJavascriptPlaceholders() && javascript && p != null) { @@ -264,6 +299,9 @@ public String getPlaceholderValue(OfflinePlayer p, String identifier, boolean ja return "Not a valid placeholder"; } + /** + * Load all placeholders. + */ public void load() { placeholders.clear(); nonPlayerPlaceholders.clear(); @@ -1168,6 +1206,9 @@ public void onChange(AdvancedCoreUser user, String... keys) { }); } + /** + * Handle bungee vote party update. + */ public void onBungeeVotePartyUpdate() { /* * for (NonPlayerPlaceHolder placeholder : @@ -1178,6 +1219,10 @@ public void onBungeeVotePartyUpdate() { */ } + /** + * Handle player logout. + * @param user the voting plugin user + */ public void onLogout(VotingPluginUser user) { if (plugin.getPlaceholders().getCacheLevel().onlineOnly()) { for (PlaceHolder placeholder : placeholders) { @@ -1188,6 +1233,9 @@ public void onLogout(VotingPluginUser user) { } } + /** + * Update all placeholders. + */ public void onUpdate() { checkNonCachedPlaceholders(); for (Player p : Bukkit.getOnlinePlayers()) { @@ -1204,6 +1252,11 @@ public void onUpdate() { } + /** + * Update placeholders for specific user. + * @param user the voting plugin user + * @param login whether this is a login update + */ public void onUpdate(VotingPluginUser user, boolean login) { for (PlaceHolder placeholder : placeholders) { if (placeholder.isUsesCache()) { @@ -1233,6 +1286,9 @@ public void onUpdate(VotingPluginUser user, boolean login) { } } + /** + * Handle vote party update. + */ public void onVotePartyUpdate() { /* * for (NonPlayerPlaceHolder placeholder : @@ -1243,6 +1299,9 @@ public void onVotePartyUpdate() { */ } + /** + * Reload placeholders. + */ public void reload() { cacheLevel = plugin.getConfigFile().getPlaceholderCacheLevel(); onUpdate(); @@ -1253,6 +1312,10 @@ public void reload() { } } + /** + * Schedule placeholder check for user. + * @param user the voting plugin user + */ public void schedulePlaceholderCheck(VotingPluginUser user) { plugin.getTimer().execute(new Runnable() { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceholderCacheLevel.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceholderCacheLevel.java index 471fba4bd..4e8ab373b 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceholderCacheLevel.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/placeholders/PlaceholderCacheLevel.java @@ -1,8 +1,25 @@ package com.bencodez.votingplugin.placeholders; +/** + * Enum for placeholder cache levels. + */ public enum PlaceholderCacheLevel { - NONE, SPECIFIC, AUTO, AUTOALL, SPECIFICALL; + /** No caching. */ + NONE, + /** Specific placeholders cached. */ + SPECIFIC, + /** Auto-cache for online players. */ + AUTO, + /** Auto-cache for all players. */ + AUTOALL, + /** Specific cache for all players. */ + SPECIFICALL; + /** + * Get cache level from string. + * @param str the string to parse + * @return the cache level + */ public static PlaceholderCacheLevel getCache(String str) { for (PlaceholderCacheLevel v : PlaceholderCacheLevel.values()) { if (v.toString().equalsIgnoreCase(str)) { @@ -12,6 +29,10 @@ public static PlaceholderCacheLevel getCache(String str) { return AUTO; } + /** + * Check if cache is for online players only. + * @return true if online only + */ public boolean onlineOnly() { if ((this == AUTOALL) || (this == SPECIFICALL)) { return false; @@ -19,6 +40,10 @@ public boolean onlineOnly() { return true; } + /** + * Check if caching should be enabled. + * @return true if should cache + */ public boolean shouldCache() { switch (this) { case AUTO: @@ -36,6 +61,10 @@ public boolean shouldCache() { } } + /** + * Check if cache should always be used. + * @return true if cache always + */ public boolean isCacheAlways() { if ((this == AUTOALL) || (this == SPECIFICALL)) { return true; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/BungeeMethod.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/BungeeMethod.java index 07df760f4..23181537b 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/BungeeMethod.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/BungeeMethod.java @@ -1,12 +1,35 @@ package com.bencodez.votingplugin.proxy; +/** + * Enumeration of available Bungee connection methods. + */ public enum BungeeMethod { - MYSQL, PLUGINMESSAGING, SOCKETS, REDIS, MQTT; + /** MySQL database connection. */ + MYSQL, + /** Plugin messaging channel. */ + PLUGINMESSAGING, + /** Socket connection. */ + SOCKETS, + /** Redis connection. */ + REDIS, + /** MQTT message broker. */ + MQTT; + /** + * Checks if this method requires a player to be online. + * + * @return true if player must be online + */ public boolean requiresPlayerOnline() { return this == PLUGINMESSAGING; } + /** + * Gets a BungeeMethod by name. + * + * @param str the method name + * @return the matching BungeeMethod, or PLUGINMESSAGING if not found + */ public static BungeeMethod getByName(String str) { for (BungeeMethod method : values()) { if (method.toString().equalsIgnoreCase(str)) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/OfflineBungeeVote.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/OfflineBungeeVote.java index 55f29d39f..00226300e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/OfflineBungeeVote.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/OfflineBungeeVote.java @@ -5,6 +5,9 @@ import lombok.Getter; import lombok.Setter; +/** + * Represents an offline bungee vote. + */ public class OfflineBungeeVote { @Getter @@ -23,6 +26,16 @@ public class OfflineBungeeVote { @Getter private UUID voteId; + /** + * Constructor with UUID voteId. + * @param voteId the vote ID + * @param playerName the player name + * @param uuid the player UUID + * @param service the vote service + * @param time the vote time + * @param realVote whether this is a real vote + * @param text additional text + */ public OfflineBungeeVote(UUID voteId, String playerName, String uuid, String service, long time, boolean realVote, String text) { this.playerName = playerName; @@ -34,6 +47,16 @@ public OfflineBungeeVote(UUID voteId, String playerName, String uuid, String ser this.voteId = voteId; } + /** + * Constructor with String voteId. + * @param voteId the vote ID as string + * @param playerName the player name + * @param uuid the player UUID + * @param service the vote service + * @param time the vote time + * @param realVote whether this is a real vote + * @param text additional text + */ public OfflineBungeeVote(String voteId, String playerName, String uuid, String service, long time, boolean realVote, String text) { this.playerName = playerName; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/ProxyMysqlUserTable.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/ProxyMysqlUserTable.java index cb0c63f74..df53f8171 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/ProxyMysqlUserTable.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/ProxyMysqlUserTable.java @@ -22,6 +22,9 @@ import com.bencodez.simpleapi.sql.mysql.config.MysqlConfig; import com.bencodez.simpleapi.sql.mysql.queries.Query; +/** + * Proxy MySQL user table for managing voting plugin user data. + */ public abstract class ProxyMysqlUserTable extends AbstractSqlTable { // Keep this so existing callers relying on getName() still work @@ -69,10 +72,20 @@ public String buildCreateTableSql(DbType dbType) { // Keep these existing abstract methods for compatibility with your old // subclasses + /** + * Debug log for SQL exceptions. + * @param e the SQL exception + */ public abstract void debug(SQLException e); // ---- Constructors ---- + /** + * Constructor with new MySQL connection. + * @param tableName the table name + * @param config the MySQL configuration + * @param debug enable debug mode + */ public ProxyMysqlUserTable(String tableName, MysqlConfig config, boolean debug) { super(tableName, config, debug); @@ -90,6 +103,9 @@ public ProxyMysqlUserTable(String tableName, MysqlConfig config, boolean debug) /** * Use an already-connected pool (shared). + * @param tableName the table name + * @param existingMysql existing MySQL connection + * @param debug enable debug mode */ public ProxyMysqlUserTable(String tableName, MySQL existingMysql, boolean debug) { super(tableName, existingMysql, debug); @@ -102,12 +118,17 @@ public ProxyMysqlUserTable(String tableName, MySQL existingMysql, boolean debug) // ---- Backwards-compatible API ---- + /** + * Get table name. + * @return the table name + */ public String getName() { return name; } /** * Keep old method name and behavior. + * @return set of UUIDs */ public Set getUuids() { return getPrimaryKeys(); @@ -115,24 +136,37 @@ public Set getUuids() { /** * Keep old behavior: query uuids fresh. + * @return list of UUIDs from database */ public ArrayList getUuidsQuery() { return new ArrayList<>(getPrimaryKeysQuery()); } + /** + * Load data from database. + */ public void loadData() { // old name -> new behavior loadBasicCaches(); } + /** + * Clear cache. + */ public void clearCache() { clearCacheBasic(); } + /** + * Clear basic cache. + */ public void clearCacheBasic() { clearCaches(); } + /** + * Shutdown and close connections. + */ public void shutdown() { close(); } @@ -144,10 +178,18 @@ public boolean containsKeyQuery(String index) { // ---- Required old utility methods (kept) ---- + /** + * Get columns from query. + * @return list of column names + */ public ArrayList getColumnsQueury() { return new ArrayList<>(getColumnsQuery()); } + /** + * Get rows with player names from query. + * @return list of columns with player names + */ public ArrayList getRowsNameQuery() { ArrayList result = new ArrayList<>(); checkColumn("PlayerName", DataType.STRING); @@ -166,6 +208,10 @@ public ArrayList getRowsNameQuery() { return result; } + /** + * Get player names from query. + * @return list of player names + */ public ArrayList getNamesQuery() { ArrayList names = new ArrayList<>(); checkColumn("PlayerName", DataType.STRING); @@ -184,6 +230,10 @@ public ArrayList getNamesQuery() { return names; } + /** + * Get all rows from query. + * @return list of columns with UUID data + */ public ArrayList getRowsQuery() { ArrayList result = new ArrayList<>(); String sqlStr = "SELECT " + qi("uuid") + " FROM " + qi(getTableName()) + ";"; @@ -202,6 +252,10 @@ public ArrayList getRowsQuery() { return result; } + /** + * Get UUID to name mapping from query. + * @return map of UUID to player name + */ public ConcurrentHashMap getRowsUUIDNameQuery() { ConcurrentHashMap uuidNames = new ConcurrentHashMap<>(); @@ -230,6 +284,11 @@ public ConcurrentHashMap getRowsUUIDNameQuery() { return uuidNames; } + /** + * Get UUID by player name. + * @param playerName the player name + * @return the UUID or null if not found + */ public String getUUID(String playerName) { checkColumn("PlayerName", DataType.STRING); @@ -255,6 +314,11 @@ public String getUUID(String playerName) { return null; } + /** + * Get exact match query. + * @param column the column to match + * @return list of matching columns + */ public ArrayList getExactQuery(Column column) { ArrayList result = new ArrayList<>(); @@ -298,16 +362,32 @@ public ArrayList getExactQuery(Column column) { return result; } + /** + * Check if column is integer type. + * @param key the column name + * @return true if integer column + */ public boolean isIntColumn(String key) { return intColumns.contains(key); } // ---- INSERT/UPDATE/WIPE (kept similar to your existing behavior) ---- + /** + * Insert a value. + * @param index the UUID + * @param column the column name + * @param value the value to insert + */ public void insert(String index, String column, DataValue value) { insertQuery(index, Arrays.asList(new Column(column, value))); } + /** + * Insert multiple columns. + * @param index the UUID + * @param cols the columns to insert + */ public void insertQuery(String index, List cols) { for (Column c : cols) { checkColumn(c.getName(), c.getDataType()); @@ -380,6 +460,11 @@ public void insertQuery(String index, List cols) { } } + /** + * Update multiple columns. + * @param index the UUID + * @param cols the columns to update + */ public void update(String index, List cols) { for (Column col : cols) { checkColumn(col.getName(), col.getDataType()); @@ -439,6 +524,12 @@ private void bindValue(PreparedStatement ps, int index, Column col) throws SQLEx ps.setString(index, v == null ? null : v.toString()); } + /** + * Update a single column value. + * @param index the UUID + * @param column the column name + * @param value the value to update + */ public void update(String index, String column, DataValue value) { checkColumn(column, value.getType()); @@ -471,6 +562,11 @@ public void update(String index, String column, DataValue value) { } } + /** + * Wipe all data from a column. + * @param columnName the column name + * @param dataType the data type + */ public void wipeColumnData(String columnName, DataType dataType) { checkColumn(columnName, dataType); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/VotingPluginProxyConfig.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/VotingPluginProxyConfig.java index f0b0ebcd2..d4dc84bdb 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/VotingPluginProxyConfig.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/VotingPluginProxyConfig.java @@ -5,8 +5,16 @@ import java.util.List; import java.util.Map; +/** + * Configuration interface for proxy server integration. + */ public interface VotingPluginProxyConfig { + /** + * Gets whether proxy broadcast is enabled. + * + * @return true if proxy broadcast is enabled + */ default boolean getProxyBroadcastEnabled() { return false; } @@ -15,6 +23,8 @@ default boolean getProxyBroadcastEnabled() { * Routing scope mode. * * Expected values: PLAYER_SERVER | ALL_SERVERS | SERVERS | ALL_EXCEPT + * + * @return the scope mode */ default String getProxyBroadcastScopeMode() { return "ALL_SERVERS"; @@ -22,6 +32,8 @@ default String getProxyBroadcastScopeMode() { /** * Optional server list used by scope modes SERVERS and ALL_EXCEPT. + * + * @return the list of scope servers */ default List getProxyBroadcastScopeServers() { return Collections.emptyList(); @@ -31,6 +43,8 @@ default List getProxyBroadcastScopeServers() { * What to do when the voting player is offline and scope is PLAYER_SERVER. * * Expected values: NONE | QUEUE | FORWARD + * + * @return the offline mode */ default String getProxyBroadcastOfflineMode() { return "QUEUE"; @@ -41,169 +55,574 @@ default String getProxyBroadcastOfflineMode() { * PLAYER_SERVER. * * Ignored when Scope.Mode is ALL_SERVERS or ALL_EXCEPT. + * + * @return the list of offline forward servers */ default List getProxyBroadcastOfflineForwardServers() { return Collections.emptyList(); } + /** + * Gets whether unjoined players are allowed. + * + * @return true if unjoined players are allowed + */ public boolean getAllowUnJoined(); + /** + * Gets the Bedrock player prefix. + * + * @return the Bedrock player prefix + */ public String getBedrockPlayerPrefix(); + /** + * Gets the list of blocked servers. + * + * @return the list of blocked servers + */ public List getBlockedServers(); + /** + * Gets the Bungee host. + * + * @return the Bungee host + */ public String getBungeeHost(); + /** + * Gets whether Bungee manages totals. + * + * @return true if Bungee manages totals + */ public boolean getBungeeManageTotals(); + /** + * Gets the Bungee method. + * + * @return the Bungee method + */ public String getBungeeMethod(); + /** + * Gets the Bungee port. + * + * @return the Bungee port + */ public int getBungeePort(); + /** + * Gets the plugin message channel. + * + * @return the plugin message channel + */ public String getPluginMessageChannel(); + /** + * Gets whether plugin message encryption is enabled. + * + * @return true if plugin message encryption is enabled + */ public boolean getPluginMessageEncryption(); + /** + * Gets whether debug mode is enabled. + * + * @return true if debug mode is enabled + */ public boolean getDebug(); + /** + * Gets whether vote cache uses MySQL. + * + * @return true if vote cache uses MySQL + */ public boolean getVoteCacheUseMySQL(); + /** + * Gets whether vote cache uses main MySQL. + * + * @return true if vote cache uses main MySQL + */ public boolean getVoteCacheUseMainMySQL(); + /** + * Gets whether non-voted cache uses MySQL. + * + * @return true if non-voted cache uses MySQL + */ public boolean getNonVotedCacheUseMySQL(); + /** + * Gets whether non-voted cache uses main MySQL. + * + * @return true if non-voted cache uses main MySQL + */ public boolean getNonVotedCacheUseMainMySQL(); + /** + * Gets the MQTT client ID. + * + * @return the MQTT client ID + */ public String getMqttClientID(); + /** + * Gets the MQTT broker URL. + * + * @return the MQTT broker URL + */ public String getMqttBrokerURL(); + /** + * Gets the MQTT username. + * + * @return the MQTT username + */ public String getMqttUsername(); + /** + * Gets the MQTT password. + * + * @return the MQTT password + */ public String getMqttPassword(); + /** + * Gets the MQTT prefix. + * + * @return the MQTT prefix + */ public String getMqttPrefix(); + /** + * Gets the fallback server. + * + * @return the fallback server + */ public String getFallBack(); + /** + * Gets whether global data is enabled. + * + * @return true if global data is enabled + */ public boolean getGlobalDataEnabled(); + /** + * Gets whether global data uses main MySQL. + * + * @return true if global data uses main MySQL + */ public boolean getGlobalDataUseMainMySQL(); + /** + * Gets the limit for vote points. + * + * @return the vote points limit + */ public int getLimitVotePoints(); + /** + * Gets the maximum amount of votes per day. + * + * @return the maximum votes per day + */ public int getMaxAmountOfVotesPerDay(); + /** + * Gets the multi-proxy method. + * + * @return the multi-proxy method + */ public String getMultiProxyMethod(); + /** + * Gets whether multi-proxy uses one global reward. + * + * @return true if multi-proxy uses one global reward + */ public boolean getMultiProxyOneGlobalReward(); + /** + * Gets the multi-proxy Redis host. + * + * @return the Redis host + */ public String getMultiProxyRedisHost(); + /** + * Gets the multi-proxy Redis password. + * + * @return the Redis password + */ public String getMultiProxyRedisPassword(); + /** + * Gets the multi-proxy Redis port. + * + * @return the Redis port + */ public int getMultiProxyRedisPort(); + /** + * Gets whether multi-proxy Redis uses existing connection. + * + * @return true if using existing connection + */ public boolean getMultiProxyRedisUseExistingConnection(); + /** + * Gets the multi-proxy Redis username. + * + * @return the Redis username + */ public String getMultiProxyRedisUsername(); + /** + * Gets the collection of multi-proxy servers. + * + * @return the collection of server names + */ public Collection getMultiProxyServers(); + /** + * Gets the configuration for a specific multi-proxy server. + * + * @param s the server name + * @return the server configuration as a map + */ public Map getMultiProxyServersConfiguration(String s); + /** + * Gets the multi-proxy socket host. + * + * @return the socket host + */ public String getMultiProxySocketHostHost(); + /** + * Gets the multi-proxy socket host port. + * + * @return the socket port + */ public int getMultiProxySocketHostPort(); + /** + * Gets whether multi-proxy support is enabled. + * + * @return true if multi-proxy support is enabled + */ public boolean getMultiProxySupport(); + /** + * Gets whether online mode is enabled. + * + * @return true if online mode is enabled + */ public boolean getOnlineMode(); + /** + * Gets the points awarded per vote. + * + * @return the points per vote + */ public int getPointsOnVote(); + /** + * Gets whether this is the primary server. + * + * @return true if this is the primary server + */ public boolean getPrimaryServer(); + /** + * Gets the proxy server name. + * + * @return the proxy server name + */ public String getProxyServerName(); + /** + * Gets the list of proxy servers. + * + * @return the list of proxy servers + */ public List getProxyServers(); + /** + * Gets the Redis host. + * + * @return the Redis host + */ public String getRedisHost(); + /** + * Gets the Redis password. + * + * @return the Redis password + */ public String getRedisPassword(); + /** + * Gets the Redis port. + * + * @return the Redis port + */ public int getRedisPort(); + /** + * Gets the Redis database index. + * + * @return the Redis database index + */ public int getRedisDbIndex(); + /** + * Gets the Redis prefix. + * + * @return the Redis prefix + */ public String getRedisPrefix(); + /** + * Gets the Redis username. + * + * @return the Redis username + */ public String getRedisUsername(); + /** + * Gets whether votes should be sent to all servers. + * + * @return true if votes should be sent to all servers + */ public boolean getSendVotesToAllServers(); + /** + * Gets the configuration for a specific Spigot server. + * + * @param s the server name + * @return the server configuration as a map + */ public Map getSpigotServerConfiguration(String s); + /** + * Gets the collection of Spigot servers. + * + * @return the collection of server names + */ public Collection getSpigotServers(); + /** + * Gets whether to store month totals with date. + * + * @return true if month totals are stored with date + */ public boolean getStoreMonthTotalsWithDate(); + /** + * Gets whether time change fail-safe bypass is enabled. + * + * @return true if time change fail-safe bypass is enabled + */ public boolean getTimeChangeFailSafeBypass(); + /** + * Gets the time hour offset. + * + * @return the hour offset + */ public int getTimeHourOffSet(); + /** + * Gets the time week offset. + * + * @return the week offset + */ public int getTimeWeekOffSet(); + /** + * Gets the time zone. + * + * @return the time zone + */ public String getTimeZone(); + /** + * Gets whether to use month date totals as primary total. + * + * @return true if month date totals are used as primary total + */ public boolean getUseMonthDateTotalsAsPrimaryTotal(); + /** + * Gets whether UUID lookup is enabled. + * + * @return true if UUID lookup is enabled + */ public boolean getUUIDLookup(); + /** + * Gets the vote cache time. + * + * @return the vote cache time + */ public int getVoteCacheTime(); + /** + * Gets the vote party broadcast message. + * + * @return the vote party broadcast message + */ public String getVotePartyBroadcast(); + /** + * Gets the list of vote party Bungee commands. + * + * @return the list of commands + */ public List getVotePartyBungeeCommands(); + /** + * Gets whether vote party is enabled. + * + * @return true if vote party is enabled + */ public boolean getVotePartyEnabled(); + /** + * Gets the vote party increase votes required. + * + * @return the increase in votes required + */ public int getVotePartyIncreaseVotesRequired(); + /** + * Gets whether to send vote party to all servers. + * + * @return true if vote party is sent to all servers + */ public boolean getVotePartySendToAllServers(); + /** + * Gets the list of servers to send vote party to. + * + * @return the list of servers + */ public List getVotePartyServersToSend(); + /** + * Gets the number of votes required for vote party. + * + * @return the votes required + */ public int getVotePartyVotesRequired(); + /** + * Gets whether to wait for user to be online. + * + * @return true if waiting for user to be online + */ public boolean getWaitForUserOnline(); + /** + * Gets the list of whitelisted servers. + * + * @return the list of whitelisted servers + */ public List getWhiteListedServers(); + /** + * Gets the collection of sites with vote delay configured. + * + * @return the collection of site names + */ public Collection getWaitUntilVoteDelaySites(); + /** + * Gets the vote delay service for a specific site. + * + * @param site the site name + * @return the service name + */ public String getWaitUntilVoteDelayService(String site); + /** + * Gets the vote delay in seconds for a specific site. + * + * @param site the site name + * @return the vote delay in seconds + */ public int getWaitUntilVoteDelayVoteDelay(String site); + /** + * Gets the minimum vote delay for a specific site. + * + * @param site the site name + * @return the minimum vote delay + */ public int getWaitUntilVoteDelayVoteDelayMin(String site); + /** + * Gets the hourly vote delay for a specific site. + * + * @param site the site name + * @return the hourly vote delay + */ public int getWaitUntilVoteDelayVoteDelayHour(String site); + /** + * Gets whether the vote delay is daily for a specific site. + * + * @param site the site name + * @return true if the delay is daily + */ public boolean getWaitUntilVoteDelayVoteDelayDaily(String site); + /** + * Loads the configuration. + */ public void load(); + /** + * Saves the configuration. + */ public void save(); + /** + * Gets whether vote logging is enabled. + * + * @return true if vote logging is enabled + */ public boolean getVoteLoggingEnabled(); + /** + * Gets the number of days to keep vote logs. + * + * @return the purge days + */ public int getVoteLoggingPurgeDays(); + /** + * Gets whether vote logging uses main MySQL. + * + * @return true if vote logging uses main MySQL + */ public boolean getVoteLoggingUseMainMySQL(); + /** + * Gets whether a database is configured. + * + * @return true if a database is configured + */ public boolean hasDatabaseConfigured(); + /** + * Gets the multi-proxy Redis database index. + * + * @return the database index + */ public int getMultiProxyRedisDbIndex(); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/OfflineMode.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/OfflineMode.java index fcfa5ff79..b68db2d3e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/OfflineMode.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/OfflineMode.java @@ -2,9 +2,23 @@ import java.util.Locale; +/** + * Enum for offline broadcast modes. + */ public enum OfflineMode { - NONE, QUEUE, FORWARD; + /** No offline handling. */ + NONE, + /** Queue votes for offline players. */ + QUEUE, + /** Forward to other servers. */ + FORWARD; + /** + * Parse offline mode from string. + * @param value the string to parse + * @param def the default value + * @return the offline mode + */ public static OfflineMode parse(String value, OfflineMode def) { if (value == null) return def; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ProxyBroadcastDecider.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ProxyBroadcastDecider.java index 207d12dab..27c6e9411 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ProxyBroadcastDecider.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ProxyBroadcastDecider.java @@ -25,6 +25,13 @@ public final class ProxyBroadcastDecider { private final Predicate isServerValid; private final Predicate isBlockedServer; + /** + * Constructor for ProxyBroadcastDecider. + * @param config configuration supplier + * @param allServers all servers supplier + * @param isServerValid server validation predicate + * @param isBlockedServer blocked server predicate + */ public ProxyBroadcastDecider(Supplier config, Supplier> allServers, Predicate isServerValid, @@ -40,6 +47,7 @@ public ProxyBroadcastDecider(Supplier config, * * @param playerOnline whether the voting player is currently online * @param currentPlayerServer the server the player is on (only used when playerOnline=true) + * @return set of target servers */ public Set resolveTargets(boolean playerOnline, String currentPlayerServer) { VotingPluginProxyConfig cfg = config.get(); @@ -89,6 +97,9 @@ public Set resolveTargets(boolean playerOnline, String currentPlayerServ /** * Convenience check for "should this specific server broadcast?" + * @param server the server name + * @param targets the target servers + * @return true if should broadcast */ public boolean shouldBroadcast(String server, Set targets) { return targets != null && server != null && targets.contains(server); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ScopeMode.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ScopeMode.java index 93a77f109..f28f55aeb 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ScopeMode.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/broadcast/ScopeMode.java @@ -26,6 +26,13 @@ public enum ScopeMode { */ ALL_EXCEPT; + /** + * Parses a string value to a ScopeMode with a default fallback. + * + * @param value the string value to parse + * @param def the default value if parsing fails + * @return the parsed ScopeMode or the default + */ public static ScopeMode parse(String value, ScopeMode def) { if (value == null) { return def; @@ -51,6 +58,12 @@ public static ScopeMode parse(String value, ScopeMode def) { } } + /** + * Parses a string value to a ScopeMode with ALL_SERVERS as default. + * + * @param value the string value to parse + * @return the parsed ScopeMode or ALL_SERVERS + */ public static ScopeMode parse(String value) { return parse(value, ALL_SERVERS); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BStatsMetricsBungee.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BStatsMetricsBungee.java index 4f9bbbbd3..c34655b18 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BStatsMetricsBungee.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BStatsMetricsBungee.java @@ -153,6 +153,12 @@ public static abstract class CustomChart { this.chartId = chartId; } + /** + * Gets the chart data to be sent. + * + * @return the chart data as a JsonObject + * @throws Exception if an error occurs while getting the data + */ protected abstract JsonObject getChartData() throws Exception; private JsonObject getRequestJsonObject(Logger logger, boolean logFailedRequests) { @@ -371,7 +377,9 @@ protected JsonObject getChartData() throws Exception { } - // The version of this bStats class + /** + * The version of this bStats class. + */ public static final int B_STATS_VERSION = 1; // A list with all known metrics class objects including this one diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeConfig.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeConfig.java index 4c2e7d9ee..7b35829e1 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeConfig.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeConfig.java @@ -17,15 +17,29 @@ import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.YamlConfiguration; +/** + * Configuration implementation for Bungee proxy server. + */ public class BungeeConfig implements VotingPluginProxyConfig { private VotingPluginBungee bungee; @Getter private Configuration data; + /** + * Constructs a new BungeeConfig. + * + * @param bungee the VotingPluginBungee instance + */ public BungeeConfig(VotingPluginBungee bungee) { this.bungee = bungee; } + /** + * Converts a Configuration object to a Map. + * + * @param config the configuration to convert + * @return a map representation of the configuration + */ public Map configToMap(Configuration config) { Map map = new HashMap<>(); if (config != null) { @@ -478,6 +492,13 @@ public boolean getVoteLoggingUseMainMySQL() { return getData().getBoolean("VoteLogging.UseMainMySQL", true); } + /** + * Returns a configuration section if the key exists, otherwise null. + * + * @param root the root configuration + * @param key the key to check + * @return the configuration section or null + */ public Configuration sectionOrNull(Configuration root, String key) { Object v = root.get(key); return (v instanceof Configuration) ? (Configuration) v : null; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonNonVotedPlayersCache.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonNonVotedPlayersCache.java index c9241a131..1ddb19455 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonNonVotedPlayersCache.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonNonVotedPlayersCache.java @@ -6,9 +6,17 @@ import com.bencodez.simpleapi.file.BungeeJsonFile; import com.bencodez.votingplugin.proxy.cache.nonvoted.INonVotedPlayersStorage; +/** + * JSON file-based storage for non-voted players cache on Bungee. + */ public class BungeeJsonNonVotedPlayersCache extends BungeeJsonFile implements INonVotedPlayersStorage { + /** + * Constructs a new BungeeJsonNonVotedPlayersCache. + * + * @param file the file to store data in + */ public BungeeJsonNonVotedPlayersCache(File file) { super(file); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonVoteCache.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonVoteCache.java index 229bf8f11..41875cbdd 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonVoteCache.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/BungeeJsonVoteCache.java @@ -10,9 +10,17 @@ import com.bencodez.votingplugin.proxy.cache.IVoteCache; import com.bencodez.votingplugin.timequeue.VoteTimeQueue; +/** + * JSON file-based vote cache for Bungee. + */ public class BungeeJsonVoteCache extends BungeeJsonFile implements IVoteCache { private VotingPluginBungee bungee; + /** + * Constructs a new BungeeJsonVoteCache. + * + * @param bungee the bungee plugin instance + */ public BungeeJsonVoteCache(VotingPluginBungee bungee) { super(new File(bungee.getDataFolder(), "votecache.json")); this.bungee = bungee; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VoteEventBungee.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VoteEventBungee.java index f9cc05c84..af28bf93c 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VoteEventBungee.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/bungee/VoteEventBungee.java @@ -5,13 +5,24 @@ import net.md_5.bungee.event.EventHandler; +/** + * Handles vote events from Bungee proxy. + */ public class VoteEventBungee implements net.md_5.bungee.api.plugin.Listener { private VotingPluginBungee plugin; + /** + * Constructs a new Bungee vote event handler. + * @param plugin the plugin instance + */ public VoteEventBungee(VotingPluginBungee plugin) { this.plugin = plugin; } + /** + * Handles Votifier vote events. + * @param event the votifier event + */ @EventHandler public void onVote(VotifierEvent event) { plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ConfigDataNode.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ConfigDataNode.java index 80885babd..6227c668a 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ConfigDataNode.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ConfigDataNode.java @@ -3,10 +3,18 @@ import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; +/** + * ConfigurationNode-based implementation of DataNode. + */ public class ConfigDataNode implements DataNode { private final ConfigurationNode node; + /** + * Constructs a new ConfigDataNode. + * + * @param node the configuration node + */ public ConfigDataNode(ConfigurationNode node) { this.node = node; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/DataNode.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/DataNode.java index 312f98d94..1bb6d73ac 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/DataNode.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/DataNode.java @@ -1,32 +1,117 @@ package com.bencodez.votingplugin.proxy.cache; +/** + * Interface for data node operations. + */ public interface DataNode { + /** + * Checks if this node is an object. + * + * @return true if this is an object node + */ boolean isObject(); + /** + * Checks if this node is an array. + * + * @return true if this is an array node + */ boolean isArray(); + /** + * Checks if this node is a primitive value. + * + * @return true if this is a primitive node + */ boolean isPrimitive(); + /** + * Gets a child node by key. + * + * @param key the key + * @return the child data node + */ DataNode get(String key); + /** + * Gets a child node by index. + * + * @param index the index + * @return the child data node + */ DataNode get(int index); + /** + * Sets a value for a key. + * + * @param key the key + * @param value the value to set + */ void set(String key, Object value); + /** + * Sets a value at an index. + * + * @param index the index + * @param value the value to set + */ void set(int index, Object value); + /** + * Gets the primitive value. + * + * @return the primitive object + */ Object asPrimitive(); + /** + * Gets the value as a string. + * + * @return the string value + */ String asString(); + /** + * Gets the value as a long. + * + * @return the long value + */ long asLong(); + /** + * Checks if a key exists. + * + * @param key the key to check + * @return true if the key exists + */ boolean has(String key); + + /** + * Checks if an index exists. + * + * @param index the index to check + * @return true if the index exists + */ boolean has(int index); + /** + * Gets the value as an int. + * + * @return the int value + */ int asInt(); + /** + * Gets the value as a boolean. + * + * @return the boolean value + */ boolean asBoolean(); - Object toInternal(); // Returns either JsonElement or ConfigurationNode + /** + * Returns the internal representation (JsonElement or ConfigurationNode). + * + * @return the internal object + */ + Object toInternal(); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/GsonDataNode.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/GsonDataNode.java index 617b95667..e13a2e040 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/GsonDataNode.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/GsonDataNode.java @@ -4,10 +4,18 @@ import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; +/** + * Implementation of DataNode using Google Gson. + */ public class GsonDataNode implements DataNode { private final JsonElement element; + /** + * Constructs a new GsonDataNode. + * + * @param element the JSON element to wrap + */ public GsonDataNode(JsonElement element) { this.element = element; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/IVoteCache.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/IVoteCache.java index 9a6bc7faf..739254346 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/IVoteCache.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/IVoteCache.java @@ -5,55 +5,193 @@ import com.bencodez.votingplugin.proxy.OfflineBungeeVote; import com.bencodez.votingplugin.timequeue.VoteTimeQueue; +/** + * Interface for vote caching operations. + */ public interface IVoteCache { + /** + * Adds a timed vote to the cache. + * + * @param num the vote number + * @param voteTimedQueue the vote time queue + */ void addTimedVote(int num, VoteTimeQueue voteTimedQueue); + /** + * Adds a vote for a specific server. + * + * @param server the server name + * @param num the vote number + * @param voteData the vote data + */ void addVote(String server, int num, OfflineBungeeVote voteData); + /** + * Adds a vote for an online player. + * + * @param player the player name + * @param num the vote number + * @param voteData the vote data + */ void addVoteOnline(String player, int num, OfflineBungeeVote voteData); + /** + * Clears all cached data. + */ void clearData(); + /** + * Gets all online votes for a player. + * + * @param name the player name + * @return collection of vote identifiers + */ Collection getOnlineVotes(String name); + /** + * Gets a specific online vote for a player. + * + * @param name the player name + * @param num the vote number + * @return the vote data node + */ DataNode getOnlineVotes(String name, String num); + /** + * Gets all cached players. + * + * @return collection of player names + */ Collection getPlayers(); + /** + * Gets all cached servers. + * + * @return collection of server names + */ Collection getServers(); + /** + * Gets all votes for a server. + * + * @param server the server name + * @return collection of vote identifiers + */ Collection getServerVotes(String server); + /** + * Gets a specific vote for a server. + * + * @param server the server name + * @param num the vote number + * @return the vote data node + */ DataNode getServerVotes(String server, String num); + /** + * Gets all timed vote cache entries. + * + * @return collection of cache keys + */ Collection getTimedVoteCache(); + /** + * Gets a specific timed vote cache entry. + * + * @param key the cache key + * @return the vote data node + */ DataNode getTimedVoteCache(String key); + /** + * Gets the vote party cache for a server. + * + * @param server the server name + * @return the cached vote count + */ int getVotePartyCache(String server); + /** + * Gets the current vote party votes. + * + * @return the current vote count + */ int getVotePartyCurrentVotes(); + /** + * Gets the vote party increase votes required. + * + * @return the increase amount + */ int getVotePartyInreaseVotesRequired(); + /** + * Sets the vote party cache for a server. + * + * @param server the server name + * @param amount the vote amount + */ void setVotePartyCache(String server, int amount); + /** + * Sets the current vote party votes. + * + * @param amount the vote amount + */ void setVotePartyCurrentVotes(int amount); + /** + * Sets the vote party increase votes required. + * + * @param amount the increase amount + */ void setVotePartyInreaseVotesRequired(int amount); + /** + * Saves the cache data. + */ void save(); + /** + * Reloads the cache data. + */ void reload(); + /** + * Removes all online votes for a player. + * + * @param player the player name + */ void removeOnlineVotes(String player); + /** + * Removes all votes for a server. + * + * @param server the server name + */ void removeServerVotes(String server); + /** + * Removes a specific vote for a server. + * + * @param server the server name + * @param uuid the vote UUID + */ void removeServerVote(String server, String uuid); + /** + * Removes a vote from a server. + * + * @param server the server name + * @param vote the vote to remove + */ void removeVote(String server, OfflineBungeeVote vote); + /** + * Removes an online vote. + * + * @param vote the vote to remove + */ void removeOnlineVote(OfflineBungeeVote vote); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyOnlineVoteCacheTable.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyOnlineVoteCacheTable.java index b3957f976..096b69aa2 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyOnlineVoteCacheTable.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyOnlineVoteCacheTable.java @@ -18,6 +18,9 @@ import com.bencodez.simpleapi.sql.mysql.queries.Query; import com.bencodez.votingplugin.proxy.OfflineBungeeVote; +/** + * Table for caching online votes in the proxy. + */ public abstract class ProxyOnlineVoteCacheTable extends AbstractSqlTable { // Prevent repeated startup DDL across multiple instances/subclasses @@ -45,6 +48,10 @@ public String buildCreateTableSql(DbType dbType) { + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"; } + /** + * Removes all votes for a specific UUID. + * @param uuid the player UUID + */ public void removeVotesByUuid(String uuid) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("uuid") + " = ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -71,6 +78,12 @@ public void removeVotesByUuid(String uuid) { @Override public abstract void debug(Throwable t); + /** + * Constructor using an existing MySQL connection. + * @param existingMysql the existing MySQL instance + * @param tablePrefix the table prefix + * @param debug whether debug mode is enabled + */ public ProxyOnlineVoteCacheTable(MySQL existingMysql, String tablePrefix, boolean debug) { super((tablePrefix != null ? tablePrefix : "") + "votingplugin_onlinevotecache", existingMysql, debug); @@ -80,6 +93,11 @@ public ProxyOnlineVoteCacheTable(MySQL existingMysql, String tablePrefix, boolea ensureIndexesOnce(); } + /** + * Constructor using a MySQL configuration. + * @param config the MySQL configuration + * @param debug whether debug mode is enabled + */ public ProxyOnlineVoteCacheTable(MysqlConfig config, boolean debug) { super("votingplugin_onlinevotecache", config, debug); @@ -88,6 +106,11 @@ public ProxyOnlineVoteCacheTable(MysqlConfig config, boolean debug) { ensureIndexesOnce(); } + /** + * Updates the text field of a vote. + * @param vote the vote to update + * @param newText the new text + */ public void updateVoteText(OfflineBungeeVote vote, String newText) { if (vote == null) { return; @@ -181,6 +204,16 @@ private void addVoteIdColumnIfMissing() { // --- INSERT --- + /** + * Inserts a new vote into the cache. + * @param voteId the vote ID + * @param uuid the player UUID + * @param playerName the player name + * @param service the voting service + * @param time the vote time + * @param real whether this is a real vote + * @param text the vote text/payload + */ public void insertVote(UUID voteId, String uuid, String playerName, String service, long time, boolean real, String text) { @@ -218,10 +251,19 @@ public void insertVote(UUID voteId, String uuid, String playerName, String servi // --- GET --- + /** + * Gets all votes from the table. + * @return list of all vote rows + */ public List getAllVotes() { return selectVotes("SELECT * FROM " + qi(getTableName()) + ";", null); } + /** + * Gets all votes for a specific UUID. + * @param uuid the player UUID + * @return list of vote rows + */ public List getVotesByUUID(String uuid) { String sql = "SELECT * FROM " + qi(getTableName()) + " WHERE " + qi("uuid") + " = ?;"; Object param = (getDbType() == DbType.POSTGRESQL) ? UUID.fromString(uuid) : uuid; @@ -230,6 +272,10 @@ public List getVotesByUUID(String uuid) { // --- DELETE --- + /** + * Removes a vote by its ID. + * @param id the vote ID + */ public void removeVoteById(int id) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("id") + " = ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -241,6 +287,10 @@ public void removeVoteById(int id) { } } + /** + * Removes a specific vote. + * @param vote the vote to remove + */ public void removeVote(OfflineBungeeVote vote) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("uuid") + " = ? AND " + qi("service") + " = ? AND " + qi("time") + " = ?;"; @@ -263,6 +313,9 @@ public void removeVote(OfflineBungeeVote vote) { } } + /** + * Clears all votes from the table. + */ public void clearTable() { try { if (getDbType() == DbType.POSTGRESQL) { @@ -302,6 +355,9 @@ private List selectVotes(String sql, Object[] params) { return list; } + /** + * Represents a row in the online vote cache table. + */ public static class VoteRow { private final int id; private final String voteId; @@ -312,6 +368,17 @@ public static class VoteRow { private final boolean realVote; private final String text; + /** + * Constructor for VoteRow. + * @param id the row ID + * @param voteId the vote ID + * @param uuid the player UUID + * @param playerName the player name + * @param service the voting service + * @param time the vote time + * @param realVote whether this is a real vote + * @param text the vote text + */ public VoteRow(int id, String voteId, String uuid, String playerName, String service, long time, boolean realVote, String text) { this.id = id; @@ -324,34 +391,66 @@ public VoteRow(int id, String voteId, String uuid, String playerName, String ser this.text = text; } + /** + * Gets the row ID. + * @return the ID + */ public int getId() { return id; } + /** + * Gets the vote ID. + * @return the vote ID + */ public String getVoteId() { return voteId; } + /** + * Gets the player UUID. + * @return the UUID + */ public String getUuid() { return uuid; } + /** + * Gets the player name. + * @return the player name + */ public String getPlayerName() { return playerName; } + /** + * Gets the voting service. + * @return the service name + */ public String getService() { return service; } + /** + * Gets the vote time. + * @return the time in milliseconds + */ public long getTime() { return time; } + /** + * Checks if this is a real vote. + * @return true if real vote + */ public boolean isRealVote() { return realVote; } + /** + * Gets the vote text. + * @return the text/payload + */ public String getText() { return text; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyTimedVoteCacheTable.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyTimedVoteCacheTable.java index f6b6a8617..1eaf33ba8 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyTimedVoteCacheTable.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyTimedVoteCacheTable.java @@ -13,6 +13,9 @@ import com.bencodez.simpleapi.sql.mysql.config.MysqlConfig; import com.bencodez.simpleapi.sql.mysql.queries.Query; +/** + * Table for caching timed votes in the proxy. + */ public abstract class ProxyTimedVoteCacheTable extends AbstractSqlTable { @Override @@ -49,6 +52,12 @@ public String buildCreateTableSql(DbType dbType) { @Override public abstract void debug(Throwable t); + /** + * Constructor using an existing MySQL connection. + * @param existingMysql the existing MySQL instance + * @param tablePrefix the table prefix + * @param debug whether debug mode is enabled + */ public ProxyTimedVoteCacheTable(MySQL existingMysql, String tablePrefix, boolean debug) { super((tablePrefix != null ? tablePrefix : "") + "votingplugin_timedvotecache", existingMysql, @@ -56,6 +65,11 @@ public ProxyTimedVoteCacheTable(MySQL existingMysql, String tablePrefix, boolean ensureIndexes(); } + /** + * Constructor using a MySQL configuration. + * @param config the MySQL configuration + * @param debug whether debug mode is enabled + */ public ProxyTimedVoteCacheTable(MysqlConfig config, boolean debug) { super("votingplugin_timedvotecache", config, debug); ensureIndexes(); @@ -73,6 +87,12 @@ private void ensureIndexes() { } // --- INSERT --- + /** + * Inserts a timed vote. + * @param playerName the player name + * @param service the voting service + * @param time the vote time + */ public void insertTimedVote(String playerName, String service, long time) { String sql = "INSERT INTO " + qi(getTableName()) + " (" + qi("playerName") + ", " + qi("service") + ", " + qi("time") + ") VALUES (?, ?, ?);"; @@ -88,16 +108,29 @@ public void insertTimedVote(String playerName, String service, long time) { } // --- GET --- + /** + * Gets all timed votes. + * @return list of all timed vote rows + */ public List getAllVotes() { return selectVotes("SELECT * FROM " + qi(getTableName()) + ";", null); } + /** + * Gets expired votes before a given time. + * @param now the current time in milliseconds + * @return list of expired vote rows + */ public List getExpiredVotes(long now) { return selectVotes("SELECT * FROM " + qi(getTableName()) + " WHERE " + qi("time") + " <= ?;", new Object[] { now }); } // --- DELETE --- + /** + * Removes a vote by its ID. + * @param id the vote ID + */ public void removeVoteById(int id) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("id") + " = ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -109,6 +142,10 @@ public void removeVoteById(int id) { } } + /** + * Removes expired votes before a given time. + * @param now the current time in milliseconds + */ public void removeExpiredVotes(long now) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("time") + " <= ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -120,6 +157,9 @@ public void removeExpiredVotes(long now) { } } + /** + * Clears all votes from the table. + */ public void clearTable() { try { if (getDbType() == DbType.POSTGRESQL) { @@ -159,12 +199,22 @@ private List selectVotes(String sql, Object[] params) { return list; } + /** + * Represents a row in the timed vote cache table. + */ public static class TimedVoteRow { private final int id; private final String playerName; private final String service; private final long time; + /** + * Constructor for TimedVoteRow. + * @param id the row ID + * @param playerName the player name + * @param service the voting service + * @param time the vote time + */ public TimedVoteRow(int id, String playerName, String service, long time) { this.id = id; this.playerName = playerName; @@ -172,18 +222,34 @@ public TimedVoteRow(int id, String playerName, String service, long time) { this.time = time; } + /** + * Gets the row ID. + * @return the ID + */ public int getId() { return id; } + /** + * Gets the player name. + * @return the player name + */ public String getPlayerName() { return playerName; } + /** + * Gets the voting service. + * @return the service name + */ public String getService() { return service; } + /** + * Gets the vote time. + * @return the time in milliseconds + */ public long getTime() { return time; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyVoteCacheTable.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyVoteCacheTable.java index b0345c2be..6fbd116f4 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyVoteCacheTable.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/ProxyVoteCacheTable.java @@ -69,6 +69,12 @@ public String buildCreateTableSql(DbType dbType) { return sb.toString(); } + /** + * Updates the text field of a vote. + * @param vote the vote to update + * @param server the server name + * @param newText the new text + */ public void updateVoteText(OfflineBungeeVote vote, String server, String newText) { if (vote == null || server == null) { return; @@ -109,6 +115,12 @@ public void updateVoteText(OfflineBungeeVote vote, String server, String newText // ---- Constructors ---- + /** + * Constructor using an existing MySQL connection. + * @param existingMysql the existing MySQL instance + * @param tablePrefix the table prefix + * @param debug whether debug mode is enabled + */ public ProxyVoteCacheTable(MySQL existingMysql, String tablePrefix, boolean debug) { super((tablePrefix != null ? tablePrefix : "") + "votingplugin_votecache", existingMysql, debug); @@ -118,6 +130,11 @@ public ProxyVoteCacheTable(MySQL existingMysql, String tablePrefix, boolean debu ensureIndexesOnce(); } + /** + * Constructor using a MySQL configuration. + * @param config the MySQL configuration + * @param debug whether debug mode is enabled + */ public ProxyVoteCacheTable(MysqlConfig config, boolean debug) { super("votingplugin_votecache", config, debug); @@ -199,6 +216,17 @@ private void addVoteIdColumnIfMissing() { // ---- INSERT ---- + /** + * Inserts a new vote into the cache. + * @param voteId the vote ID + * @param uuid the player UUID + * @param playerName the player name + * @param service the voting service + * @param time the vote time + * @param real whether this is a real vote + * @param text the vote text/payload + * @param server the server name + */ public void insertVote(UUID voteId, String uuid, String playerName, String service, long time, boolean real, String text, String server) { @@ -237,21 +265,40 @@ public void insertVote(UUID voteId, String uuid, String playerName, String servi // ---- GET ---- + /** + * Gets all votes from the table. + * @return list of all vote rows + */ public List getAllVotes() { return selectVotes("SELECT * FROM " + qi(getTableName()) + ";", null); } + /** + * Gets all votes for a specific server. + * @param server the server name + * @return list of vote rows + */ public List getVotesForServer(String server) { return selectVotes("SELECT * FROM " + qi(getTableName()) + " WHERE " + qi("server") + " = ?;", new Object[] { server }); } + /** + * Gets a vote by its ID. + * @param id the vote ID + * @return the vote row or null if not found + */ public VoteRow getVoteById(int id) { List list = selectVotes("SELECT * FROM " + qi(getTableName()) + " WHERE " + qi("id") + " = ?;", new Object[] { id }); return list.isEmpty() ? null : list.get(0); } + /** + * Gets all votes for a specific UUID. + * @param uuid the player UUID + * @return list of vote rows + */ public List getVotesByUUID(String uuid) { String sql = "SELECT * FROM " + qi(getTableName()) + " WHERE " + qi("uuid") + " = ?;"; Object[] params = (getDbType() == DbType.POSTGRESQL) ? new Object[] { UUID.fromString(uuid) } @@ -259,11 +306,20 @@ public List getVotesByUUID(String uuid) { return selectVotes(sql, params); } + /** + * Gets all votes for a specific player name. + * @param playerName the player name + * @return list of vote rows + */ public List getVotesByPlayerName(String playerName) { return selectVotes("SELECT * FROM " + qi(getTableName()) + " WHERE " + qi("playerName") + " = ?;", new Object[] { playerName }); } + /** + * Gets all distinct servers that have votes. + * @return set of server names + */ public Set getServers() { Set servers = new HashSet<>(); String sql = "SELECT DISTINCT " + qi("server") + " FROM " + qi(getTableName()) + " WHERE " + qi("server") @@ -286,6 +342,10 @@ public Set getServers() { // ---- DELETE ---- + /** + * Removes a vote by its ID. + * @param id the vote ID + */ public void removeVoteById(int id) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("id") + " = ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -297,6 +357,11 @@ public void removeVoteById(int id) { } } + /** + * Removes all votes for a specific server and UUID. + * @param server the server name + * @param uuid the player UUID + */ public void removeVotesByServerAndUUID(String server, String uuid) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("server") + " = ? AND " + qi("uuid") + " = ?;"; @@ -316,6 +381,11 @@ public void removeVotesByServerAndUUID(String server, String uuid) { } } + /** + * Removes a specific vote. + * @param vote the vote to remove + * @param server the server name + */ public void removeVote(OfflineBungeeVote vote, String server) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("uuid") + " = ? AND " + qi("service") + " = ? AND " + qi("time") + " = ? AND " + qi("server") + " = ?;"; @@ -339,6 +409,10 @@ public void removeVote(OfflineBungeeVote vote, String server) { } } + /** + * Removes all votes for a specific server. + * @param server the server name + */ public void removeVotesByServer(String server) { String sql = "DELETE FROM " + qi(getTableName()) + " WHERE " + qi("server") + " = ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -350,6 +424,9 @@ public void removeVotesByServer(String server) { } } + /** + * Clears all votes from the table. + */ public void clearTable() { try { if (getDbType() == DbType.POSTGRESQL) { @@ -390,6 +467,9 @@ private List selectVotes(String sql, Object[] params) { return list; } + /** + * Represents a row in the vote cache table. + */ public static class VoteRow { private final int id; private final String voteId; @@ -401,6 +481,18 @@ public static class VoteRow { private final String text; private final String server; + /** + * Constructor for VoteRow. + * @param id the row ID + * @param voteId the vote ID + * @param uuid the player UUID + * @param playerName the player name + * @param service the voting service + * @param time the vote time + * @param realVote whether this is a real vote + * @param text the vote text + * @param server the server name + */ public VoteRow(int id, String voteId, String uuid, String playerName, String service, long time, boolean realVote, String text, String server) { this.id = id; @@ -414,38 +506,74 @@ public VoteRow(int id, String voteId, String uuid, String playerName, String ser this.server = server; } + /** + * Gets the row ID. + * @return the ID + */ public int getId() { return id; } + /** + * Gets the vote ID. + * @return the vote ID + */ public String getVoteId() { return voteId; } + /** + * Gets the player UUID. + * @return the UUID + */ public String getUuid() { return uuid; } + /** + * Gets the player name. + * @return the player name + */ public String getPlayerName() { return playerName; } + /** + * Gets the voting service. + * @return the service name + */ public String getService() { return service; } + /** + * Gets the vote time. + * @return the time in milliseconds + */ public long getTime() { return time; } + /** + * Checks if this is a real vote. + * @return true if real vote + */ public boolean isRealVote() { return realVote; } + /** + * Gets the vote text. + * @return the text/payload + */ public String getText() { return text; } + /** + * Gets the server name. + * @return the server name + */ public String getServer() { return server; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/VoteCacheHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/VoteCacheHandler.java index 1c1a45f61..9ea53e30a 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/VoteCacheHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/VoteCacheHandler.java @@ -16,8 +16,14 @@ import lombok.Getter; +/** + * Handles caching of votes for proxy servers. + */ public abstract class VoteCacheHandler { + /** + * Queue of timed votes for time change processing. + */ @Getter private Queue timeChangeQueue = new ConcurrentLinkedQueue<>(); @@ -27,10 +33,20 @@ public abstract class VoteCacheHandler { // server based private ConcurrentHashMap> cachedVotes = new ConcurrentHashMap<>(); + /** + * Checks if a server has cached votes. + * @param server the server name + * @return true if the server has cached votes + */ public boolean hasVotes(String server) { return cachedVotes.containsKey(server); } + /** + * Gets cached votes for a server. + * @param server the server name + * @return list of cached votes + */ public ArrayList getVotes(String server) { return cachedVotes.getOrDefault(server, new ArrayList<>()); } @@ -66,6 +82,11 @@ public int getProxyCachedTotal(String uuid) { return total; } + /** + * Adds a vote to the server cache. + * @param server the server name + * @param vote the vote to add + */ public void addServerVote(String server, OfflineBungeeVote vote) { cachedVotes.putIfAbsent(server, new ArrayList<>()); cachedVotes.get(server).add(vote); @@ -82,6 +103,11 @@ public void addServerVote(String server, OfflineBungeeVote vote) { } } + /** + * Removes a vote for a specific player from a server cache. + * @param server the server name + * @param uuid the player UUID + */ public void removeVote(String server, String uuid) { if (cachedVotes.containsKey(server)) { ArrayList votes = cachedVotes.get(server); @@ -96,6 +122,10 @@ public void removeVote(String server, String uuid) { } } + /** + * Removes all cached votes for a server. + * @param server the server name + */ public void removeVotes(String server) { cachedVotes.remove(server); if (useMySQL) { @@ -106,14 +136,29 @@ public void removeVotes(String server) { } } + /** + * Checks if a player has cached online votes. + * @param uuid the player UUID + * @return true if the player has cached online votes + */ public boolean hasOnlineVotes(String uuid) { return cachedOnlineVotes.containsKey(uuid); } + /** + * Gets cached online votes for a player. + * @param uuid the player UUID + * @return list of cached online votes + */ public ArrayList getOnlineVotes(String uuid) { return cachedOnlineVotes.getOrDefault(uuid, new ArrayList<>()); } + /** + * Adds a vote to the online vote cache for a player. + * @param uuid the player UUID + * @param vote the vote to add + */ public void addOnlineVote(String uuid, OfflineBungeeVote vote) { cachedOnlineVotes.putIfAbsent(uuid, new ArrayList<>()); cachedOnlineVotes.get(uuid).add(vote); @@ -130,6 +175,10 @@ public void addOnlineVote(String uuid, OfflineBungeeVote vote) { } } + /** + * Removes all cached online votes for a player. + * @param uuid the player UUID + */ public void removeOnlineVotes(String uuid) { cachedOnlineVotes.remove(uuid); if (useMySQL) { @@ -140,6 +189,10 @@ public void removeOnlineVotes(String uuid) { } } + /** + * Checks and removes expired votes from cache. + * @param voteCacheTime cache time in days + */ public void checkVoteCacheTime(int voteCacheTime) { long cTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); @@ -173,6 +226,9 @@ public void checkVoteCacheTime(int voteCacheTime) { } } + /** + * Saves the vote cache to storage. + */ public void saveVoteCache() { if (useMySQL) { @@ -194,10 +250,17 @@ public void saveVoteCache() { } } + /** + * Adds a timed vote to the cache queue. + * @param vote the timed vote to add + */ public void addTimeVoteToCache(VoteTimeQueue vote) { timeChangeQueue.add(vote); } + /** + * Loads vote cache from storage. + */ public void load() { if (useMySQL) { // Load votes from MySQL @@ -322,16 +385,45 @@ public void load() { private IVoteCache jsonStorage; + /** + * Logs an info message. + * @param msg the message to log + */ public abstract void logInfo1(String msg); + /** + * Logs a severe message. + * @param msg the message to log + */ public abstract void logSevere1(String msg); + /** + * Logs a debug exception. + * @param e the exception to log + */ public abstract void debug1(Exception e); + /** + * Logs a debug throwable. + * @param e the throwable to log + */ public abstract void debug1(Throwable e); + /** + * Logs a debug message. + * @param msg the message to log + */ public abstract void debug1(String msg); + /** + * Constructs a new vote cache handler. + * @param mysqlConfig MySQL configuration + * @param useMySQL whether to use MySQL + * @param useExistingConnection whether to use an existing connection + * @param mysql existing MySQL connection + * @param debug whether debug mode is enabled + * @param jsonStorage JSON storage implementation + */ public VoteCacheHandler(MysqlConfig mysqlConfig, boolean useMySQL, boolean useExistingConnection, MySQL mysql, boolean debug, IVoteCache jsonStorage) { this.useMySQL = useMySQL; @@ -483,10 +575,19 @@ public void debug(String text) { } } + /** + * Gets all servers with cached votes. + * @return array of server names + */ public String[] getCachedVotesServers() { return cachedVotes.keySet().toArray(new String[0]); } + /** + * Removes specific votes from a server cache. + * @param server the server name + * @param removed list of votes to remove + */ public void removeServerVotes(String server, ArrayList removed) { for (OfflineBungeeVote vote : removed) { for (Map.Entry> entry : cachedVotes.entrySet()) { @@ -504,6 +605,10 @@ public void removeServerVotes(String server, ArrayList remove } } + /** + * Removes specific votes from the online vote cache. + * @param removed list of votes to remove + */ public void removeOnlineVotes(ArrayList removed) { for (OfflineBungeeVote vote : removed) { for (Map.Entry> entry : cachedOnlineVotes.entrySet()) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/INonVotedPlayersStorage.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/INonVotedPlayersStorage.java index 3cd1a2945..a1347c209 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/INonVotedPlayersStorage.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/INonVotedPlayersStorage.java @@ -2,42 +2,89 @@ import java.util.function.Consumer; +/** + * Interface for storing non-voted players data. + */ public interface INonVotedPlayersStorage { - /** Insert or update a player entry. */ + /** + * Insert or update a player entry. + * + * @param uuid the player UUID + * @param playerName the player name + * @param lastTime the last recorded time + */ void upsertPlayer(String uuid, String playerName, long lastTime); - /** Returns UUID for the player or empty string if not found. */ + /** + * Returns UUID for the player or empty string if not found. + * + * @param playerName the player name + * @return the UUID or empty string + */ String getUuidByPlayerName(String playerName); - /** Remove a player from storage. */ + /** + * Remove a player from storage. + * + * @param playerName the player name + */ void removeByPlayerName(String playerName); - /** Iterate snapshot of all entries. */ + /** + * Iterate snapshot of all entries. + * + * @param consumer the consumer to process each entry + */ void forEach(Consumer consumer); /** Close resources if needed (MySQL); no-op for JSON. */ void close(); + /** + * Entry for a non-voted player. + */ final class NonVotedPlayerEntry { private final String playerName; private final String uuid; private final long lastTime; + /** + * Constructs a new non-voted player entry. + * + * @param playerName the player name + * @param uuid the UUID + * @param lastTime the last time + */ public NonVotedPlayerEntry(String playerName, String uuid, long lastTime) { this.playerName = playerName; this.uuid = uuid; this.lastTime = lastTime; } + /** + * Gets the player name. + * + * @return the player name + */ public String getPlayerName() { return playerName; } + /** + * Gets the UUID. + * + * @return the UUID + */ public String getUuid() { return uuid; } + /** + * Gets the last time. + * + * @return the last time + */ public long getLastTime() { return lastTime; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/MySQLNonVotedPlayersStorage.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/MySQLNonVotedPlayersStorage.java index 501f8cc41..81c5e78fb 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/MySQLNonVotedPlayersStorage.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/MySQLNonVotedPlayersStorage.java @@ -6,16 +6,30 @@ import com.bencodez.simpleapi.sql.mysql.MySQL; import com.bencodez.simpleapi.sql.mysql.config.MysqlConfig; +/** + * MySQL storage for non-voted players. + */ public abstract class MySQLNonVotedPlayersStorage extends ProxyNonVotedPlayersTable implements INonVotedPlayersStorage { private final boolean ownsConnection; + /** + * Constructor with existing MySQL connection. + * @param existingMysql existing MySQL connection + * @param tablePrefix table prefix + * @param debug enable debug mode + */ public MySQLNonVotedPlayersStorage(MySQL existingMysql, String tablePrefix, boolean debug) { super(existingMysql, tablePrefix, debug); this.ownsConnection = false; } + /** + * Constructor with new MySQL configuration. + * @param config MySQL configuration + * @param debug enable debug mode + */ public MySQLNonVotedPlayersStorage(MysqlConfig config, boolean debug) { super(config, debug); this.ownsConnection = true; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/NonVotedPlayersCache.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/NonVotedPlayersCache.java index b96082fe7..afda7443e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/NonVotedPlayersCache.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/NonVotedPlayersCache.java @@ -6,6 +6,9 @@ import com.bencodez.simpleapi.sql.mysql.MySQL; import com.bencodez.simpleapi.sql.mysql.config.MysqlConfig; +/** + * Cache for players who haven't voted yet. + */ public abstract class NonVotedPlayersCache { private INonVotedPlayersStorage storage; @@ -13,6 +16,15 @@ public abstract class NonVotedPlayersCache { // 5 days in millis (same as your current logic) private static final long MAX_AGE_MILLIS = TimeUnit.DAYS.toMillis(5); + /** + * Constructor for NonVotedPlayersCache. + * @param mysqlConfig MySQL configuration + * @param useMysql whether to use MySQL + * @param useExistingConnection whether to use existing connection + * @param mysql existing MySQL connection + * @param storage storage implementation + * @param debug enable debug mode + */ public NonVotedPlayersCache(MysqlConfig mysqlConfig, boolean useMysql, boolean useExistingConnection, MySQL mysql, INonVotedPlayersStorage storage, boolean debug) { if (useMysql) { @@ -61,10 +73,17 @@ public void debug(Exception e) { } } + /** + * Check if user exists. + * @param uuid the player UUID + * @return true if user exists + */ public abstract boolean userExists(String uuid); /** * Add a player directly by uuid + name, only if they don't already have votes. + * @param uuid the player UUID + * @param playerName the player name */ public void addPlayer(String uuid, String playerName) { if (uuid == null || uuid.isEmpty()) { @@ -76,6 +95,10 @@ public void addPlayer(String uuid, String playerName) { } } + /** + * Get all UUIDs in cache. + * @return set of UUIDs + */ public abstract Set getAllUUIDs(); /** @@ -113,20 +136,41 @@ public void check() { /** * Returns the UUID for a cached non-voted player, or empty string if not * present. + * @param playerName the player name + * @return the UUID or empty string */ public String getUUID(String playerName) { return storage.getUuidByPlayerName(playerName); } + /** + * Close storage connections. + */ public void close() { storage.close(); } + /** + * Log info message. + * @param msg the message + */ public abstract void logInfo1(String msg); + /** + * Log severe message. + * @param msg the message + */ public abstract void logSevere1(String msg); + /** + * Debug log exception. + * @param e the exception + */ public abstract void debug1(Exception e); + /** + * Debug log message. + * @param msg the message + */ public abstract void debug1(String msg); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/ProxyNonVotedPlayersTable.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/ProxyNonVotedPlayersTable.java index a2bd9752a..bb5e073f1 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/ProxyNonVotedPlayersTable.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/cache/nonvoted/ProxyNonVotedPlayersTable.java @@ -13,24 +13,50 @@ import lombok.Getter; +/** + * Table for tracking non-voted players in the proxy cache. + */ public abstract class ProxyNonVotedPlayersTable { @Getter private final MySQL mysql; private final String tableName; + /** + * Logs a severe message. + * @param msg the message to log + */ public abstract void logSevere(String msg); + /** + * Logs an info message. + * @param msg the message to log + */ public abstract void logInfo(String msg); + /** + * Logs debug information for an exception. + * @param e the exception to debug + */ public abstract void debug(Exception e); + /** + * Constructor using an existing MySQL connection. + * @param existingMysql the existing MySQL instance + * @param tablePrefix the table prefix + * @param debug whether debug mode is enabled + */ public ProxyNonVotedPlayersTable(MySQL existingMysql, String tablePrefix, boolean debug) { this.mysql = existingMysql; this.tableName = (tablePrefix != null ? tablePrefix : "") + "votingplugin_nonvotedplayers"; createTableIfNeeded(); } + /** + * Constructor using a MySQL configuration. + * @param config the MySQL configuration + * @param debug whether debug mode is enabled + */ public ProxyNonVotedPlayersTable(MysqlConfig config, boolean debug) { String prefix = config.getTablePrefix() != null ? config.getTablePrefix() : ""; this.tableName = prefix + "votingplugin_nonvotedplayers"; @@ -82,10 +108,20 @@ private void createTableIfNeeded() { } } + /** + * Gets the table name. + * @return the table name + */ public String getTableName() { return tableName; } + /** + * Upsert player record. + * @param uuid the player UUID + * @param playerName the player name + * @param lastTime the last time + */ public void upsertPlayer(String uuid, String playerName, long lastTime) { String sql = "INSERT INTO `" + tableName + "` (uuid, playerName, lastTime) " + "VALUES (?, ?, ?) " + "ON DUPLICATE KEY UPDATE uuid = VALUES(uuid), lastTime = VALUES(lastTime);"; @@ -100,6 +136,11 @@ public void upsertPlayer(String uuid, String playerName, long lastTime) { } } + /** + * Get UUID by player name. + * @param playerName the player name + * @return the UUID or empty string + */ public String getUuidByPlayerName(String playerName) { String sql = "SELECT uuid FROM `" + tableName + "` WHERE playerName = ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -117,6 +158,10 @@ public String getUuidByPlayerName(String playerName) { return ""; } + /** + * Remove player by name. + * @param playerName the player name + */ public void removeByPlayerName(String playerName) { String sql = "DELETE FROM `" + tableName + "` WHERE playerName = ?;"; try (Connection conn = mysql.getConnectionManager().getConnection(); @@ -128,6 +173,10 @@ public void removeByPlayerName(String playerName) { } } + /** + * Gets all rows from the table. + * @return list of all non-voted player rows + */ public List getAllRows() { List list = new ArrayList<>(); String sql = "SELECT id, uuid, playerName, lastTime FROM `" + tableName + "`;"; @@ -144,6 +193,9 @@ public List getAllRows() { return list; } + /** + * Clears all rows from the table. + */ public void clearAll() { try { new Query(mysql, "TRUNCATE TABLE `" + tableName + "`;").executeUpdate(); @@ -152,12 +204,22 @@ public void clearAll() { } } + /** + * Represents a row in the non-voted players table. + */ public static class NonVotedPlayerRow { private final int id; private final String uuid; private final String playerName; private final long lastTime; + /** + * Constructor for NonVotedPlayerRow. + * @param id the row ID + * @param uuid the player UUID + * @param playerName the player name + * @param lastTime the last time + */ public NonVotedPlayerRow(int id, String uuid, String playerName, long lastTime) { this.id = id; this.uuid = uuid; @@ -165,18 +227,34 @@ public NonVotedPlayerRow(int id, String uuid, String playerName, long lastTime) this.lastTime = lastTime; } + /** + * Gets the row ID. + * @return the ID + */ public int getId() { return id; } + /** + * Gets the player UUID. + * @return the UUID + */ public String getUuid() { return uuid; } + /** + * Gets the player name. + * @return the player name + */ public String getPlayerName() { return playerName; } + /** + * Gets the last time. + * @return the last time + */ public long getLastTime() { return lastTime; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyHandler.java index c265ac7b4..752b20ebf 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyHandler.java @@ -19,6 +19,9 @@ import lombok.Getter; +/** + * Abstract handler for multi-proxy support. + */ public abstract class MultiProxyHandler { private HashMap multiproxyClientHandles; private SocketHandler multiproxySocketHandler; @@ -26,13 +29,30 @@ public abstract class MultiProxyHandler { @Getter private RedisHandler multiProxyRedis; + /** + * Constructs a new multi-proxy handler. + */ public MultiProxyHandler() { } + /** + * Adds a non-voted player to the cache. + * + * @param uuid the player UUID + * @param playerName the player name + */ public abstract void addNonVotedPlayerCache(String uuid, String playerName); + /** + * Clears a vote for a player. + * + * @param uuid the player UUID + */ public abstract void clearVote(String uuid); + /** + * Closes the multi-proxy handler. + */ public void close() { if (multiproxySocketHandler != null) { multiproxySocketHandler.closeConnection(); @@ -43,55 +63,185 @@ public void close() { } } + /** + * Gets whether debug mode is enabled. + * + * @return true if debug mode is enabled + */ public abstract boolean getDebug(); + /** + * Gets the encryption handler. + * + * @return the encryption handler + */ public abstract EncryptionHandler getEncryptionHandler(); + /** + * Gets the multi-proxy method. + * + * @return the multi-proxy method + */ public abstract MultiProxyMethod getMultiProxyMethod(); + /** + * Gets the multi-proxy password. + * + * @return the password + */ public abstract String getMultiProxyPassword(); + /** + * Gets the multi-proxy Redis host. + * + * @return the Redis host + */ public abstract String getMultiProxyRedisHost(); + /** + * Gets the multi-proxy Redis port. + * + * @return the Redis port + */ public abstract int getMultiProxyRedisPort(); + /** + * Gets the multi-proxy Redis database index. + * + * @return the database index + */ public abstract int getMultiProxyRedisDbIndex(); + /** + * Gets whether to use an existing Redis connection. + * + * @return true if using existing connection + */ public abstract boolean getMultiProxyRedisUseExistingConnection(); + /** + * Gets the multi-proxy server name. + * + * @return the server name + */ public abstract String getMultiProxyServerName(); + /** + * Gets the multi-proxy servers. + * + * @return the servers + */ public abstract Collection getMultiProxyServers(); + /** + * Gets the configuration for a multi-proxy server. + * + * @param s the server name + * @return the server configuration + */ public abstract MultiProxyServerSocketConfiguration getMultiProxyServersConfiguration(String s); + /** + * Gets the multi-proxy socket host. + * + * @return the socket host + */ public abstract String getMultiProxySocketHostHost(); + /** + * Gets the multi-proxy socket host port. + * + * @return the socket host port + */ public abstract int getMultiProxySocketHostPort(); + /** + * Gets whether multi-proxy support is enabled. + * + * @return true if multi-proxy support is enabled + */ public abstract boolean getMultiProxySupportEnabled(); + /** + * Gets the multi-proxy username. + * + * @return the username + */ public abstract String getMultiProxyUsername(); + /** + * Gets the plugin data folder. + * + * @return the plugin data folder + */ public abstract File getPluginDataFolder(); + /** + * Gets whether this is the primary server. + * + * @return true if this is the primary server + */ public abstract boolean getPrimaryServer(); + /** + * Gets the proxy servers. + * + * @return the proxy servers + */ public abstract List getProxyServers(); + /** + * Gets the Redis handler. + * + * @return the Redis handler + */ public abstract RedisHandler getRedisHandler(); + /** + * Gets the version. + * + * @return the version + */ public abstract String getVersion(); + /** + * Logs an info message. + * + * @param msg the message to log + */ public abstract void logInfo(String msg); + /** + * Runs a task asynchronously. + * + * @param runnable the task to run + */ public abstract void runAsnc(Runnable runnable); + /** + * Sets the encryption handler. + * + * @param encryptionHandler the encryption handler + */ public abstract void setEncryptionHandler(EncryptionHandler encryptionHandler); + /** + * Triggers a vote. + * + * @param player the player name + * @param service the service name + * @param realVote whether this is a real vote + * @param timeQueue whether to queue by time + * @param queueTime the queue time + * @param text the vote totals snapshot + * @param uuid the player UUID + */ public abstract void triggerVote(String player, String service, boolean realVote, boolean timeQueue, long queueTime, VoteTotalsSnapshot text, String uuid); + /** + * Loads multi-proxy support. + */ public void loadMultiProxySupport() { if (!getMultiProxySupportEnabled()) { return; @@ -156,6 +306,12 @@ public void debug(String message) { logInfo("Loaded multi-proxy support: " + getMultiProxyMethod().toString()); } + /** + * Handles player login. + * + * @param uuid the player UUID + * @param playerName the player name + */ public void login(String uuid, String playerName) { if (!getMultiProxySupportEnabled() || getPrimaryServer()) { return; @@ -163,6 +319,12 @@ public void login(String uuid, String playerName) { sendMultiProxyEnvelope(VotingPluginWire.login(playerName, uuid, getMultiProxyServerName())); } + /** + * Sends a clear vote message. + * + * @param uuid the player UUID + * @param playerName the player name + */ public void sendClearVote(String uuid, String playerName) { if (!getMultiProxySupportEnabled()) { return; @@ -170,6 +332,9 @@ public void sendClearVote(String uuid, String playerName) { sendMultiProxyEnvelope(VotingPluginWire.clearVote(uuid, playerName, getMultiProxyServerName())); } + /** + * Sends a status message. + */ public void sendStatus() { if (!getMultiProxySupportEnabled()) { return; @@ -177,6 +342,11 @@ public void sendStatus() { sendMultiProxyEnvelope(VotingPluginWire.status(getMultiProxyServerName())); } + /** + * Sends a multi-proxy envelope. + * + * @param envelope the envelope to send + */ public void sendMultiProxyEnvelope(JsonEnvelope envelope) { if (envelope == null) { return; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyMethod.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyMethod.java index 9f3c58a77..7aa5efb7e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyMethod.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyMethod.java @@ -1,8 +1,20 @@ package com.bencodez.votingplugin.proxy.multiproxy; +/** + * Multi-proxy communication methods. + */ public enum MultiProxyMethod { - SOCKETS, REDIS; + /** Socket-based communication. */ + SOCKETS, + /** Redis-based communication. */ + REDIS; + /** + * Gets the multi-proxy method by name. + * + * @param str the method name + * @return the multi-proxy method + */ public static MultiProxyMethod getByName(String str) { for (MultiProxyMethod method : values()) { if (method.toString().equalsIgnoreCase(str)) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfiguration.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfiguration.java index bec62276b..c6201d385 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfiguration.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfiguration.java @@ -1,9 +1,27 @@ package com.bencodez.votingplugin.proxy.multiproxy; +/** + * Configuration for a multi-proxy server socket. + */ public interface MultiProxyServerSocketConfiguration { + /** + * Gets the host. + * + * @return the host + */ String getHost(); + /** + * Gets the port. + * + * @return the port + */ int getPort(); + /** + * Gets the server name. + * + * @return the server name + */ String getServerName(); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationBungee.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationBungee.java index da3ebb89a..022b49833 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationBungee.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationBungee.java @@ -2,11 +2,19 @@ import java.util.Map; +/** + * Multi-proxy server socket configuration for Bungee. + */ public class MultiProxyServerSocketConfigurationBungee implements MultiProxyServerSocketConfiguration { private String server; private String host = ""; private int port; + /** + * Constructor for Bungee configuration. + * @param s the server name + * @param config the configuration map + */ public MultiProxyServerSocketConfigurationBungee(String s, Map config) { server = s; if (config.containsKey("Host")) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationVelocity.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationVelocity.java index 8862edf92..9997b92bd 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationVelocity.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/multiproxy/MultiProxyServerSocketConfigurationVelocity.java @@ -2,12 +2,20 @@ import org.spongepowered.configurate.ConfigurationNode; +/** + * Multi-proxy server socket configuration for Velocity. + */ public class MultiProxyServerSocketConfigurationVelocity implements MultiProxyServerSocketConfiguration { private String server; private String host; private int port; + /** + * Constructor for Velocity configuration. + * @param s the server name + * @param config the configuration node + */ public MultiProxyServerSocketConfigurationVelocity(String s, ConfigurationNode config) { server = s; host = config.node("Host").getString("0.0.0.0"); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityConfig.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityConfig.java index f8fbb9552..c2e15188b 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityConfig.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityConfig.java @@ -15,8 +15,15 @@ import org.spongepowered.configurate.ConfigurationNode; +/** + * Configuration file handler for Velocity proxy. + */ public class VelocityConfig extends VelocityYMLFile implements VotingPluginProxyConfig { + /** + * Constructs a new Velocity configuration. + * @param file the configuration file + */ public VelocityConfig(File file) { super(file); } @@ -159,6 +166,11 @@ public String getMultiProxyRedisUsername() { return getChildrenAsList(getNode("MultiProxyServers")); } + /** + * Gets children of a configuration node as a list. + * @param config the configuration node + * @return list of child keys + */ public List getChildrenAsList(ConfigurationNode config) { List children = new ArrayList<>(); if (config != null) { @@ -189,6 +201,10 @@ public boolean getMultiProxySupport() { return getBoolean(getNode("MultiProxySupport"), false); } + /** + * Gets the MySQL configuration node. + * @return the MySQL configuration node + */ public ConfigurationNode getMysqlNode() { return getNode("MySQL"); } @@ -283,6 +299,11 @@ public String getMqttPrefix() { return getString(getNode("MQTT", "Prefix"), ""); } + /** + * Converts a configuration node to a map. + * @param config the configuration node + * @return map of configuration values + */ public Map configToMap(ConfigurationNode config) { Map map = new HashMap<>(); if (config != null) { @@ -343,6 +364,10 @@ public int getVotePartyIncreaseVotesRequired() { return getInt(getVotePartyNode().node("IncreaseVotesRequired"), 0); } + /** + * Gets the vote party configuration node. + * @return the vote party configuration node + */ public ConfigurationNode getVotePartyNode() { return getNode("VoteParty"); } @@ -468,6 +493,11 @@ public boolean getVoteLoggingUseMainMySQL() { return getBoolean(getNode("VoteLogging", "UseMainMySQL"), true); } + /** + * Checks if a node is a configuration section. + * @param node the node to check + * @return true if the node is a section + */ private boolean isSection(ConfigurationNode node) { return node != null && node.raw() instanceof Map; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonNonVotedPlayersCache.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonNonVotedPlayersCache.java index 04244d7a0..1bf318b78 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonNonVotedPlayersCache.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonNonVotedPlayersCache.java @@ -6,8 +6,15 @@ import com.bencodez.simpleapi.file.velocity.VelocityJSONFile; import com.bencodez.votingplugin.proxy.cache.nonvoted.INonVotedPlayersStorage; +/** + * JSON-based non-voted players cache for Velocity proxy. + */ public class VelocityJsonNonVotedPlayersCache extends VelocityJSONFile implements INonVotedPlayersStorage { + /** + * Constructs a new Velocity JSON non-voted players cache. + * @param file the file to store cache data + */ public VelocityJsonNonVotedPlayersCache(File file) { super(file); } @@ -49,6 +56,11 @@ public void close() { } + /** + * Sets a value at a specific path. + * @param value the value to set + * @param path the path elements + */ private void setPath(Object value, Object... path) { set(path, value); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonVoteCache.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonVoteCache.java index a5d79c58f..e20b03202 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonVoteCache.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VelocityJsonVoteCache.java @@ -10,8 +10,15 @@ import com.bencodez.votingplugin.proxy.cache.IVoteCache; import com.bencodez.votingplugin.timequeue.VoteTimeQueue; +/** + * JSON-based vote cache implementation for Velocity proxy. + */ public class VelocityJsonVoteCache extends VelocityJSONFile implements IVoteCache { + /** + * Constructs a new Velocity JSON vote cache. + * @param file the file to store cache data + */ public VelocityJsonVoteCache(File file) { super(file); } @@ -219,6 +226,11 @@ public void removeOnlineVote(OfflineBungeeVote vote) { } } + /** + * Sets a value at a specific path. + * @param value the value to set + * @param path the path elements + */ private void setPath(Object value, Object... path) { set(path, value); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VoteEventVelocity.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VoteEventVelocity.java index c978692ef..ad03a27c9 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VoteEventVelocity.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/proxy/velocity/VoteEventVelocity.java @@ -3,13 +3,24 @@ import com.velocitypowered.api.event.Subscribe; import com.vexsoftware.votifier.velocity.event.VotifierEvent; +/** + * Handles vote events from Velocity proxy. + */ public class VoteEventVelocity { private VotingPluginVelocity plugin; + /** + * Constructs a new Velocity vote event handler. + * @param plugin the plugin instance + */ public VoteEventVelocity(VotingPluginVelocity plugin) { this.plugin = plugin; } + /** + * Handles Votifier vote events. + * @param event the votifier event + */ @Subscribe public void onVotifierEvent(VotifierEvent event) { final String serviceSiteVote = event.getVote().getServiceName(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/SignHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/SignHandler.java index 485494efe..2f2780cfe 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/SignHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/SignHandler.java @@ -61,6 +61,16 @@ public class SignHandler { private int votes; + /** + * Constructs a new SignHandler. + * + * @param plugin the main plugin instance + * @param sign the sign identifier + * @param location the sign location + * @param skullLocation the skull location + * @param data the sign data + * @param position the sign position + */ public SignHandler(VotingPluginMain plugin, String sign, Location location, Location skullLocation, String data, int position) { this.plugin = plugin; @@ -157,10 +167,20 @@ public boolean isLocationSame(Location loc) { return loc.equals(getLocation()); } + /** + * Checks if skull location is set. + * + * @return true if skull is set + */ public boolean isSkullSet() { return skullLocation != null; } + /** + * Checks if no player name is available. + * + * @return true if no name available + */ public boolean noNameAvailable() { return playerName.equalsIgnoreCase("No Player") || playerName.equals(""); } @@ -274,6 +294,12 @@ public void run() { }, delay, getLocation()); } + /** + * Updates skulls in the specified region. + * + * @param loc1 the first location + * @param loc2 the second location + */ public void updateSkulls(Location loc1, Location loc2) { if (!NMSManager.getInstance().isVersion("1.12")) { BlockState state = getLocation().getBlock().getState(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/Signs.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/Signs.java index a1397554d..6b1ab8279 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/Signs.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/signs/Signs.java @@ -20,6 +20,11 @@ public class Signs { @Setter private ArrayList signs; + /** + * Constructs a new Signs manager. + * + * @param plugin the main plugin instance + */ public Signs(VotingPluginMain plugin) { this.plugin = plugin; this.signs = new ArrayList<>(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/SpecialRewards.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/SpecialRewards.java index eda7d4f60..54f7f515a 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/SpecialRewards.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/SpecialRewards.java @@ -20,10 +20,24 @@ public class SpecialRewards { private VotingPluginMain plugin; + /** + * Constructs a new SpecialRewards handler. + * + * @param plugin the main plugin instance + */ public SpecialRewards(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Checks and processes vote streak rewards for a user. + * + * @param voteUUID the vote UUID + * @param user the voting user + * @param type the streak type (day/week/month) + * @param forceBungee whether to force bungee mode + * @return true if a reward was given + */ public boolean checkVoteStreak(UUID voteUUID, VotingPluginUser user, String type, boolean forceBungee) { boolean gotReward = false; @@ -79,6 +93,17 @@ public boolean checkVoteStreak(UUID voteUUID, VotingPluginUser user, String type } + /** + * Gives a vote streak reward to a user. + * + * @param voteUUID the vote UUID + * @param user the voting user + * @param online whether the user is online + * @param type the streak type + * @param string the streak value + * @param votes the current streak count + * @param forceBungee whether to force bungee mode + */ public void giveVoteStreakReward(UUID voteUUID, VotingPluginUser user, boolean online, String type, String string, int votes, boolean forceBungee) { PlayerSpecialRewardEvent event = new PlayerSpecialRewardEvent(user, diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/RangeSpec.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/RangeSpec.java index 8963f6fcc..3c6444dae 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/RangeSpec.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/RangeSpec.java @@ -10,16 +10,32 @@ */ public final class RangeSpec { + /** The start value of the range. */ public final long start; + /** The end value of the range. */ public final long end; + /** The step increment for the range. */ public final long step; + /** + * Constructs a new RangeSpec. + * + * @param start the start value + * @param end the end value + * @param step the step increment + */ public RangeSpec(long start, long end, long step) { this.start = start; this.end = end; this.step = step; } + /** + * Attempts to parse a range specification string. + * + * @param s the string to parse + * @return the parsed RangeSpec or null if parsing fails + */ public static RangeSpec tryParse(String s) { // Normalize whitespace String str = s.trim().replaceAll("\\s+", " "); @@ -74,6 +90,11 @@ public static RangeSpec tryParse(String s) { return new RangeSpec(start, end, step); } + /** + * Expands the range into a list of discrete values. + * + * @return the list of values in the range + */ public List expand() { List out = new ArrayList<>(); // Safety: avoid accidental huge expansions diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestone.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestone.java index 1b3512f6e..1509aaa68 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestone.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestone.java @@ -35,6 +35,19 @@ public class VoteMilestone { @Getter private final VoteMilestoneLimit limit; + /** + * Constructs a new VoteMilestone. + * + * @param id milestone id + * @param enabled whether milestone is enabled + * @param total total type to check + * @param atMatcher matcher for specific values (may be null) + * @param every interval for repeating milestone (may be null) + * @param rewardPath path to rewards configuration + * @param groupSelect group selection mode + * @param groupKey group key + * @param limit retrigger limit + */ public VoteMilestone(String id, boolean enabled, VoteMilestoneTotal total, AtMatcher atMatcher, Integer every, String rewardPath, VoteMilestoneGroupSelect groupSelect, String groupKey, VoteMilestoneLimit limit) { this.id = id; @@ -48,14 +61,31 @@ public VoteMilestone(String id, boolean enabled, VoteMilestoneTotal total, AtMat this.limit = (limit == null ? VoteMilestoneLimit.none() : limit); } + /** + * Checks if this milestone has an at matcher for debugging. + * + * @return true if at matcher exists + */ public boolean hasAtMatcherDebug() { return atMatcher != null; } + /** + * Gets debug string representation of the at matcher. + * + * @param maxValues maximum number of values to include + * @return debug string or "none" + */ public String getAtMatcherDebugString(int maxValues) { return atMatcher == null ? "none" : atMatcher.toDebugString(maxValues); } + /** + * Checks if this milestone matches the given total. + * + * @param newTotal total to check against + * @return true if milestone matches + */ public boolean matches(long newTotal) { if (atMatcher != null && atMatcher.matches(newTotal)) { return true; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupParser.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupParser.java index dee66b3c2..cd3446fa1 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupParser.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupParser.java @@ -5,11 +5,20 @@ import org.bukkit.configuration.ConfigurationSection; +/** + * Utility class for parsing vote milestone group configuration. + */ public final class VoteMilestoneGroupParser { private VoteMilestoneGroupParser() { } + /** + * Parses group selection modes from configuration. + * + * @param root root configuration section + * @return map of group id to selection mode + */ public static Map parseGroups(ConfigurationSection root) { HashMap out = new HashMap<>(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupSelect.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupSelect.java index 351cecc32..506eb4a36 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupSelect.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneGroupSelect.java @@ -1,5 +1,8 @@ package com.bencodez.votingplugin.specialrewards.votemilestones; +/** + * Enum for selecting which milestones to trigger when multiple match in a group. + */ public enum VoteMilestoneGroupSelect { /** * Trigger every matching milestone in the group. diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneLimit.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneLimit.java index dcbed57fb..bd27e01a3 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneLimit.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneLimit.java @@ -16,34 +16,88 @@ */ public final class VoteMilestoneLimit { + /** + * Limit types for milestone retriggering. + */ public enum Type { - NONE, WINDOW_DAY, WINDOW_WEEK, WINDOW_MONTH, COOLDOWN + /** + * No limit. + */ + NONE, + /** + * Once per calendar day window. + */ + WINDOW_DAY, + /** + * Once per week window. + */ + WINDOW_WEEK, + /** + * Once per month window. + */ + WINDOW_MONTH, + /** + * Fixed cooldown duration. + */ + COOLDOWN } private final Type type; private final long cooldownMillis; // fixed millis cooldown + /** + * Constructs a new VoteMilestoneLimit. + * + * @param type limit type + * @param cooldownMillis cooldown duration in milliseconds + */ public VoteMilestoneLimit(Type type, long cooldownMillis) { this.type = type == null ? Type.NONE : type; this.cooldownMillis = Math.max(0L, cooldownMillis); } + /** + * Creates a VoteMilestoneLimit with no restrictions. + * + * @return limit with NONE type + */ public static VoteMilestoneLimit none() { return new VoteMilestoneLimit(Type.NONE, 0L); } + /** + * Gets the limit type. + * + * @return limit type + */ public Type getType() { return type; } + /** + * Gets the cooldown duration in milliseconds. + * + * @return cooldown milliseconds + */ public long getCooldownMillis() { return cooldownMillis; } + /** + * Checks if the limit is enabled. + * + * @return true if limit is enabled + */ public boolean isEnabled() { return type != Type.NONE; } + /** + * Parses a VoteMilestoneLimit from configuration. + * + * @param milestoneSection milestone configuration section + * @return parsed limit or none() + */ public static VoteMilestoneLimit fromConfig(ConfigurationSection milestoneSection) { if (milestoneSection == null) { return none(); @@ -114,6 +168,14 @@ private static Type parseType(String raw) { /* ---------------- enforcement ---------------- */ + /** + * Checks if the limit allows retriggering at the given time. + * + * @param lastTriggeredMs last triggered time in milliseconds + * @param nowMs current time in milliseconds + * @param zone time zone for window calculations + * @return true if retriggering is allowed + */ public boolean allows(long lastTriggeredMs, long nowMs, ZoneId zone) { if (type == Type.NONE) { return true; @@ -139,6 +201,12 @@ public boolean allows(long lastTriggeredMs, long nowMs, ZoneId zone) { } } + /** + * Calculates the next allowed trigger time in milliseconds. + * + * @param lastTriggeredMs last triggered time in milliseconds + * @return next allowed time or 0 if not applicable + */ public long nextAllowedMs(long lastTriggeredMs) { if (type != Type.COOLDOWN || lastTriggeredMs <= 0) { return 0L; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneTotal.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneTotal.java index d7f70b91b..5d1ffb0c0 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneTotal.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestoneTotal.java @@ -12,6 +12,7 @@ public enum VoteMilestoneTotal { // ---- Vote totals (TopVoter-based) ---- + /** All-time votes total. */ ALLTIME_VOTES { @Override public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData) { @@ -22,6 +23,7 @@ public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData } }, + /** Daily votes total. */ DAILY_VOTES { @Override public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData) { @@ -32,6 +34,7 @@ public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData } }, + /** Weekly votes total. */ WEEKLY_VOTES { @Override public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData) { @@ -42,6 +45,7 @@ public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData } }, + /** Monthly votes total. */ MONTHLY_VOTES { @Override public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData) { @@ -53,6 +57,7 @@ public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData }, // ---- Global points (single value only) ---- + /** Player points total. */ POINTS { @Override public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData) { @@ -62,6 +67,7 @@ public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData return user.getPoints(); } }, + /** All unique sites voted today. */ ALLSITES_TODAY { @Override public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData) { @@ -69,6 +75,13 @@ public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData } }; + /** + * Gets the value for this total type. + * + * @param user the voting plugin user + * @param bungeeMessageData the bungee message data snapshot + * @return the total value + */ public abstract long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData); /** @@ -76,6 +89,9 @@ public long getValue(VotingPluginUser user, VoteTotalsSnapshot bungeeMessageData * * Supported examples: - ALLTIME_VOTES - AllTime - ALLTIME - Daily / Weekly / * Monthly - Points / VotePoints - Legacy_Milestone_Count + * + * @param input the input string to parse + * @return the parsed VoteMilestoneTotal, or ALLTIME_VOTES as default */ public static VoteMilestoneTotal parse(String input) { if (input == null || input.trim().isEmpty()) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesConfig.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesConfig.java index 958806f1e..2d8082876 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesConfig.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesConfig.java @@ -7,6 +7,9 @@ import com.bencodez.votingplugin.VotingPluginMain; +/** + * Configuration for vote milestones. + */ public class VoteMilestonesConfig { private final Map milestones; @@ -15,10 +18,23 @@ private VoteMilestonesConfig(Map milestones) { this.milestones = milestones; } + /** + * Gets the map of milestones. + * + * @return the milestones map + */ public Map getMilestones() { return milestones; } + /** + * Loads vote milestones configuration from the configuration section. + * + * @param plugin the main plugin instance + * @param manager the vote milestones manager + * @param root the root configuration section + * @return the loaded vote milestones configuration + */ public static VoteMilestonesConfig load(VotingPluginMain plugin, VoteMilestonesManager manager, ConfigurationSection root) { Map out = new LinkedHashMap<>(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesMigrator.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesMigrator.java index 4ac224022..2cb74c81e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesMigrator.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/votemilestones/VoteMilestonesMigrator.java @@ -19,6 +19,15 @@ public final class VoteMilestonesMigrator { private VoteMilestonesMigrator() { } + /** + * Compiles legacy milestone configuration into the new format. + * + * @param root the configuration section containing legacy milestones + * @param totalSites the total number of vote sites + * @param onlyOneCumulative whether only one cumulative milestone should trigger + * @param resetMilestonesMonthly whether milestones reset monthly + * @return map of milestone names to VoteMilestone objects + */ public static Map compileLegacy(ConfigurationSection root, int totalSites, boolean onlyOneCumulative, boolean resetMilestonesMonthly) { Map out = new LinkedHashMap<>(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/voteparty/VoteParty.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/voteparty/VoteParty.java index 087fdfb89..e98633330 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/voteparty/VoteParty.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/specialrewards/voteparty/VoteParty.java @@ -36,10 +36,20 @@ public class VoteParty implements Listener { private VotingPluginMain plugin; + /** + * Constructs a new VoteParty. + * + * @param plugin the main plugin instance + */ public VoteParty(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Adds a vote total for the user. + * + * @param user the voting plugin user + */ public void addTotal(VotingPluginUser user) { setTotalVotes(getTotalVotes() + 1); user.setVotePartyVotes(user.getVotePartyVotes() + 1); @@ -63,6 +73,12 @@ public void addVotePlayer(VotingPluginUser user) { } } + /** + * Checks if vote party requirements are met and triggers if appropriate. + * + * @param user the voting plugin user + * @param forceBungee whether to force Bungee processing + */ public void check(VotingPluginUser user, boolean forceBungee) { if (getTotalVotes() < getVotesRequired()) { plugin.extraDebug("Not enough votes for vote party: " + getTotalVotes() + " / " + getVotesRequired()); @@ -104,6 +120,11 @@ public void check(VotingPluginUser user, boolean forceBungee) { } + /** + * Checks and sends vote reminders if requirements are met. + * + * @param user the voting plugin user + */ public void checkVoteReminder(VotingPluginUser user) { if (!user.isVanished()) { int neededVotes = getNeededVotes(); @@ -162,6 +183,11 @@ public int getNeededVotes() { return neededVotes; } + /** + * Gets a random player name from voted users. + * + * @return random player name or "No Player" if none available + */ public String getRandomPlayerName() { ArrayList allPlayers = new ArrayList<>(); for (Player players : Bukkit.getOnlinePlayers()) { @@ -196,6 +222,11 @@ public List getVotedUsers() { return new ArrayList<>(); } + /** + * Gets the number of votes required for the vote party. + * + * @return votes required including extra requirements + */ public int getVotesRequired() { int required = plugin.getSpecialRewardsConfig().getVotePartyVotesRequired(); int extra = plugin.getServerData().getVotePartyExtraRequired(); @@ -205,6 +236,12 @@ public int getVotesRequired() { return required; } + /** + * Gives vote party reward to a user. + * + * @param user the voting plugin user + * @param useBungee whether to use Bungee processing + */ public void giveReward(VotingPluginUser user, boolean useBungee) { if (plugin.getSpecialRewardsConfig().getVotePartyUserVotesRequired() > 0) { if (user.getVotePartyVotes() < plugin.getSpecialRewardsConfig().getVotePartyUserVotesRequired()) { @@ -214,6 +251,13 @@ public void giveReward(VotingPluginUser user, boolean useBungee) { giveReward(user, user.isOnline(), useBungee); } + /** + * Gives vote party reward to a user with online status. + * + * @param user the voting plugin user + * @param online whether the user is online + * @param useBungee whether to use Bungee processing + */ public void giveReward(VotingPluginUser user, boolean online, boolean useBungee) { new RewardBuilder(plugin.getSpecialRewardsConfig().getData(), plugin.getSpecialRewardsConfig().getVotePartyRewardsPath()).setOnline(online) @@ -222,6 +266,12 @@ public void giveReward(VotingPluginUser user, boolean online, boolean useBungee) .setServer(useBungee).send(user); } + /** + * Gives rewards to all eligible players for the vote party. + * + * @param orgUser the original voting user who triggered the party + * @param forceBungee whether to force Bungee processing + */ public void giveRewards(VotingPluginUser orgUser, boolean forceBungee) { MiscUtils.getInstance().broadcast(plugin.getSpecialRewardsConfig().getVotePartyBroadcast()); @@ -307,6 +357,11 @@ public void run() { reset(false); } + /** + * Handles day change events to reset vote party if configured. + * + * @param event the day change event + */ @EventHandler public void onDayChange(DayChangeEvent event) { if (plugin.getSpecialRewardsConfig().isVotePartyResetEachDay()) { @@ -314,6 +369,11 @@ public void onDayChange(DayChangeEvent event) { } } + /** + * Handles month change events to reset vote party if configured. + * + * @param event the month change event + */ @EventHandler public void onMonthChange(MonthChangeEvent event) { if (plugin.getSpecialRewardsConfig().isVotePartyResetMonthly()) { @@ -325,6 +385,11 @@ public void onMonthChange(MonthChangeEvent event) { } } + /** + * Handles week change events to reset vote party if configured. + * + * @param event the week change event + */ @EventHandler public void onWeekChange(WeekChangeEvent event) { if (plugin.getSpecialRewardsConfig().isVotePartyResetWeekly()) { @@ -336,10 +401,18 @@ public void onWeekChange(WeekChangeEvent event) { } } + /** + * Registers this class as an event listener. + */ public void register() { plugin.getServer().getPluginManager().registerEvents(this, plugin); } + /** + * Resets the vote party state. + * + * @param override whether to override total votes to zero + */ public void reset(boolean override) { if (override) { setTotalVotes(0); @@ -349,6 +422,9 @@ public void reset(boolean override) { } + /** + * Resets the vote party count for all users. + */ public void resetVotePartyCount() { plugin.getUserManager().removeAllKeyValues("VotePartyVotes", DataType.INTEGER); } @@ -373,6 +449,13 @@ public void setVotedUsers(List value) { plugin.getServerData().saveData(); } + /** + * Processes a vote for the vote party system. + * + * @param user the voting plugin user + * @param realVote whether this is a real vote + * @param forceBungee whether to force Bungee processing + */ public synchronized void vote(VotingPluginUser user, boolean realVote, boolean forceBungee) { if (plugin.getSpecialRewardsConfig().isVotePartyEnabled()) { if (plugin.getSpecialRewardsConfig().isVotePartyCountFakeVotes() || realVote) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/timequeue/TimeQueueHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/timequeue/TimeQueueHandler.java index cb70baaa8..f6bd94123 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/timequeue/TimeQueueHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/timequeue/TimeQueueHandler.java @@ -17,22 +17,39 @@ import lombok.Getter; +/** + * The TimeQueueHandler class manages time-based vote queue processing. + */ public class TimeQueueHandler implements Listener { @Getter private Queue timeChangeQueue = new ConcurrentLinkedQueue<>(); private VotingPluginMain plugin; + /** + * Constructs a new TimeQueueHandler. + * + * @param plugin the main plugin instance + */ public TimeQueueHandler(VotingPluginMain plugin) { this.plugin = plugin; load(); } + /** + * Adds a vote to the time change queue. + * + * @param voteUsername the voter username + * @param voteSiteName the vote site name + */ public void addVote(String voteUsername, String voteSiteName) { timeChangeQueue.add(new VoteTimeQueue(voteUsername, voteSiteName, LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())); } + /** + * Loads cached votes from server data and schedules queue processing. + */ public void load() { for (String str : plugin.getServerData().getTimedVoteCacheKeys()) { ConfigurationSection data = plugin.getServerData().getTimedVoteCacheSection(str); @@ -49,6 +66,11 @@ public void run() { }, 120, TimeUnit.SECONDS); } + /** + * Handles date change event and schedules queue processing. + * + * @param event the date changed event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void postTimeChange(DateChangedEvent event) { plugin.getVoteTimer().schedule(new Runnable() { @@ -60,6 +82,9 @@ public void run() { }, 5, TimeUnit.SECONDS); } + /** + * Processes all votes in the queue. + */ public void processQueue() { while (getTimeChangeQueue().size() > 0) { VoteTimeQueue vote = getTimeChangeQueue().remove(); @@ -76,6 +101,9 @@ public void processQueue() { } } + /** + * Saves pending votes to server data. + */ public void save() { if (!timeChangeQueue.isEmpty()) { int num = 0; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoter.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoter.java index c1761302d..1ea9c0a98 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoter.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoter.java @@ -7,9 +7,24 @@ import lombok.Getter; +/** + * Enumeration for different top voter time periods. + */ public enum TopVoter { - AllTime, Monthly, Weekly, Daily; - + /** All time top voters. */ + AllTime, + /** Monthly top voters. */ + Monthly, + /** Weekly top voters. */ + Weekly, + /** Daily top voters. */ + Daily; + + /** + * Gets the default top voter type from configuration. + * + * @return the default top voter type + */ public static TopVoter getDefault() { TopVoter top = getTopVoter(VotingPluginMain.plugin.getConfigFile().getVoteTopDefault()); if (top != null) { @@ -18,6 +33,12 @@ public static TopVoter getDefault() { return AllTime; } + /** + * Gets a top voter type by name. + * + * @param str the name string + * @return the top voter type + */ public static TopVoter getTopVoter(String str) { for (TopVoter value : values()) { if (value.toString().equalsIgnoreCase(str)) { @@ -27,6 +48,12 @@ public static TopVoter getTopVoter(String str) { return AllTime; } + /** + * Converts a TimeType to a TopVoter. + * + * @param type the time type + * @return the corresponding top voter type + */ public static TopVoter of(TimeType type) { switch (type) { case DAY: @@ -40,6 +67,11 @@ public static TopVoter of(TimeType type) { } } + /** + * Gets all top voter types except AllTime. + * + * @return array of top voter types + */ public static TopVoter[] valuesMinusAllTime() { return new TopVoter[] { TopVoter.Daily, TopVoter.Weekly, TopVoter.Monthly }; } @@ -47,6 +79,11 @@ public static TopVoter[] valuesMinusAllTime() { @Getter private ArrayList switchItems = new ArrayList<>(); + /** + * Gets the database column name for this top voter type. + * + * @return the column name + */ public String getColumnName() { switch (this) { case AllTime: @@ -63,6 +100,11 @@ public String getColumnName() { } } + /** + * Gets the last period database column name for this top voter type. + * + * @return the last column name + */ public String getLastColumnName() { switch (this) { case AllTime: @@ -79,6 +121,11 @@ public String getLastColumnName() { } } + /** + * Gets the formatted name for this top voter type. + * + * @return the formatted name + */ public String getName() { if (this.equals(TopVoter.Monthly)) { return VotingPluginMain.plugin.getConfigFile().getFormatTopVoterMonthly(); @@ -93,6 +140,11 @@ public String getName() { } } + /** + * Gets the next top voter type in the cycle. + * + * @return the next top voter type + */ public TopVoter next() { ArrayList list = new ArrayList<>(); if (switchItems != null && !switchItems.isEmpty()) { @@ -124,6 +176,11 @@ public TopVoter next() { return TopVoter.AllTime; } + /** + * Gets the previous top voter type in the cycle. + * + * @return the previous top voter type + */ public TopVoter prev() { ArrayList list = new ArrayList<>(); if (switchItems != null && !switchItems.isEmpty()) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterHandler.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterHandler.java index d8f5a8222..3d02d832a 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterHandler.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterHandler.java @@ -39,14 +39,25 @@ import com.bencodez.votingplugin.VotingPluginMain; import com.bencodez.votingplugin.user.VotingPluginUser; +/** + * Handles top voter rankings and statistics. + */ public class TopVoterHandler implements Listener { private VotingPluginMain plugin; + /** + * Constructs a new top voter handler. + * @param plugin the plugin instance + */ public TopVoterHandler(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Checks if bungee should handle resets. + * @return true if bungee handles resets + */ public boolean bungeeHandleResets() { if (plugin.getBungeeSettings().isUseBungeecoord()) { if (plugin.getBungeeSettings().isGloblalDataEnabled()) { @@ -57,6 +68,11 @@ public boolean bungeeHandleResets() { return false; } + /** + * Gets monthly top voters at a specific time. + * @param atTime the time to check + * @return map of top voters and their vote counts + */ public LinkedHashMap getMonthlyTopVotersAtTime(LocalDateTime atTime) { // int limitSize = plugin.getConfigFile().getMaxiumNumberOfTopVotersToLoad(); @@ -94,10 +110,20 @@ public LinkedHashMap getMonthlyTopVotersAtTime(LocalDat } + /** + * Gets the top voter blacklist. + * @return list of blacklisted players + */ public ArrayList getTopVoterBlackList() { return plugin.getConfigFile().getBlackList(); } + /** + * Gets top voters for a specific month. + * @param month the year-month to check + * @param cols player data columns + * @return map of top voters and their vote counts + */ public LinkedHashMap getTopVotersOfMonth(YearMonth month, HashMap> cols) { @@ -130,6 +156,10 @@ public LinkedHashMap getTopVotersOfMonth(YearMonth mont * @return the string[] */ + /** + * Gets weekly top voters as formatted strings. + * @return array of formatted top voter lines + */ public String[] getTopVotersWeekly() { ArrayList msg = new ArrayList<>(); ArrayList users = plugin.convertSet(plugin.getTopVoter(TopVoter.Weekly).keySet()); @@ -163,6 +193,9 @@ private HashMap handlePlaces(Set places) { return place; } + /** + * Loads last month's top voter data. + */ public void loadLastMonth() { if (!plugin.getGui().isLastMonthGUI()) { return; @@ -203,6 +236,9 @@ public void loadLastMonth() { }); } + /** + * Loads previous month top voters for all configured months. + */ public void loadPreviousMonthTopVoters() { if (!plugin.getConfigFile().isStoreMonthTotalsWithDate()) { return; @@ -331,6 +367,11 @@ public void loadPreviousMonthTopVoters() { }); } + /** + * Handles date change events. + * + * @param event date changed event + */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onDateChanged(DateChangedEvent event) { plugin.setUpdate(true); @@ -343,6 +384,10 @@ public void onDateChanged(DateChangedEvent event) { } } + /** + * Handles day change events. + * @param event the day change event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDayChange(DayChangeEvent event) { synchronized (VotingPluginMain.plugin) { @@ -439,6 +484,10 @@ public void onDayChange(DayChangeEvent event) { } } + /** + * Handles month change events. + * @param event the month change event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onMonthChange(MonthChangeEvent event) { long startTime = System.currentTimeMillis(); @@ -556,6 +605,10 @@ public void onMonthChange(MonthChangeEvent event) { } } + /** + * Handles pre-date change events. + * @param event the pre-date changed event + */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPreDateChanged(PreDateChangedEvent event) { if (event.getTimeType().equals(TimeType.DAY)) { @@ -568,6 +621,11 @@ public void onPreDateChanged(PreDateChangedEvent event) { plugin.update(); } + /** + * Handles week change events. + * + * @param event week change event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onWeekChange(WeekChangeEvent event) { long startTime = System.currentTimeMillis(); @@ -671,18 +729,35 @@ public void onWeekChange(WeekChangeEvent event) { } } + /** + * Registers this handler as a listener. + */ public void register() { plugin.getServer().getPluginManager().registerEvents(this, plugin); } + /** + * Resets vote totals for a specific period. + * @param topVoter the top voter period to reset + */ public void resetTotals(TopVoter topVoter) { plugin.getUserManager().removeAllKeyValues(topVoter.getColumnName(), DataType.INTEGER); } + /** + * Resets vote shop limits for a specific shop. + * @param shopIdent the shop identifier + */ public void resetVoteShopLimit(String shopIdent) { plugin.getUserManager().removeAllKeyValues("VoteShopLimit" + shopIdent, DataType.INTEGER); } + /** + * Sorts top voters by their vote counts. + * @param map the map to sort + * @param order true for ascending order, false for descending + * @return sorted map of top voters + */ public LinkedHashMap sortByValues(LinkedHashMap map, final boolean order) { @@ -716,6 +791,10 @@ public int compare(Entry o1, Entry msg = new ArrayList<>(); @@ -904,11 +980,9 @@ public String[] topVotersAllTime() { } /** - * Top voters daily. - * - * @return the string[] + * Gets daily top voters as formatted strings. + * @return array of formatted top voter lines */ - public String[] topVotersDaily() { ArrayList msg = new ArrayList<>(); ArrayList users = plugin.convertSet(plugin.getTopVoter(TopVoter.Daily).keySet()); @@ -929,9 +1003,8 @@ public String[] topVotersDaily() { } /** - * Top voters. - * - * @return the string[] + * Gets monthly top voters as formatted strings. + * @return array of formatted top voter lines */ public String[] topVotersMonthly() { ArrayList msg = new ArrayList<>(); @@ -956,10 +1029,9 @@ public String[] topVotersMonthly() { } /** - * Top voter weekly. - * - * @param page the page - * @return the string[] + * Gets weekly top voters with pagination. + * @param page the page number + * @return array of formatted top voter lines */ public String[] topVoterWeekly(int page) { int pagesize = plugin.getConfigFile().getFormatPageSize(); @@ -994,6 +1066,10 @@ public String[] topVoterWeekly(int page) { return ArrayUtils.convert(msg); } + /** + * Updates top voter rankings for a specific period. + * @param tempTopVoter map of top voter periods to player rankings + */ public synchronized void updateTopVoters( LinkedHashMap> tempTopVoter) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterPlayer.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterPlayer.java index e31b25270..86322f6b9 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterPlayer.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/topvoter/TopVoterPlayer.java @@ -10,6 +10,9 @@ import lombok.Getter; import lombok.Setter; +/** + * Represents a top voter player with ranking information. + */ public class TopVoterPlayer { @Getter @Setter @@ -22,16 +25,30 @@ public class TopVoterPlayer { @Setter private Long lastVoteTime; + /** + * Constructs a new top voter player. + * @param uuid the player UUID + * @param playerName the player name + * @param lastVoteTime the last vote time + */ public TopVoterPlayer(UUID uuid, String playerName, Long lastVoteTime) { this.uuid = uuid; this.playerName = playerName; this.lastVoteTime = lastVoteTime; } + /** + * Gets the player head item stack. + * @return the player head item + */ public ItemStack getPlayerHead() { return VotingPluginMain.plugin.getSkullCacheHandler().getSkull(uuid, playerName); } + /** + * Gets the VotingPluginUser for this top voter. + * @return the voting plugin user + */ public VotingPluginUser getUser() { return VotingPluginMain.plugin.getVotingPluginUserManager().getVotingPluginUser(getUuid(), getPlayerName()); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/updater/CheckUpdate.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/updater/CheckUpdate.java index 9472354af..e745c8c74 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/updater/CheckUpdate.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/updater/CheckUpdate.java @@ -14,6 +14,11 @@ public class CheckUpdate { private VotingPluginMain plugin; + /** + * Constructs a new CheckUpdate instance. + * + * @param plugin the main plugin instance + */ public CheckUpdate(VotingPluginMain plugin) { this.plugin = plugin; } @@ -48,6 +53,9 @@ public void checkUpdate() { } } + /** + * Performs a basic update check without downloading. + */ public void checkUpdateBasic() { if (plugin.getConfigFile().isDisableUpdateChecking()) { return; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/user/UserManager.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/user/UserManager.java index 97e0db5b0..6b1a166f4 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/user/UserManager.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/user/UserManager.java @@ -18,13 +18,23 @@ import com.bencodez.votingplugin.specialrewards.votemilestones.VoteMilestonesManager; import com.bencodez.votingplugin.topvoter.TopVoter; +/** + * Manages VotingPlugin user operations and data. + */ public class UserManager { private VotingPluginMain plugin; + /** + * Constructs a new user manager. + * @param plugin the plugin instance + */ public UserManager(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Adds caching keys to the user data manager. + */ public void addCachingKeys() { UserDataManager manager = plugin.getUserManager().getDataManager(); manager.addKey(new UserDataKeyBoolean("TopVoterIgnore")); @@ -78,10 +88,18 @@ public void addCachingKeys() { } + /** + * Gets all user UUIDs. + * @return list of all UUIDs + */ public ArrayList getAllUUIDs() { return plugin.getUserManager().getAllUUIDs(); } + /** + * Gets the cooldown check path based on server configuration. + * @return the cooldown check path + */ public String getCoolDownCheckPath() { if (plugin.getBungeeSettings().isUseBungeecoord()) { return "CoolDownCheck_" + plugin.getBungeeSettings().getServerNameStorage(); @@ -89,6 +107,10 @@ public String getCoolDownCheckPath() { return "CoolDownCheck"; } + /** + * Gets the cooldown check site path based on server configuration. + * @return the cooldown check site path + */ public String getCoolDownCheckSitePath() { if (plugin.getBungeeSettings().isUseBungeecoord()) { return "CoolDownCheck_" + plugin.getBungeeSettings().getServerNameStorage() + "_Sites"; @@ -96,6 +118,10 @@ public String getCoolDownCheckSitePath() { return "CoolDownCheck" + "_Sites"; } + /** + * Gets the path for tracking when all sites were voted on. + * @return the all sites day path + */ public String getGottenAllSitesDayPath() { if (plugin.getBungeeSettings().isUseBungeecoord()) { return "AllSitesLast_" + plugin.getBungeeSettings().getServerNameStorage(); @@ -103,6 +129,10 @@ public String getGottenAllSitesDayPath() { return "AllSitesLast"; } + /** + * Gets the path for tracking when almost all sites were voted on. + * @return the almost all sites day path + */ public String getGottenAlmostAllSitesDayPath() { if (plugin.getBungeeSettings().isUseBungeecoord()) { return "AlmostAllSitesLast_" + plugin.getBungeeSettings().getServerNameStorage(); @@ -110,47 +140,96 @@ public String getGottenAlmostAllSitesDayPath() { return "AlmostAllSitesLast"; } + /** + * Gets the monthly totals path for the current time. + * @return the month totals path + */ public String getMonthTotalsWithDatePath() { LocalDateTime cTime = plugin.getTimeChecker().getTime(); return getMonthTotalsWithDatePath(cTime); } + /** + * Gets the monthly totals path for a specific time. + * @param cTime the time to get the path for + * @return the month totals path + */ public String getMonthTotalsWithDatePath(LocalDateTime cTime) { return "MonthTotal-" + cTime.getMonth().toString() + "-" + cTime.getYear(); } + /** + * Gets a VotingPluginUser from an AdvancedCoreUser. + * @param user the AdvancedCoreUser + * @return the VotingPluginUser + */ public VotingPluginUser getVotingPluginUser(com.bencodez.advancedcore.api.user.AdvancedCoreUser user) { return new VotingPluginUser(plugin, user); } + /** + * Gets a VotingPluginUser from an offline player. + * @param player the offline player + * @return the VotingPluginUser + */ public VotingPluginUser getVotingPluginUser(OfflinePlayer player) { return getVotingPluginUser(player.getUniqueId(), player.getName()); } + /** + * Gets a VotingPluginUser from an online player. + * @param player the online player + * @return the VotingPluginUser + */ public VotingPluginUser getVotingPluginUser(Player player) { return getVotingPluginUser(player.getUniqueId(), player.getName()); } + /** + * Gets a VotingPluginUser by player name. + * @param playerName the player name + * @return the VotingPluginUser + */ @SuppressWarnings("deprecation") public VotingPluginUser getVotingPluginUser(String playerName) { return new VotingPluginUser(plugin, plugin.getUserManager().getProperName(playerName)); } + /** + * Gets a VotingPluginUser by UUID. + * @param uuid the player UUID + * @return the VotingPluginUser + */ @SuppressWarnings("deprecation") public VotingPluginUser getVotingPluginUser(UUID uuid) { return new VotingPluginUser(plugin, uuid); } + /** + * Gets a VotingPluginUser by UUID with optional name loading. + * @param uuid the player UUID + * @param loadName whether to load the player name + * @return the VotingPluginUser + */ @SuppressWarnings("deprecation") public VotingPluginUser getVotingPluginUser(UUID uuid, boolean loadName) { return new VotingPluginUser(plugin, uuid, loadName); } + /** + * Gets a VotingPluginUser by UUID and player name. + * @param uuid the player UUID + * @param playerName the player name + * @return the VotingPluginUser + */ @SuppressWarnings("deprecation") public VotingPluginUser getVotingPluginUser(UUID uuid, String playerName) { return new VotingPluginUser(plugin, uuid, playerName); } + /** + * Purges old players with no voting data. + */ public void purgeOldPlayersNoData() { if (plugin.getOptions().isPurgeOldData() && plugin.getConfigFile().isPurgeNoDataOnStartup()) { plugin.addUserStartup(new UserStartup() { @@ -190,6 +269,9 @@ public void onStartUp(AdvancedCoreUser acUser) { plugin.getUserManager().getDataManager().clearCache(); } + /** + * Immediately purges old players with no voting data. + */ public void purgeOldPlayersNowNoData() { plugin.getUserManager().forEachUserKeys((uuid, columns) -> { if (plugin.isEnabled()) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/VoteLogMysqlTable.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/VoteLogMysqlTable.java index ac187b421..2e89daa56 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/VoteLogMysqlTable.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/VoteLogMysqlTable.java @@ -37,22 +37,49 @@ */ public abstract class VoteLogMysqlTable extends AbstractSqlTable { + /** + * Event types that can be logged in the vote log. + */ public enum VoteLogEvent { - // Core + /** + * A vote was received. + */ VOTE_RECEIVED, + /** + * A vote milestone reward was triggered. + */ VOTEMILESTONE, + /** + * A vote streak reward was triggered. + */ VOTE_STREAK_REWARD, + /** + * A top voter reward was triggered. + */ TOP_VOTER_REWARD, + /** + * A vote shop purchase was made. + */ VOTESHOP_PURCHASE } + /** + * Status types for vote processing. + */ public enum VoteLogStatus { - IMMEDIATE, CACHED + /** + * Vote was processed immediately. + */ + IMMEDIATE, + /** + * Vote was cached for later processing. + */ + CACHED } private final boolean debugEnabled; @@ -66,12 +93,27 @@ public enum VoteLogStatus { // ---- Constructors ---- + /** + * Creates a new vote log table. + * + * @param baseTableName base name for the table + * @param config mysql configuration + * @param debug whether debug logging is enabled + */ public VoteLogMysqlTable(String baseTableName, MysqlConfig config, boolean debug) { super(baseTableName, config, debug, true); this.debugEnabled = debug; ensureColumnsAndIndexes(); } + /** + * Creates a new vote log table using an existing MySQL connection. + * + * @param baseTableName base name for the table + * @param existingMysql existing MySQL connection + * @param config mysql configuration + * @param debug whether debug logging is enabled + */ public VoteLogMysqlTable(String baseTableName, MySQL existingMysql, MysqlConfig config, boolean debug) { super(resolveName(baseTableName, config), existingMysql, true); this.debugEnabled = debug; @@ -103,6 +145,13 @@ public String getPrimaryKeyColumn() { return "id"; } + /** + * Gets distinct server names from the vote log. + * + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of distinct server names + */ public List getDistinctServers(int days, int limit) { if (limit <= 0) { limit = 45; @@ -134,18 +183,49 @@ public List getDistinctServers(int days, int limit) { } } + /** + * Gets vote log entries for a specific server. + * + * @param server server name to filter by + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByServer(String server, int days, int limit) { return getByServer(server, null, days, limit); } + /** + * Gets vote log entries for a specific server, votes only. + * + * @param server server name to filter by + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByServerVotesOnly(String server, int days, int limit) { return getByServer(server, VoteLogEvent.VOTE_RECEIVED, days, limit); } + /** + * Gets top servers by vote count. + * + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of server counts + */ public List getTopServers(int days, int limit) { return getTopServers(days, limit, VoteLogEvent.VOTE_RECEIVED); } + /** + * Gets top servers by vote count with event filtering. + * + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @param eventFilter event type to filter by + * @return list of server counts + */ public List getTopServers(int days, int limit, VoteLogEvent eventFilter) { if (limit <= 0) { limit = 10; @@ -183,16 +263,40 @@ public List getTopServers(int days, int limit, VoteLogEvent eventFi } } + /** + * Holds server name and vote count. + */ public static class ServerCount { + /** + * Server name. + */ public final String server; + /** + * Vote count for this server. + */ public final long votes; + /** + * Constructs a new ServerCount. + * + * @param server server name + * @param votes vote count + */ public ServerCount(String server, long votes) { this.server = server; this.votes = votes; } } + /** + * Gets vote log entries for a specific server with event filtering. + * + * @param server server name to filter by + * @param event event type to filter by (null for all) + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByServer(String server, VoteLogEvent event, int days, int limit) { if (limit <= 0) { limit = 10; @@ -400,6 +504,13 @@ private String resolveServerName() { } } + /** + * Appends a time type to a context string. + * + * @param baseContext base context string + * @param timeType time type to append + * @return combined context string + */ public static String withTimeType(String baseContext, String timeType) { baseContext = safeStr(baseContext); timeType = safeStr(timeType); @@ -424,6 +535,13 @@ private static String limit(String s, int max) { // ---- VoteShop helpers ---- + /** + * Creates a context string for a vote shop purchase. + * + * @param identifier shop item identifier + * @param cost cost of the item + * @return formatted context string + */ public static String voteShopContext(String identifier, int cost) { identifier = safeStr(identifier); @@ -524,6 +642,15 @@ public String logVoteMilestoneReward(UUID voteUUID, String playerUuid, String pl return logEvent(voteUUID, VoteLogEvent.VOTEMILESTONE, context, playerUuid, playerName, timeMillis); } + /** + * Logs a vote shop purchase event. + * + * @param playerUuid player UUID as string + * @param playerName player name + * @param timeMillis event time in millis + * @param identifier shop item identifier + * @param cost cost of the item + */ public void logVoteShopPurchase(String playerUuid, String playerName, long timeMillis, String identifier, int cost) { String ctx = voteShopContext(identifier, cost); @@ -531,6 +658,18 @@ public void logVoteShopPurchase(String playerUuid, String playerName, long timeM timeMillis, 0); } + /** + * Logs a vote event. + * + * @param voteUUID correlation vote UUID (may be null) + * @param status processing status + * @param service vote service name + * @param playerUuid player UUID as string + * @param playerName player name + * @param voteTimeMillis vote time in millis + * @param proxyCachedTotal cached total from proxy + * @return vote id string (may be null) + */ public String logVote(UUID voteUUID, VoteLogStatus status, String service, String playerUuid, String playerName, long voteTimeMillis, int proxyCachedTotal) { @@ -538,6 +677,20 @@ public String logVote(UUID voteUUID, VoteLogStatus status, String service, Strin voteTimeMillis, proxyCachedTotal); } + /** + * Logs a generic event. + * + * @param voteUUID correlation vote UUID (may be null) + * @param event event type + * @param context event context string + * @param status processing status + * @param service vote service name + * @param playerUuid player UUID as string + * @param playerName player name + * @param timeMillis event time in millis + * @param proxyCachedTotal cached total from proxy + * @return vote id string (may be null) + */ public String logEvent(UUID voteUUID, VoteLogEvent event, String context, VoteLogStatus status, String service, String playerUuid, String playerName, long timeMillis, int proxyCachedTotal) { @@ -560,6 +713,17 @@ public String logEvent(UUID voteUUID, VoteLogEvent event, String context, VoteLo return voteId; } + /** + * Logs a generic event without service or status. + * + * @param voteUUID correlation vote UUID (may be null) + * @param event event type + * @param context event context string + * @param playerUuid player UUID as string + * @param playerName player name + * @param timeMillis event time in millis + * @return vote id string (may be null) + */ public String logEvent(UUID voteUUID, VoteLogEvent event, String context, String playerUuid, String playerName, long timeMillis) { @@ -576,16 +740,44 @@ public String logEvent(UUID voteUUID, VoteLogEvent event, String context, String return voteId; } + /** + * Logs a generic event using current time. + * + * @param voteUUID correlation vote UUID (may be null) + * @param event event type + * @param context event context string + * @param playerUuid player UUID as string + * @param playerName player name + * @return vote id string (may be null) + */ public String logEventNow(UUID voteUUID, VoteLogEvent event, String context, String playerUuid, String playerName) { return logEvent(voteUUID, event, context, playerUuid, playerName, System.currentTimeMillis()); } + /** + * Logs a vote streak reward event. + * + * @param voteUUID correlation vote UUID (may be null) + * @param playerUuid player UUID as string + * @param playerName player name + * @param timeMillis event time in millis + * @param streakKeyWithTimeType streak key with time type suffix + */ public void logVoteStreakReward(UUID voteUUID, String playerUuid, String playerName, long timeMillis, String streakKeyWithTimeType) { logEvent(voteUUID, VoteLogEvent.VOTE_STREAK_REWARD, safeStr(streakKeyWithTimeType), playerUuid, playerName, timeMillis); } + /** + * Logs a top voter reward event. + * + * @param voteUUID correlation vote UUID (may be null) + * @param playerUuid player UUID as string + * @param playerName player name + * @param timeMillis event time in millis + * @param topVoterKeyWithTimeType top voter key with time type suffix + */ public void logTopVoterReward(UUID voteUUID, String playerUuid, String playerName, long timeMillis, String topVoterKeyWithTimeType) { logEvent(voteUUID, VoteLogEvent.TOP_VOTER_REWARD, safeStr(topVoterKeyWithTimeType), playerUuid, playerName, @@ -594,6 +786,12 @@ public void logTopVoterReward(UUID voteUUID, String playerUuid, String playerNam // ---- Purge ---- + /** + * Purges vote log entries older than the specified number of days. + * + * @param days number of days to keep + * @param batchSize number of rows to delete per batch + */ public void purgeOlderThanDays(int days, int batchSize) { if (days <= 0) { return; @@ -623,6 +821,13 @@ public void purgeOlderThanDays(int days, int batchSize) { // ---- Queries ---- + /** + * Gets distinct service names from the vote log. + * + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of distinct service names + */ public List getDistinctServices(int days, int limit) { if (limit <= 0) { limit = 45; @@ -655,6 +860,13 @@ public List getDistinctServices(int days, int limit) { } } + /** + * Gets recent vote log entries for all events. + * + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getRecentAll(int days, int limit) { if (limit <= 0) { limit = 10; @@ -673,6 +885,14 @@ public List getRecentAll(int days, int limit) { return query(sql, new Object[] {}); } + /** + * Gets recent vote log entries filtered by event type. + * + * @param event event type to filter by + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getRecentByEvent(VoteLogEvent event, int days, int limit) { if (event == null) { return (days > 0) ? getRecentAll(days, limit) : getRecent(limit); @@ -694,6 +914,14 @@ public List getRecentByEvent(VoteLogEvent event, int days, int lim return query(sql, new Object[] { event.name() }); } + /** + * Gets recent vote log entries with optional event filtering. + * + * @param days number of days to look back (0 for all) + * @param eventFilter event type to filter by (null for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getRecent(int days, VoteLogEvent eventFilter, int limit) { if (limit <= 0) { limit = 10; @@ -716,6 +944,12 @@ public List getRecent(int days, VoteLogEvent eventFilter, int limi return query(sql, new Object[] {}); } + /** + * Gets the most recent vote log entry for a vote ID. + * + * @param voteId vote ID to find + * @return vote log entry or null if not found + */ public VoteLogEntry getByVoteId(String voteId) { String sql = "SELECT vote_id, vote_time, player_uuid, player_name, service, server, event, context, status, cached_total " + "FROM " + qi(getTableName()) + " WHERE vote_id=? ORDER BY vote_time DESC, id DESC LIMIT 1;"; @@ -723,6 +957,14 @@ public VoteLogEntry getByVoteId(String voteId) { return rows.isEmpty() ? null : rows.get(0); } + /** + * Gets all vote log entries for a vote ID. + * + * @param voteId vote ID to find + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByVoteIdAll(String voteId, int days, int limit) { if (limit <= 0) { limit = 10; @@ -740,6 +982,12 @@ public List getByVoteIdAll(String voteId, int days, int limit) { return query(sql, new Object[] { voteId }); } + /** + * Gets the most recent vote log entries. + * + * @param limit maximum number of results + * @return list of vote log entries + */ public List getRecent(int limit) { if (limit <= 0) { limit = 10; @@ -749,14 +997,39 @@ public List getRecent(int limit) { return query(sql, new Object[] {}); } + /** + * Gets vote log entries for a specific service. + * + * @param service service name to filter by + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByService(String service, int days, int limit) { return getByService(service, null, days, limit); } + /** + * Gets vote log entries for a specific service, votes only. + * + * @param service service name to filter by + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByServiceVotesOnly(String service, int days, int limit) { return getByService(service, VoteLogEvent.VOTE_RECEIVED, days, limit); } + /** + * Gets vote log entries for a specific service with event filtering. + * + * @param service service name to filter by + * @param event event type to filter by (null for all) + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByService(String service, VoteLogEvent event, int days, int limit) { if (limit <= 0) { limit = 10; @@ -778,14 +1051,39 @@ public List getByService(String service, VoteLogEvent event, int d return query(sql, new Object[] { service }); } + /** + * Gets vote log entries for a specific player. + * + * @param playerName player name to filter by + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByPlayerName(String playerName, int days, int limit) { return getByPlayerName(playerName, null, days, limit); } + /** + * Gets vote log entries for a specific player, votes only. + * + * @param playerName player name to filter by + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByPlayerNameVotesOnly(String playerName, int days, int limit) { return getByPlayerName(playerName, VoteLogEvent.VOTE_RECEIVED, days, limit); } + /** + * Gets vote log entries for a specific player with event filtering. + * + * @param playerName player name to filter by + * @param event event type to filter by (null for all) + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of vote log entries + */ public List getByPlayerName(String playerName, VoteLogEvent event, int days, int limit) { if (limit <= 0) { limit = 10; @@ -807,10 +1105,23 @@ public List getByPlayerName(String playerName, VoteLogEvent event, return query(sql, new Object[] { playerName }); } + /** + * Gets vote counts (total, immediate, cached). + * + * @param days number of days to look back (0 for all) + * @return vote log counts + */ public VoteLogCounts getCounts(int days) { return getCounts(days, VoteLogEvent.VOTE_RECEIVED); } + /** + * Gets vote counts with event filtering. + * + * @param days number of days to look back (0 for all) + * @param eventFilter event type to filter by + * @return vote log counts + */ public VoteLogCounts getCounts(int days, VoteLogEvent eventFilter) { boolean useCutoff = days > 0; long cutoff = useCutoff ? System.currentTimeMillis() - (days * 24L * 60L * 60L * 1000L) : 0; @@ -847,10 +1158,23 @@ public VoteLogCounts getCounts(int days, VoteLogEvent eventFilter) { return new VoteLogCounts(0, 0, 0); } + /** + * Gets the number of unique voters. + * + * @param days number of days to look back (0 for all) + * @return count of unique voters + */ public long getUniqueVoters(int days) { return getUniqueVoters(days, VoteLogEvent.VOTE_RECEIVED); } + /** + * Gets the number of unique voters with event filtering. + * + * @param days number of days to look back (0 for all) + * @param eventFilter event type to filter by + * @return count of unique voters + */ public long getUniqueVoters(int days, VoteLogEvent eventFilter) { boolean useCutoff = days > 0; long cutoff = useCutoff ? System.currentTimeMillis() - (days * 24L * 60L * 60L * 1000L) : 0; @@ -880,10 +1204,25 @@ public long getUniqueVoters(int days, VoteLogEvent eventFilter) { return 0; } + /** + * Gets top services by vote count. + * + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @return list of service counts + */ public List getTopServices(int days, int limit) { return getTopServices(days, limit, VoteLogEvent.VOTE_RECEIVED); } + /** + * Gets top services by vote count with event filtering. + * + * @param days number of days to look back (0 for all) + * @param limit maximum number of results + * @param eventFilter event type to filter by + * @return list of service counts + */ public List getTopServices(int days, int limit, VoteLogEvent eventFilter) { if (limit <= 0) { limit = 10; @@ -958,18 +1297,65 @@ private List query(String sql, Object[] params) { // ---- DTOs ---- + /** + * Represents a single vote log entry from the database. + */ public static class VoteLogEntry { + /** + * Vote ID (correlation id). + */ public final String voteId; + /** + * Vote time in milliseconds. + */ public final long voteTime; + /** + * Player UUID as string. + */ public final String playerUuid; + /** + * Player name. + */ public final String playerName; + /** + * Service name. + */ public final String service; + /** + * Server name. + */ public final String server; + /** + * Event type name. + */ public final String event; + /** + * Event context string. + */ public final String context; + /** + * Processing status. + */ public final String status; + /** + * Cached total from proxy. + */ public final int proxyCachedTotal; + /** + * Constructs a new VoteLogEntry. + * + * @param voteId vote ID + * @param voteTime vote time in milliseconds + * @param playerUuid player UUID as string + * @param playerName player name + * @param service service name + * @param server server name + * @param event event type name + * @param context event context + * @param status processing status + * @param proxyCachedTotal cached total from proxy + */ public VoteLogEntry(String voteId, long voteTime, String playerUuid, String playerName, String service, String server, String event, String context, String status, int proxyCachedTotal) { this.voteId = voteId; @@ -985,11 +1371,30 @@ public VoteLogEntry(String voteId, long voteTime, String playerUuid, String play } } + /** + * Holds vote count statistics. + */ public static class VoteLogCounts { + /** + * Total vote count. + */ public final long total; + /** + * Immediate vote count. + */ public final long immediate; + /** + * Cached vote count. + */ public final long cached; + /** + * Constructs a new VoteLogCounts. + * + * @param total total count + * @param immediate immediate count + * @param cached cached count + */ public VoteLogCounts(long total, long immediate, long cached) { this.total = total; this.immediate = immediate; @@ -997,10 +1402,25 @@ public VoteLogCounts(long total, long immediate, long cached) { } } + /** + * Holds service name and vote count. + */ public static class ServiceCount { + /** + * Service name. + */ public final String service; + /** + * Vote count for this service. + */ public final long votes; + /** + * Constructs a new ServiceCount. + * + * @param service service name + * @param votes vote count + */ public ServiceCount(String service, long votes) { this.service = service; this.votes = votes; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerPostVoteLoggerListener.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerPostVoteLoggerListener.java index 7301a039a..83f601e00 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerPostVoteLoggerListener.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerPostVoteLoggerListener.java @@ -8,6 +8,9 @@ import com.bencodez.votingplugin.events.PlayerPostVoteEvent; import com.bencodez.votingplugin.votelog.VoteLogMysqlTable.VoteLogStatus; +/** + * Listener for logging player post-vote events. + */ public class PlayerPostVoteLoggerListener implements Listener { private VotingPluginMain plugin; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerSpecialRewardLoggerListener.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerSpecialRewardLoggerListener.java index 52bd0f99b..d51bed728 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerSpecialRewardLoggerListener.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/PlayerSpecialRewardLoggerListener.java @@ -10,6 +10,9 @@ import com.bencodez.votingplugin.VotingPluginMain; import com.bencodez.votingplugin.events.PlayerSpecialRewardEvent; +/** + * Listener for logging player special reward events. + */ public class PlayerSpecialRewardLoggerListener implements Listener { private VotingPluginMain plugin; diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/VoteMilestoneVoteLogListener.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/VoteMilestoneVoteLogListener.java index 10a300200..8c64f2c4e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/VoteMilestoneVoteLogListener.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votelog/listeners/VoteMilestoneVoteLogListener.java @@ -14,10 +14,20 @@ public class VoteMilestoneVoteLogListener implements Listener { private final VotingPluginMain plugin; + /** + * Constructs a new VoteMilestoneVoteLogListener. + * + * @param plugin the main plugin instance + */ public VoteMilestoneVoteLogListener(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Handles vote milestone reward events and logs them. + * + * @param e the vote milestone reward event + */ @EventHandler public void onVoteMilestoneReward(VoteMilestoneRewardEvent e) { if (e == null || e.getUser() == null || e.getMilestone() == null) { diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersLegacyMigrator.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersLegacyMigrator.java index 56f859e43..54b6203d1 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersLegacyMigrator.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersLegacyMigrator.java @@ -8,6 +8,9 @@ import com.bencodez.votingplugin.VotingPluginMain; +/** + * Utility class for migrating legacy vote reminding configuration to the new format. + */ public final class VoteRemindersLegacyMigrator { private VoteRemindersLegacyMigrator() { @@ -20,6 +23,11 @@ private VoteRemindersLegacyMigrator() { * - NO BACKUPS (per request) - Runs once * (VoteReminderOptions.MigratedFromLegacy) - Skips if new sections already * exist + * + * @param plugin the main plugin instance + * @param configYmlFile the config.yml file + * @param cfg the file configuration + * @return true if migration was performed, false if skipped */ public static boolean migrateIfNeeded(VotingPluginMain plugin, File configYmlFile, FileConfiguration cfg) { // already migrated diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersListener.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersListener.java index baa925f45..eb5cca3c5 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersListener.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/VoteRemindersListener.java @@ -14,30 +14,58 @@ import com.bencodez.votingplugin.events.PlayerVoteSiteCoolDownEndEvent; import com.bencodez.votingplugin.votereminding.VoteRemindersManager.VoteReminderType; +/** + * Listener for vote reminder events. + */ public class VoteRemindersListener implements Listener { private VotingPluginMain plugin; + /** + * Constructs a new VoteRemindersListener. + * + * @param plugin the main plugin instance + */ public VoteRemindersListener(VotingPluginMain plugin) { this.plugin = plugin; } + /** + * Handles player post vote events for reminder tracking. + * + * @param event the player post vote event + */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPostVote(PlayerPostVoteEvent event) { plugin.getVoteRemindersManager().onVoteCast(event.getUser(), event.getVoteSite().getDisplayName()); } + /** + * Handles player login events for reminder checks. + * + * @param event the advanced core login event + */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onLogin(AdvancedCoreLoginEvent event) { plugin.getVoteRemindersManager().onJoin(event.getPlayer(), plugin.getVotingPluginUserManager().getVotingPluginUser(event.getUser())); } + /** + * Handles player quit events for reminder cleanup. + * + * @param event the player quit event + */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onQuit(PlayerQuitEvent event) { plugin.getVoteRemindersManager().onQuit(event.getPlayer()); } + /** + * Handles cooldown end events for all sites. + * + * @param event the player vote cooldown end event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCoolDownEnd(PlayerVoteCoolDownEndEvent event) { HashMap placeholders = new HashMap<>(); @@ -45,6 +73,11 @@ public void onCoolDownEnd(PlayerVoteCoolDownEndEvent event) { placeholders); } + /** + * Handles cooldown end events for specific sites. + * + * @param event the player vote site cooldown end event + */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCoolDownEnd(PlayerVoteSiteCoolDownEndEvent event) { HashMap placeholders = new HashMap<>(); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/UserDataVoteReminderCooldownStore.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/UserDataVoteReminderCooldownStore.java index 140a8775c..1cb2cfaad 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/UserDataVoteReminderCooldownStore.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/UserDataVoteReminderCooldownStore.java @@ -19,7 +19,13 @@ */ public final class UserDataVoteReminderCooldownStore implements VoteReminderCooldownStore { + /** + * Storage key for global last reminder time. + */ public static final String KEY_GLOBAL_LAST = "VoteRemindersLast"; + /** + * Storage key for per-reminder map. + */ public static final String KEY_MAP = "VoteRemindersMap"; private final VotingPluginMain plugin; @@ -27,6 +33,10 @@ public final class UserDataVoteReminderCooldownStore implements VoteReminderCool private final ConcurrentHashMap> mapCache = new ConcurrentHashMap<>(); private final ConcurrentHashMap locks = new ConcurrentHashMap<>(); + /** + * Constructs a new user data vote reminder cooldown store. + * @param plugin the plugin instance + */ public UserDataVoteReminderCooldownStore(VotingPluginMain plugin) { this.plugin = plugin; } @@ -108,6 +118,10 @@ public boolean isPersistent(UUID uuid) { return user.getData().hasData(); } + /** + * Clears cache for a specific player. + * @param uuid the player UUID + */ public void clearCache(UUID uuid) { mapCache.remove(uuid); locks.remove(uuid); diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/VoteReminderCooldownStore.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/VoteReminderCooldownStore.java index 767351628..6deb856a7 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/VoteReminderCooldownStore.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votereminding/store/VoteReminderCooldownStore.java @@ -3,12 +3,38 @@ import java.util.Map; import java.util.UUID; +/** + * Interface for storing and managing vote reminder cooldowns. + */ public interface VoteReminderCooldownStore { + /** + * Attempts to claim global cooldown for a player. + * @param uuid the player UUID + * @param nowMs current time in milliseconds + * @param globalCooldownMs global cooldown in milliseconds + * @return true if cooldown was claimed + */ boolean tryClaimGlobal(UUID uuid, long nowMs, long globalCooldownMs); + /** + * Gets per-reminder cooldown map for a player. + * @param uuid the player UUID + * @return map of reminder names to last execution times + */ Map getPerReminderMap(UUID uuid); + /** + * Sets the last execution time for a specific reminder. + * @param uuid the player UUID + * @param reminderName the reminder name + * @param nowMs current time in milliseconds + */ void setPerReminderLast(UUID uuid, String reminderName, long nowMs); + /** + * Checks if player data is persistent. + * @param uuid the player UUID + * @return true if data is persistent + */ boolean isPersistent(UUID uuid); } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votesites/NextSite.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votesites/NextSite.java index 7b0dbf8f7..99b3bef8e 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/votesites/NextSite.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/votesites/NextSite.java @@ -1,18 +1,34 @@ package com.bencodez.votingplugin.votesites; +/** + * Represents the next available vote site. + */ public final class NextSite { private final VoteSite site; private final long secondsUntilAvailable; + /** + * Constructor for NextSite. + * @param site the vote site + * @param secondsUntilAvailable seconds until site is available + */ public NextSite(VoteSite site, long secondsUntilAvailable) { this.site = site; this.secondsUntilAvailable = secondsUntilAvailable; } + /** + * Get the vote site. + * @return the vote site + */ public VoteSite getSite() { return site; } + /** + * Get seconds until available. + * @return seconds until available + */ public long getSecondsUntilAvailable() { return secondsUntilAvailable; } diff --git a/VotingPlugin/src/main/java/com/bencodez/votingplugin/webhook/DiscordWebhookPayloadBuilder.java b/VotingPlugin/src/main/java/com/bencodez/votingplugin/webhook/DiscordWebhookPayloadBuilder.java index a52390e43..3d659dac2 100644 --- a/VotingPlugin/src/main/java/com/bencodez/votingplugin/webhook/DiscordWebhookPayloadBuilder.java +++ b/VotingPlugin/src/main/java/com/bencodez/votingplugin/webhook/DiscordWebhookPayloadBuilder.java @@ -30,19 +30,34 @@ private DiscordWebhookPayloadBuilder() { // builder } - /** @param username username override */ + /** + * Sets the username override. + * + * @param username username override + * @return this builder + */ public DiscordWebhookPayloadBuilder username(String username) { this.username = username; return this; } - /** @param avatarUrl avatar URL override */ + /** + * Sets the avatar URL override. + * + * @param avatarUrl avatar URL override + * @return this builder + */ public DiscordWebhookPayloadBuilder avatarUrl(String avatarUrl) { this.avatarUrl = avatarUrl; return this; } - /** @param content message content (plain text/markdown) */ + /** + * Sets the message content. + * + * @param content message content (plain text/markdown) + * @return this builder + */ public DiscordWebhookPayloadBuilder content(String content) { this.content = content; return this;