Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@

import lombok.Getter;

/**
* Handler for Bungee/proxy server integration.
*/
public class BungeeHandler implements Listener {
@Getter
private ClientHandler clientHandler;
Expand Down Expand Up @@ -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<String, DataValue> data = globalDataHandler.getExact(plugin.getBungeeSettings().getServer());

Expand Down Expand Up @@ -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<String, DataValue> data) {
boolean isProcessing = false;
if (data.containsKey(type.toString())) {
Expand Down Expand Up @@ -157,13 +175,22 @@ public boolean checkGlobalDataTime(TimeType type, HashMap<String, DataValue> 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();
}
return Boolean.valueOf(data.getString());
}

/**
* Closes and cleans up all handlers and connections.
*/
public void close() {
if (backendMysqlMessenger != null) {
backendMysqlMessenger.shutdown();
Expand All @@ -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");

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public final class BroadcastHandler {
private final ConcurrentHashMap<UUID, LinkedHashSet<String>> intervalSites = new ConcurrentHashMap<UUID, LinkedHashSet<String>>();
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;
Expand All @@ -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();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
public enum VoteBroadcastType {

/**
* No vote broadcasting.
*/
NONE,

/**
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2321,6 +2346,11 @@ public void execute(CommandSender sender, String[] args) {

private final Set<String> aliasCommandNames = new HashSet<>();

/**
* Gets the set of alias command names.
*
* @return set of alias command names
*/
public Set<String> getAliasCommandNames() {
return aliasCommandNames;
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +44,12 @@ public ArrayList<String> 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));

Expand Down
Loading