diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/AdvancedCorePlugin.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/AdvancedCorePlugin.java index 04495747ae..c562261161 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/AdvancedCorePlugin.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/AdvancedCorePlugin.java @@ -78,150 +78,379 @@ import lombok.Getter; import lombok.Setter; +/** + * Abstract base class for plugins that use AdvancedCore. + * Provides core functionality for user management, rewards, permissions, and more. + */ public abstract class AdvancedCorePlugin extends JavaPlugin { private static AdvancedCorePlugin javaPlugin; + /** + * Gets the singleton instance of this plugin. + * + * @return the plugin instance + */ public static AdvancedCorePlugin getInstance() { return javaPlugin; } + /** + * Sets the singleton instance of this plugin. + * + * @param plugin the plugin instance to set + */ public static void setInstance(AdvancedCorePlugin plugin) { javaPlugin = plugin; } + /** + * Handler for Vault integration. + * + * @return the vault handler + */ @Getter public VaultHandler vaultHandler; + /** + * Command loader for AdvancedCore commands. + * + * @return the command loader + */ @Getter private CommandLoader advancedCoreCommandLoader; + /** + * Handler for skull caching. + * + * @return the skull cache handler + */ @Getter private SkullCacheHandler skullCacheHandler; + /** + * Whether AuthMe is loaded. + * + * @return true if AuthMe is loaded + */ @Getter private boolean authMeLoaded = false; + /** + * Whether nLogin is loaded. + * + * @return true if nLogin is loaded + */ @Getter private boolean nLoginLoaded = false; + /** + * Whether LoginSecurity is loaded. + * + * @return true if LoginSecurity is loaded + */ @Getter private boolean loginSecurityLoaded = false; + /** + * List of banned player UUIDs. + * + * @return list of banned player UUIDs + */ @Getter private ArrayList bannedPlayers = new ArrayList<>(); + /** + * Build time of AdvancedCore. + * + * @return the build time string + */ @Getter private String buildTime = ""; + /** + * BungeeCord channel name. + * + * @return the bungee channel name + * @param bungeeChannel the channel name to set + */ @Getter @Setter private String bungeeChannel; + /** + * Handler for CMI integration. + * + * @return the CMI handler + */ @Getter private CMIHandler cmiHandle; private Database database; + /** + * Handler for full inventory management. + * + * @return the full inventory handler + */ @Getter private FullInventoryHandler fullInventoryHandler; + /** + * Handler for hologram management. + * + * @return the hologram handler + */ @Getter private HologramHandler hologramHandler; + /** + * JavaScript engine context map. + * + * @return the javascript engine map + * @param javascriptEngine the javascript engine map to set + */ @Getter @Setter private HashMap javascriptEngine = new HashMap<>(); + /** + * List of JavaScript placeholder requests. + * + * @return the javascript engine requests list + * @param javascriptEngineRequests the requests list to set + */ @Getter @Setter private ArrayList javascriptEngineRequests = new ArrayList<>(); + /** + * Whether rewards should be loaded. + * + * @return true if rewards should be loaded + * @param loadRewards true to load rewards + */ @Getter @Setter private boolean loadRewards = true; + /** + * Whether server data should be loaded. + * + * @return true if server data should be loaded + * @param loadServerData true to load server data + */ @Getter @Setter private boolean loadServerData = true; + /** + * Whether user data should be loaded. + * + * @return true if user data should be loaded + * @param loadUserData true to load user data + */ @Getter @Setter private boolean loadUserData = true; + /** + * MySQL database connection. + * + * @return the mysql connection + */ @Getter private MySQL mysql; + /** + * Configuration options for AdvancedCore. + * + * @return the configuration options + */ @Getter private AdvancedCoreConfigOptions options = new AdvancedCoreConfigOptions(); + /** + * Whether PlaceholderAPI is enabled. + * + * @return true if PlaceholderAPI is enabled + */ @Getter private boolean placeHolderAPIEnabled; + /** + * Plugin messaging handler. + * + * @return the plugin messaging handler + */ @Getter private PluginMessage pluginMessaging; + /** + * Server data file handler. + * + * @return the server data file + */ @Getter private ServerData serverDataFile; + /** + * Sign menu for user input. + * + * @return the sign menu + */ @Getter private SignMenu signMenu; + /** + * Time checker for scheduled operations. + * + * @return the time checker + */ @Getter private TimeChecker timeChecker; + /** + * Main timer for scheduled tasks. + * + * @return the timer + */ @Getter private ScheduledExecutorService timer; + /** + * Timer for login-related tasks. + * + * @return the login timer + */ @Getter private ScheduledExecutorService loginTimer; + /** + * Timer for inventory-related tasks. + * + * @return the inventory timer + */ @Getter private ScheduledExecutorService inventoryTimer; + /** + * User manager instance. + * + * @param userManager the user manager to set + */ @Setter private UserManager userManager; private ArrayList userStartup = new ArrayList<>(); + /** + * Version string of AdvancedCore. + * + * @return the version string + */ @Getter private String advancedCoreVersion = ""; + /** + * Build number of AdvancedCore. + * + * @return the build number + */ @Getter private String advancedCoreBuildNumber = "NOTSET"; + /** + * Handler for permission management. + * + * @return the permission handler + */ @Getter private PermissionHandler permissionHandler; + /** + * Handler for rewards system. + * + * @return the reward handler + */ @Getter private RewardHandler rewardHandler; + /** + * Handler for LuckPerms integration. + * + * @return the LuckPerms handler + */ @Getter private LuckPermsHandle luckPermsHandle; + /** + * Bukkit scheduler wrapper. + * + * @return the bukkit scheduler + */ @Getter private BukkitScheduler bukkitScheduler; + /** + * Whether Bedrock API should be loaded. + * + * @return true if Bedrock API should be loaded + * @param loadBedrockAPI true to load Bedrock API + */ @Getter @Setter private boolean loadBedrockAPI = true; + /** + * Whether LuckPerms should be loaded. + * + * @return true if LuckPerms should be loaded + * @param loadLuckPerms true to load LuckPerms + */ @Getter @Setter private boolean loadLuckPerms = true; + /** + * Handler for Bedrock player name resolution. + * + * @return the bedrock handler + */ @Getter private BedrockNameResolver bedrockHandle;; + /** + * Whether skull handler should be loaded. + * + * @return true if skull handler should be loaded + * @param loadSkullHandler true to load skull handler + */ @Getter @Setter private boolean loadSkullHandler = true; + /** + * Whether Vault should be loaded. + * + * @return true if Vault should be loaded + * @param loadVault true to load Vault + */ @Getter @Setter private boolean loadVault = true; + /** + * Adds a user startup task to be executed on plugin startup. + * + * @param start the startup task to add + */ public void addUserStartup(UserStartup start) { userStartup.add(start); } + /** + * Allows downloading plugin updates from Spigot. + * + * @param resourceId the Spigot resource ID + */ public void allowDownloadingFromSpigot(int resourceId) { getOptions().setResourceId(resourceId); } @@ -256,6 +485,9 @@ public void run() { } + /** + * Checks for plugin updates in the background. + */ public void checkPluginUpdate() { if (!loadServerData) { return; @@ -275,6 +507,12 @@ public void run() { } + /** + * Converts data from one storage type to another. + * + * @param from the source storage type + * @param to the target storage type + */ public void convertDataStorage(UserStorage from, UserStorage to) { debug("Starting convert process"); if (to == null) { @@ -306,6 +544,12 @@ public void convertDataStorage(UserStorage from, UserStorage to) { } + /** + * Logs a debug message at the specified debug level. + * + * @param debugLevel the debug level + * @param debug the debug message + */ public void debug(DebugLevel debugLevel, String debug) { if (debugLevel.equals(DebugLevel.EXTRA)) { debug = "ExtraDebug: " + debug; @@ -331,18 +575,38 @@ public void debug(Throwable e) { } } + /** + * Logs a debug message at INFO level. + * + * @param debug the debug message + */ public void debug(String debug) { debug(DebugLevel.INFO, debug); } + /** + * Logs a debug message at DEV level. + * + * @param debug the debug message + */ public void devDebug(String debug) { debug(DebugLevel.DEV, debug); } + /** + * Logs a debug message at EXTRA level. + * + * @param debug the debug message + */ public void extraDebug(String debug) { debug(DebugLevel.EXTRA, debug); } + /** + * Gets the SQLite user table. + * + * @return the user table, or null if not using SQLite + */ public UserTable getSQLiteUserTable() { if (database == null && loadUserData) { loadUserAPI(getStorageType()); @@ -357,10 +621,20 @@ public UserTable getSQLiteUserTable() { return null; } + /** + * Gets the current storage type configuration. + * + * @return the storage type + */ public UserStorage getStorageType() { return getOptions().getStorageType(); } + /** + * Gets the user manager instance. + * + * @return the user manager + */ public UserManager getUserManager() { if (userManager == null) { userManager = new UserManager(this); @@ -396,6 +670,11 @@ private YamlConfiguration getVersionFile() { return null; } + /** + * Checks if MySQL connection is okay. + * + * @return true if not using MySQL or if MySQL is connected, false otherwise + */ public boolean isMySQLOkay() { if (getStorageType().equals(UserStorage.MYSQL)) { return mysql != null; @@ -403,6 +682,9 @@ public boolean isMySQLOkay() { return true; } + /** + * Loads AdvancedCore event listeners. + */ public void loadAdvancedCoreEvents() { if (loadUserData) { Bukkit.getPluginManager().registerEvents(new PlayerJoinEvent(this), this); @@ -570,6 +852,9 @@ private void loadSignAPI() { } } + /** + * Loads tab completion options. + */ public void loadTabComplete() { TabCompleteHandler.getInstance().addTabCompleteOption(new TabCompleteHandle("(AllPlayer)", new ArrayList<>()) { @@ -749,6 +1034,11 @@ public void updateReplacements() { TabCompleteHandler.getInstance().addTabCompleteOption("(TimeType)", times); } + /** + * Loads user API for specified storage type. + * + * @param storageType the storage type to load + */ @SuppressWarnings("deprecation") public void loadUserAPI(UserStorage storageType) { if (storageType.equals(UserStorage.SQLITE)) { @@ -818,6 +1108,9 @@ public void onStartUp(AdvancedCoreUser user) { TabCompleteHandler.getInstance().loadTimer(getTimer()); } + /** + * Loads value request input commands. + */ public void loadValueRequestInputCommands() { CommandLoader.getInstance().loadValueRequestCommands(); try { @@ -832,6 +1125,9 @@ public void loadValueRequestInputCommands() { } } + /** + * Loads Vault integration. + */ public void loadVault() { vaultHandler = new VaultHandler(); if (Bukkit.getPluginManager().getPlugin("Vault") != null) { @@ -902,12 +1198,29 @@ public void onEnable() { getRewardHandler().checkDirectlyDefinedRewardFiles(); } + /** + * Called after plugin loads. + * Subclasses must implement this method. + */ public abstract void onPostLoad(); + /** + * Called before plugin loads. + * Subclasses must implement this method. + */ public abstract void onPreLoad(); + /** + * Called when plugin unloads. + * Subclasses must implement this method. + */ public abstract void onUnLoad(); + /** + * Registers BungeeCord messaging channels. + * + * @param name the channel name + */ public void registerBungeeChannels(String name) { this.bungeeChannel = name; getServer().getMessenger().registerOutgoingPluginChannel(this, name); @@ -916,17 +1229,36 @@ public void registerBungeeChannels(String name) { getLogger().info("Loaded plugin message channels: " + name); } + /** + * Registers a listener. + * + * @param listener the listener to register + */ public void registerEvents(Listener listener) { Bukkit.getPluginManager().registerEvents(listener, this); } + /** + * Reloads plugin configuration. + * Subclasses must implement this method. + */ public abstract void reload(); + /** + * Reloads AdvancedCore configuration. + * + * @deprecated use {@link #reloadAdvancedCore(boolean)} instead + */ @Deprecated public void reloadAdvancedCore() { reloadAdvancedCore(false); } + /** + * Reloads AdvancedCore configuration. + * + * @param userStorage whether to reload user storage + */ public void reloadAdvancedCore(boolean userStorage) { getServerDataFile().reloadData(); rewardHandler.loadRewards(); @@ -976,12 +1308,19 @@ public void setValue(String path, Object value) { }); } + /** + * Sets configuration data. + * + * @param ymlConfig the configuration to set + */ public void setConfigData(YMLConfig ymlConfig) { getOptions().setYmlConfig(ymlConfig); } /** - * @param mysql the mysql to set + * Sets the MySQL database connection. + * + * @param mysql the mysql connection to set */ public void setMysql(MySQL mysql) { if (this.mysql != null) { @@ -991,6 +1330,9 @@ public void setMysql(MySQL mysql) { this.mysql = mysql; } + /** + * Unregisters value request commands. + */ public void unRegisterValueRequest() { try { final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); @@ -1004,6 +1346,9 @@ public void unRegisterValueRequest() { } } + /** + * Runs user startup tasks. + */ public void userStartup() { if (!loadUserData) { debug("Not loading userdata"); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/backup/BackupHandle.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/backup/BackupHandle.java index 72f22d8895..997748bcf1 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/backup/BackupHandle.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/backup/BackupHandle.java @@ -11,9 +11,17 @@ import com.bencodez.advancedcore.api.time.TimeType; import com.bencodez.advancedcore.api.time.events.DateChangedEvent; +/** + * Handles automatic backups of plugin data. + */ public class BackupHandle implements Listener { private static BackupHandle instance = new BackupHandle(); + /** + * Gets the singleton instance. + * + * @return the backup handler instance + */ public static BackupHandle getInstance() { return instance; } @@ -21,6 +29,9 @@ public static BackupHandle getInstance() { private BackupHandle() { } + /** + * Checks for and deletes old backups older than 5 days. + */ public void checkOldBackups() { for (File file : new File(AdvancedCorePlugin.getInstance().getDataFolder(), "Backups").listFiles()) { long lastModified = file.lastModified(); @@ -31,6 +42,11 @@ public void checkOldBackups() { } } + /** + * Handles date change events to create daily backups. + * + * @param e the date changed event + */ @EventHandler public void onPostDateChange(DateChangedEvent e) { if (!e.getTimeType().equals(TimeType.DAY) || !AdvancedCorePlugin.getInstance().getOptions().isCreateBackups()) { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bedrock/BedrockNameResolver.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bedrock/BedrockNameResolver.java index 4faf408037..fd7ff66c7c 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bedrock/BedrockNameResolver.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bedrock/BedrockNameResolver.java @@ -15,6 +15,9 @@ import com.bencodez.advancedcore.api.user.UserManager; import com.bencodez.advancedcore.api.user.UserStartup; +/** + * Resolves Bedrock player names and detects Bedrock players. + */ public final class BedrockNameResolver { private final BedrockDetect bedrockDetect; @@ -25,6 +28,11 @@ public final class BedrockNameResolver { private final Map cache = new ConcurrentHashMap<>(); private final Map ciIndex = new ConcurrentHashMap<>(); + /** + * Creates a new Bedrock name resolver. + * + * @param plugin the plugin instance + */ public BedrockNameResolver(AdvancedCorePlugin plugin) { this.plugin = plugin; this.bedrockDetect = new BedrockDetect(plugin::debug); @@ -56,10 +64,23 @@ public void onFinish() { }); } + /** + * Checks if a player is a Bedrock player by name. + * + * @param name the player name + * @return true if the player is a Bedrock player + */ public boolean isBedrock(String name) { return isBedrockName(name); } + /** + * Checks if a player is a Bedrock player by UUID and name. + * + * @param uuid the player UUID + * @param name the player name + * @return true if the player is a Bedrock player + */ public boolean isBedrock(UUID uuid, String name) { // 1) UUID is authoritative if present if (uuid != null) { @@ -138,6 +159,11 @@ public boolean isBedrock(UUID uuid, String name) { // ------------ EXISTING METHODS (unchanged behavior) ------------ + /** + * Learns whether a user is a Bedrock player. + * + * @param user the user to learn from + */ public void learn(AdvancedCoreUser user) { if (user == null) return; @@ -147,6 +173,11 @@ public void learn(AdvancedCoreUser user) { putLearned(name, user.isBedrockUser()); } + /** + * Learns whether a player is a Bedrock player. + * + * @param player the player to learn from + */ public void learn(Player player) { if (player == null) return; @@ -165,9 +196,12 @@ public void learn(Player player) { /** * Detect whether a name corresponds to a Bedrock player. - * + * * IMPORTANT: This method does NOT add prefixes. It only returns a boolean. Use * {@link #resolve(String)} if you want canonical (possibly prefixed) names. + * + * @param name the player name + * @return true if the player is a Bedrock player */ public boolean isBedrockName(String name) { if (name == null || name.isEmpty()) @@ -216,6 +250,12 @@ public boolean isBedrockName(String name) { return bedrockPrefix != null && !bedrockPrefix.isEmpty() && name.startsWith(bedrockPrefix); } + /** + * Resolve a name to its canonical form and determine if it's a Bedrock player. + * + * @param incomingName the player name to resolve + * @return the result containing the canonical name and Bedrock status + */ public Result resolve(String incomingName) { if (incomingName == null || incomingName.isEmpty()) return new Result(incomingName, false, "empty-name"); @@ -292,10 +332,19 @@ public Result resolve(String incomingName) { return new Result(incomingName, false, "unknown-default-java"); } + /** + * Get the prefixed name if the player is a Bedrock player. + * + * @param name the player name + * @return the prefixed name if Bedrock, otherwise the original name + */ public String getPrefixedIfBedrock(String name) { return addPrefixIfNeeded(name, isBedrockName(name)); } + /** + * Clear the cache and case-insensitive index. + */ public void clearCache() { cache.clear(); ciIndex.clear(); @@ -436,11 +485,24 @@ private Player findOnlineByNameOrStripped(String name) { return (javaCandidate != null) ? javaCandidate : bedrockCandidate; } + /** + * Result of name resolution containing the final name, Bedrock status, and rationale. + */ public static final class Result { + /** The final resolved name. */ public final String finalName; + /** Whether the player is a Bedrock player. */ public final boolean isBedrock; + /** The rationale for the resolution decision. */ public final String rationale; + /** + * Instantiates a new result. + * + * @param finalName the final resolved name + * @param isBedrock whether the player is Bedrock + * @param rationale the rationale for the decision + */ public Result(String finalName, boolean isBedrock, String rationale) { this.finalName = finalName; this.isBedrock = isBedrock; @@ -451,6 +513,9 @@ public Result(String finalName, boolean isBedrock, String rationale) { // ====================== Embedded BedrockDetect with DEBUG // ====================== + /** + * Bedrock detection using Floodgate and Geyser APIs. + */ public static class BedrockDetect { private volatile boolean floodgateAvailable = false; private volatile boolean geyserAvailable = false; @@ -464,16 +529,27 @@ public static class BedrockDetect { private final Consumer debug; + /** + * Instantiates a new Bedrock detector with no debug output. + */ public BedrockDetect() { this(s -> { }); } + /** + * Instantiates a new Bedrock detector with debug output. + * + * @param debug the debug consumer + */ public BedrockDetect(Consumer debug) { this.debug = (debug != null) ? debug : (s -> { }); } + /** + * Load Floodgate and Geyser APIs. + */ public void load() { loadFloodgate(); loadGeyser(); @@ -514,6 +590,12 @@ private void loadGeyser() { } } + /** + * Check if a player is a Bedrock player by UUID. + * + * @param uuid the player UUID + * @return true if the player is a Bedrock player + */ public boolean isBedrock(UUID uuid) { if (uuid == null) return false; @@ -543,6 +625,12 @@ public boolean isBedrock(UUID uuid) { return false; } + /** + * Get the Floodgate player object. + * + * @param uuid the player UUID + * @return the Floodgate player object or null + */ public Object getFloodgatePlayer(UUID uuid) { if (!floodgateAvailable || fgGetPlayer == null || uuid == null) return null; @@ -554,10 +642,20 @@ public Object getFloodgatePlayer(UUID uuid) { } } + /** + * Check if Floodgate API is available. + * + * @return true if Floodgate is available + */ public boolean isFloodgateAvailable() { return floodgateAvailable; } + /** + * Check if Geyser API is available. + * + * @return true if Geyser is available + */ public boolean isGeyserAvailable() { return geyserAvailable; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/BookWrapper.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/BookWrapper.java index dd96940046..ac34c942a7 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/BookWrapper.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/BookWrapper.java @@ -14,32 +14,83 @@ import net.md_5.bungee.api.chat.BaseComponent; import xyz.upperlevel.spigot.book.BookUtil; +/** + * Wrapper for creating and managing book GUIs. + */ public class BookWrapper { + /** + * The book item stack. + * + * @return the book item + */ @Getter private ItemStack book; + /** + * The list of pages. + * + * @return the page builder list + */ @Getter private ArrayList builder = new ArrayList<>(); + /** + * The current page being built. + * + * @return the current page builder + */ @Getter private BookUtil.PageBuilder currentPage; + /** + * The current page line count. + * + * @return the current page line count + * @param currentPageLines the current page line count to set + */ @Getter @Setter private int currentPageLines = 0; + /** + * Placeholders to be replaced in the book. + * + * @return the placeholder map + */ @Getter private HashMap placeholders = new HashMap<>(); + /** + * The book title. + * + * @return the book title + * @param title the book title to set + */ @Getter @Setter private String title; + /** + * Instantiates a new book wrapper. + * + * @param title the book title + */ public BookWrapper(String title) { this.title = title; currentPage = new BookUtil.PageBuilder(); } + /** + * Add a layout to the current page. + * + * @param layout the layout to add + * @return this book wrapper + */ public BookWrapper addLayout(Layout layout) { addToCurrentPage(layout.getLayout(getPlaceholders())); return this; } + /** + * Add a line to the current page. + * + * @return this book wrapper + */ public BookWrapper addLine() { currentPageLines += 1; if (currentPageLines > 14) { @@ -49,11 +100,24 @@ public BookWrapper addLine() { return this; } + /** + * Add a placeholder to this book. + * + * @param toReplace the string to replace + * @param replaceWith the replacement string + * @return this book wrapper + */ public BookWrapper addPlaceholder(String toReplace, String replaceWith) { placeholders.put(toReplace, replaceWith); return this; } + /** + * Add components to the current page. + * + * @param baseComponents the components to add + * @return this book wrapper + */ public BookWrapper addToCurrentPage(BaseComponent... baseComponents) { currentPageLines += baseComponents.length; if (currentPageLines > 14) { @@ -66,10 +130,22 @@ public BookWrapper addToCurrentPage(BaseComponent... baseComponents) { return this; } + /** + * Colorize a string. + * + * @param s the string to colorize + * @return the colorized string + */ public String colorize(String s) { return MessageAPI.colorize(s); } + /** + * Move to the next page. + * + * @param newSize the new page size + * @return this book wrapper + */ public BookWrapper nextPage(int newSize) { builder.add(currentPage.build()); currentPage = new BookUtil.PageBuilder(); @@ -77,6 +153,11 @@ public BookWrapper nextPage(int newSize) { return this; } + /** + * Open the book for a player. + * + * @param player the player + */ public void open(Player player) { builder.add(currentPage.build()); book = BookUtil.writtenBook().author(player.getName()).title(colorize(title)).pages(builder).build(); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/Layout.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/Layout.java index 7f6cfd15d7..fe56a4b6ae 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/Layout.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/bookgui/Layout.java @@ -12,18 +12,38 @@ import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; +/** + * Represents a layout for book GUIs. + */ public class Layout { private BaseComponent compToAdd; private HashMap placeholders = new HashMap<>(); + /** + * Gets the string layout. + * + * @return the string layout + */ @Getter private ArrayList stringLayout; private String text; + /** + * Creates a new layout. + * + * @param layout the string layout + */ public Layout(ArrayList layout) { this.stringLayout = layout; } + /** + * Adds a placeholder replacement. + * + * @param toReplace the text to replace + * @param replaceWith the replacement text + * @return this layout for chaining + */ public Layout addPlaceholder(String toReplace, String replaceWith) { placeholders.put(toReplace, replaceWith); return this; @@ -33,6 +53,12 @@ private String colorize(String s) { return ChatColor.translateAlternateColorCodes('&', s); } + /** + * Gets the layout with placeholders replaced. + * + * @param placeholders the placeholders to replace + * @return the layout components + */ public BaseComponent[] getLayout(HashMap placeholders) { stringLayout = PlaceholderUtils.replacePlaceHolder(stringLayout, placeholders); stringLayout = PlaceholderUtils.replacePlaceHolder(stringLayout, this.placeholders); @@ -67,6 +93,13 @@ public BaseComponent[] getLayout(HashMap placeholders) { return comps; } + /** + * Replaces text with a component. + * + * @param text the text to replace + * @param compToAdd the component to add + * @return this layout for chaining + */ public Layout replaceTextComponent(String text, BaseComponent compToAdd) { this.text = text; this.compToAdd = compToAdd; diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/cmi/CMIHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/cmi/CMIHandler.java index cf8e0bb3a0..3fb4b4b36f 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/cmi/CMIHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/cmi/CMIHandler.java @@ -4,7 +4,16 @@ import com.Zrips.CMI.CMI; +/** + * Handler for CMI integration. + */ public class CMIHandler { + /** + * Checks if player is vanished. + * + * @param p the player + * @return true if vanished + */ public boolean isVanished(Player p) { return CMI.getInstance().getPlayerManager().getUser(p).isVanished(); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/AdvancedCoreTabCompleteHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/AdvancedCoreTabCompleteHandler.java index 455639c0ed..4c8f95bacc 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/AdvancedCoreTabCompleteHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/AdvancedCoreTabCompleteHandler.java @@ -7,13 +7,30 @@ import com.bencodez.simpleapi.command.TabCompleteHandler; +/** + * Handles tab completion for AdvancedCore commands. + */ public class AdvancedCoreTabCompleteHandler { static AdvancedCoreTabCompleteHandler instance = new AdvancedCoreTabCompleteHandler(); + /** + * Gets the singleton instance. + * + * @return the tab complete handler instance + */ public static AdvancedCoreTabCompleteHandler getInstance() { return instance; } + /** + * Gets tab complete options for a command. + * + * @param handles the command handlers + * @param sender the command sender + * @param args the command arguments + * @param argNum the argument number + * @return list of tab complete options + */ public ArrayList getTabCompleteOptions(ArrayList handles, CommandSender sender, String[] args, int argNum) { ArrayList tabComplete = new ArrayList<>(); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/CommandHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/CommandHandler.java index 467e556e04..c69381c901 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/CommandHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/command/CommandHandler.java @@ -11,9 +11,18 @@ */ public abstract class CommandHandler extends com.bencodez.simpleapi.command.CommandHandler { + /** + * Gets the plugin. + * + * @return the plugin + */ @Getter private AdvancedCorePlugin plugin; + /** + * Instantiates a new command handler. + * @deprecated Use constructor with plugin parameter + */ @Deprecated public CommandHandler() { super(AdvancedCorePlugin.getInstance()); @@ -21,6 +30,11 @@ public CommandHandler() { setAllowMultiplePermissions(plugin.getOptions().isMultiplePermissionChecks()); } + /** + * Instantiates a new command handler. + * + * @param plugin the plugin + */ public CommandHandler(AdvancedCorePlugin plugin) { super(plugin); this.plugin = plugin; @@ -89,6 +103,13 @@ public CommandHandler(AdvancedCorePlugin plugin, String[] args, String perm, Str setAllowMultiplePermissions(plugin.getOptions().isMultiplePermissionChecks()); } + /** + * Instantiates a new command handler. + * + * @param args the args + * @param perm the permission + * @deprecated Use constructor with plugin parameter + */ @Deprecated public CommandHandler(String[] args, String perm) { super(AdvancedCorePlugin.getInstance(), args, perm); @@ -98,6 +119,14 @@ public CommandHandler(String[] args, String perm) { } + /** + * Instantiates a new command handler. + * + * @param args the args + * @param perm the permission + * @param helpMessage the help message + * @deprecated Use constructor with plugin parameter + */ @Deprecated public CommandHandler(String[] args, String perm, String helpMessage) { super(AdvancedCorePlugin.getInstance(), args, perm, helpMessage); @@ -105,6 +134,15 @@ public CommandHandler(String[] args, String perm, String helpMessage) { setAllowMultiplePermissions(plugin.getOptions().isMultiplePermissionChecks()); } + /** + * Instantiates a new command handler. + * + * @param args the args + * @param perm the permission + * @param helpMessage the help message + * @param allowConsole whether console is allowed + * @deprecated Use constructor with plugin parameter + */ @Deprecated public CommandHandler(String[] args, String perm, String helpMessage, boolean allowConsole) { super(AdvancedCorePlugin.getInstance(), args, perm, helpMessage, allowConsole); @@ -112,6 +150,16 @@ public CommandHandler(String[] args, String perm, String helpMessage, boolean al setAllowMultiplePermissions(plugin.getOptions().isMultiplePermissionChecks()); } + /** + * Instantiates a new command handler. + * + * @param args the args + * @param perm the permission + * @param helpMessage the help message + * @param allowConsole whether console is allowed + * @param forceConsole whether to force console only + * @deprecated Use constructor with plugin parameter + */ @Deprecated public CommandHandler(String[] args, String perm, String helpMessage, boolean allowConsole, boolean forceConsole) { super(AdvancedCorePlugin.getInstance(), args, perm, helpMessage, allowConsole, forceConsole); @@ -145,6 +193,11 @@ public String getHelpLine() { return plugin.getOptions().getHelpLine(); } + /** + * Ignores number check. + * + * @return the command handler + */ @Override public CommandHandler ignoreNumberCheck() { super.ignoreNumberCheck(); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/exceptions/FileDirectoryException.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/exceptions/FileDirectoryException.java index e833d502b3..6ab43d6da8 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/exceptions/FileDirectoryException.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/exceptions/FileDirectoryException.java @@ -1,20 +1,42 @@ package com.bencodez.advancedcore.api.exceptions; +/** + * Exception for file directory errors. + */ public class FileDirectoryException extends Exception { private static final long serialVersionUID = 3691439344307857655L; + /** + * Constructor for FileDirectoryException. + */ public FileDirectoryException() { } + /** + * Constructor for FileDirectoryException with message. + * + * @param message the error message + */ public FileDirectoryException(String message) { super(message); } + /** + * Constructor for FileDirectoryException with message and cause. + * + * @param message the error message + * @param cause the cause + */ public FileDirectoryException(String message, Throwable cause) { super(message, cause); } + /** + * Constructor for FileDirectoryException with cause. + * + * @param cause the cause + */ public FileDirectoryException(Throwable cause) { super(cause); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIHandler.java index 44a9457a21..052f8a47b1 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIHandler.java @@ -15,35 +15,88 @@ import lombok.Getter; import net.md_5.bungee.api.chat.TextComponent; +/** + * Abstract handler for GUI operations supporting multiple display methods. + */ public abstract class GUIHandler { + /** + * @return the data map for storing GUI-related information + */ @Getter private HashMap data = new HashMap<>(); + /** + * @return the command sender viewing the GUI + */ @Getter private CommandSender player; + /** + * @return the plugin instance + */ @Getter private AdvancedCorePlugin plugin; + /** + * Constructs a new GUIHandler. + * + * @param plugin the plugin instance + * @param player the command sender + */ public GUIHandler(AdvancedCorePlugin plugin, CommandSender player) { this.plugin = plugin; this.player = player; } + /** + * Colorizes the given string. + * + * @param str the string to colorize + * @return the colorized string + */ public String colorize(String str) { return MessageAPI.colorize(str); } + /** + * Gets the chat representation of the GUI. + * + * @param sender the command sender + * @return the list of chat messages + */ public abstract ArrayList getChat(CommandSender sender); + /** + * Opens the GUI as a book for the player. + * + * @param player the player + */ public abstract void onBook(Player player); + /** + * Opens the GUI as chat messages for the command sender. + * + * @param player the command sender + */ public abstract void onChat(CommandSender player); + /** + * Opens the GUI as a chest inventory for the player. + * + * @param player the player + */ public abstract void onChest(Player player); + /** + * Opens the GUI using the default method. + */ public abstract void open(); + /** + * Opens the GUI using the specified method. + * + * @param method the GUI method to use + */ public void open(GUIMethod method) { if (player instanceof Player) { switch (method) { @@ -65,6 +118,11 @@ public void open(GUIMethod method) { } } + /** + * Sends messages to the command sender. + * + * @param message the list of messages to send + */ public void sendMessage(ArrayList message) { if (player instanceof Player) { AdvancedCoreUser user = plugin.getUserManager().getUser((Player) player); @@ -74,6 +132,11 @@ public void sendMessage(ArrayList message) { } } + /** + * Sends messages to the command sender. + * + * @param message the messages to send + */ public void sendMessage(String... message) { if (player instanceof Player) { AdvancedCoreUser user = plugin.getUserManager().getUser((Player) player); @@ -83,6 +146,11 @@ public void sendMessage(String... message) { } } + /** + * Sends JSON text components to the command sender. + * + * @param text the text components to send + */ public void sendMessageJson(ArrayList text) { if (player instanceof Player) { AdvancedCoreUser user = plugin.getUserManager().getUser((Player) player); @@ -92,6 +160,12 @@ public void sendMessageJson(ArrayList text) { } } + /** + * Sets data in the data map. + * + * @param str the key + * @param value the value to set + */ public void setData(String str, Object value) { data.put(str, value); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIMethod.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIMethod.java index 5a35ff467f..78d73b31b4 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIMethod.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/gui/GUIMethod.java @@ -1,5 +1,19 @@ package com.bencodez.advancedcore.api.gui; +/** + * Enum for GUI display methods. + */ public enum GUIMethod { - BOOK, CHAT, CHEST; + /** + * Book GUI method. + */ + BOOK, + /** + * Chat GUI method. + */ + CHAT, + /** + * Chest GUI method. + */ + CHEST; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/Hologram.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/Hologram.java index 5092dfff32..b4769ccbd9 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/Hologram.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/Hologram.java @@ -14,12 +14,27 @@ import lombok.Getter; +/** + * Represents a hologram using armor stands. + */ public class Hologram { + /** + * @return the armor stand entity + */ @Getter private ArmorStand armorStand; + /** + * @return the location of the hologram + */ @Getter private Location loc; + /** + * Creates a new hologram at the specified location with the given name. + * + * @param loc the location + * @param name the hologram name + */ public Hologram(Location loc, String name) { this.loc = loc; if (!Bukkit.isPrimaryThread()) { @@ -39,6 +54,13 @@ public void run() { AdvancedCorePlugin.getInstance().getHologramHandler().add(this); } + /** + * Creates a new hologram with marker setting. + * + * @param loc the location + * @param name the hologram name + * @param marker whether to set as marker + */ public Hologram(Location loc, String name, boolean marker) { this.loc = loc; if (!Bukkit.isPrimaryThread()) { @@ -57,6 +79,14 @@ public void run() { AdvancedCorePlugin.getInstance().getHologramHandler().add(this); } + /** + * Creates a new hologram with marker and glowing settings. + * + * @param loc the location + * @param name the hologram name + * @param marker whether to set as marker + * @param glowing whether the hologram should glow + */ public Hologram(Location loc, String name, boolean marker, boolean glowing) { this.loc = loc; if (!Bukkit.isPrimaryThread()) { @@ -75,6 +105,16 @@ public void run() { AdvancedCorePlugin.getInstance().getHologramHandler().add(this); } + /** + * Creates a new hologram with persistent data. + * + * @param loc the location + * @param name the hologram name + * @param marker whether to set as marker + * @param glowing whether the hologram should glow + * @param key the namespaced key for persistent data + * @param value the persistent data value + */ public Hologram(Location loc, String name, boolean marker, boolean glowing, NamespacedKey key, int value) { this.loc = loc; if (!Bukkit.isPrimaryThread()) { @@ -93,6 +133,18 @@ public void run() { AdvancedCorePlugin.getInstance().getHologramHandler().add(this); } + /** + * Creates a new hologram with persistent data and entity metadata. + * + * @param loc the location + * @param name the hologram name + * @param marker whether to set as marker + * @param glowing whether the hologram should glow + * @param key the namespaced key for persistent data + * @param value the persistent data value + * @param str the metadata key + * @param value1 the metadata value + */ public Hologram(Location loc, String name, boolean marker, boolean glowing, NamespacedKey key, int value, String str, Object value1) { this.loc = loc; @@ -164,24 +216,47 @@ private void createHologram(String name, boolean marker, boolean glowing, Namesp MiscUtils.getInstance().setEntityMeta(armorStand, str, object); } + /** + * Gets the persistent data container of the armor stand. + * + * @return the persistent data container + */ public PersistentDataContainer getPersistentDataHolder() { return armorStand.getPersistentDataContainer(); } + /** + * Sets the glowing state of the hologram. + * + * @param value whether the hologram should glow + */ public void glow(boolean value) { if (armorStand != null) { armorStand.setGlowing(value); } } + /** + * Checks if the hologram is alive. + * + * @return true if the armor stand is not dead, false otherwise + */ public boolean isAlive() { return !armorStand.isDead(); } + /** + * Checks if the hologram has been created. + * + * @return true if the armor stand exists, false otherwise + */ public boolean isCreated() { return armorStand != null; } + /** + * Kills and removes the hologram. + */ public void kill() { if (!Bukkit.isPrimaryThread()) { AdvancedCorePlugin.getInstance().getBukkitScheduler() diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/HologramHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/HologramHandler.java index 735f24f992..3431ca32d9 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/HologramHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/hologram/HologramHandler.java @@ -4,20 +4,36 @@ import com.bencodez.advancedcore.AdvancedCorePlugin; +/** + * Handler for managing holograms. + */ public class HologramHandler { private ArrayList list; @SuppressWarnings("unused") private AdvancedCorePlugin plugin; + /** + * Constructs a new HologramHandler. + * + * @param plugin the plugin instance + */ public HologramHandler(AdvancedCorePlugin plugin) { this.plugin = plugin; list = new ArrayList<>(); } + /** + * Adds a hologram to the handler. + * + * @param hologram the hologram to add + */ public void add(Hologram hologram) { list.add(hologram); } + /** + * Called on shutdown to clean up all holograms. + */ public void onShutDown() { for (Hologram hologram : list) { hologram.kill(); @@ -25,10 +41,21 @@ public void onShutDown() { list = new ArrayList<>(); } + /** + * Removes a hologram from the handler and kills it. + * + * @param hologram the hologram to remove + */ public void remove(Hologram hologram) { remove(hologram, true); } + /** + * Removes a hologram from the handler. + * + * @param hologram the hologram to remove + * @param kill whether to kill the hologram + */ public void remove(Hologram hologram, boolean kill) { if (kill) { hologram.kill(); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventory.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventory.java index e8c6fea146..fb1b56ad9b 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventory.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventory.java @@ -40,27 +40,68 @@ public class BInventory { */ public class ClickEvent { + /** + * The button that was clicked. + * + * @return the button + */ @Getter private BInventoryButton button; + /** + * The click type. + * + * @return the click type + */ @Getter private ClickType click; + /** + * The clicked item. + * + * @return the clicked item + */ @Getter private ItemStack clickedItem; + /** + * The inventory click event. + * + * @return the inventory click event + */ @Getter private InventoryClickEvent event; + /** + * The inventory. + * + * @return the inventory + */ @Getter private Inventory inventory; + /** + * The player who clicked. + * + * @return the player + */ @Getter private Player player; + /** + * The slot that was clicked. + * + * @return the slot number + */ @Getter private int slot; + /** + * Instantiates a new click event. + * + * @param event the inventory click event + * @param b the button + */ public ClickEvent(InventoryClickEvent event, BInventoryButton b) { this.event = event; player = (Player) event.getWhoClicked(); @@ -71,6 +112,9 @@ public ClickEvent(InventoryClickEvent event, BInventoryButton b) { button = b; } + /** + * Close the inventory for the player. + */ public void closeInventory() { runSync(new Runnable() { @@ -122,6 +166,11 @@ public Player getWhoClicked() { return player; } + /** + * Run a task synchronously. + * + * @param run the runnable to execute + */ public void runSync(Runnable run) { AdvancedCorePlugin.getInstance().getBukkitScheduler().runTask(AdvancedCorePlugin.getInstance(), run); } @@ -139,6 +188,11 @@ public static void openInventory(Player player, BInventory inventory) { private Map buttons = new HashMap<>(); + /** + * Whether the inventory should close after interaction. + * + * @return whether the inventory should close + */ @Getter private boolean closeInv = true; @@ -148,17 +202,33 @@ public static void openInventory(Player player, BInventory inventory) { private String inventoryName; + /** + * The last time a button was pressed in this inventory. + * + * @return the last press time in milliseconds + * @param lastPressTime the last press time to set + */ @Getter @Setter private long lastPressTime = 0; private int maxInvSize = 54; + /** + * The maximum page number for paginated inventories. + * + * @return the maximum page number + */ @Getter private int maxPage = 1; private ItemStack nextItem; + /** + * The current page number for paginated inventories. + * + * @return the current page number + */ @Getter private int page = 1; @@ -168,9 +238,20 @@ public static void openInventory(Player player, BInventory inventory) { private String perm; + /** + * Placeholders to be replaced in the inventory. + * + * @return the placeholder map + */ @Getter private HashMap placeholders = new HashMap<>(); + /** + * Whether to play sound on inventory interaction. + * + * @return whether sound should play + * @param playerSound whether sound should play + */ @Getter @Setter private boolean playerSound = true; @@ -232,6 +313,12 @@ public void onClick(ClickEvent clickEvent) { } } + /** + * Check if a slot is taken by a button. + * + * @param slot the slot to check + * @return true if the slot is taken + */ public boolean isSlotTaken(int slot) { return buttons.containsKey(slot); } @@ -246,6 +333,13 @@ public void addButton(int position, BInventoryButton button) { getButtons().put(position, button); } + /** + * Add data to this inventory. + * + * @param key the key + * @param object the value + * @return this inventory + */ public BInventory addData(String key, Object object) { getData().put(key, object); return this; @@ -276,11 +370,26 @@ public void onClick(ClickEvent clickEvent) { fillItems.clear(); } + /** + * Add a placeholder to this inventory. + * + * @param toReplace the string to replace + * @param replaceWith the replacement string + * @return this inventory + */ public BInventory addPlaceholder(String toReplace, String replaceWith) { placeholders.put(toReplace, replaceWith); return this; } + /** + * Add an updating button with scheduled updates. + * + * @param plugin the plugin instance + * @param delay the initial delay + * @param interval the update interval + * @param runnable the runnable to execute + */ public void addUpdatingButton(AdvancedCorePlugin plugin, long delay, long interval, Runnable runnable) { if (futures == null) { futures = new ArrayList<>(); @@ -288,6 +397,9 @@ public void addUpdatingButton(AdvancedCorePlugin plugin, long delay, long interv futures.add(plugin.getInventoryTimer().scheduleWithFixedDelay(runnable, delay, delay, TimeUnit.MILLISECONDS)); } + /** + * Cancel all scheduled timers for this inventory. + */ @SuppressWarnings("rawtypes") public void cancelTimer() { if (futures != null) { @@ -298,6 +410,12 @@ public void cancelTimer() { } } + /** + * Close the inventory for a player after button click. + * + * @param p the player + * @param b the button that was clicked + */ public void closeInv(Player p, BInventoryButton b) { if (!PlayerUtils.getTopInventory(p).equals(inv)) { return; @@ -318,11 +436,21 @@ private void closeUpdatingBInv() { cancelTimer(); } + /** + * Set this inventory to not close after interaction. + * + * @return this inventory + */ public BInventory dontClose() { closeInv = false; return this; } + /** + * Force close the inventory for a player. + * + * @param p the player + */ public void forceClose(Player p) { if (Bukkit.isPrimaryThread()) { p.closeInventory(); @@ -364,10 +492,23 @@ public HashMap getData() { return data; } + /** + * Get data by key. + * + * @param key the key + * @return the data value + */ public Object getData(String key) { return data.get(key); } + /** + * Get data by key with default value. + * + * @param key the key + * @param defaultValue the default value if key is not found + * @return the data value or default value + */ public Object getData(String key, Object defaultValue) { if (data.containsKey(key)) { return data.get(key); @@ -375,6 +516,11 @@ public Object getData(String key, Object defaultValue) { return defaultValue; } + /** + * Get the first empty slot in the inventory. + * + * @return the first empty slot number + */ public int getFirstEmptySlot() { if (buttons.keySet().size() == 0) { return 0; @@ -429,6 +575,13 @@ public int getMaxInvSize() { return maxInvSize; } + /** + * Get meta from player. + * + * @param player the player + * @param str the meta key + * @return the meta value + */ public Object getMeta(Player player, String str) { return PlayerUtils.getPlayerMeta(AdvancedCorePlugin.getInstance(), player, str); } @@ -483,6 +636,12 @@ private int getProperSize(int size) { } } + /** + * Check if the inventory is open for a player. + * + * @param p the player + * @return true if the inventory is open + */ public boolean isOpen(Player p) { GUISession session = GUISession.extractSession(p); if (session != null && session.getInventoryGUI() == this) { @@ -498,11 +657,22 @@ public boolean isPages() { return pages; } + /** + * Disable sound for this inventory. + * + * @return this inventory + */ public BInventory noSound() { playerSound = false; return this; } + /** + * Handle button click. + * + * @param event the inventory click event + * @param b the button that was clicked + */ public void onClick(InventoryClickEvent event, BInventoryButton b) { playSound((Player) event.getWhoClicked()); b.onClick(new ClickEvent(event, b), this); @@ -643,6 +813,11 @@ public void openInventory(Player player, int page) { openInv(player, inv); } + /** + * Play sound for a player. + * + * @param player the player + */ public void playSound(Player player) { if (playerSound) { Sound sound = AdvancedCorePlugin.getInstance().getOptions().getClickSoundSound(); @@ -654,6 +829,11 @@ public void playSound(Player player) { } } + /** + * Require permission to open this inventory. + * + * @param permission the permission required + */ public void requirePermission(String permission) { this.perm = permission; } @@ -665,6 +845,12 @@ public void setButtons(Map buttons) { this.buttons = buttons; } + /** + * Set whether the inventory should close after interaction. + * + * @param value whether to close + * @return this inventory + */ public BInventory setCloseInv(boolean value) { closeInv = value; return this; diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryButton.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryButton.java index 1b94ec2159..fef56247ff 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryButton.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryButton.java @@ -27,17 +27,38 @@ public abstract class BInventoryButton { /** The item. */ private ItemBuilder builder; + /** + * Whether the inventory should close after interaction. + * + * @return whether the inventory should close + */ @Getter private boolean closeInv = true; + /** + * Whether closeInv has been explicitly set. + * + * @return whether closeInv has been set + */ @Getter private boolean closeInvSet = false; private HashMap data = new HashMap<>(); + /** + * The fill slots for this button. + * + * @return the fill slots list + */ @Getter private List fillSlots; + /** + * The inventory this button belongs to. + * + * @return the inventory + * @param inv the inventory to set + */ @Getter @Setter private BInventory inv; @@ -45,15 +66,30 @@ public abstract class BInventoryButton { /** The slot. */ private int slot = -1; + /** + * Whether to fill empty slots with this button. + * + * @return whether to fill empty slots + */ @Getter private boolean fillEmptySlots = false; + /** + * Instantiates a new BInventory button from an existing button. + * + * @param button the button to copy + */ public BInventoryButton(BInventoryButton button) { setBuilder(button.getBuilder()); slot = button.getSlot(); fillSlots = button.getFillSlots(); } + /** + * Instantiates a new BInventory button from an item builder. + * + * @param item the item builder + */ public BInventoryButton(ItemBuilder item) { setBuilder(item); slot = item.getSlot(); @@ -65,6 +101,11 @@ public BInventoryButton(ItemBuilder item) { } } + /** + * Instantiates a new BInventory button from an item stack. + * + * @param item the item stack + */ public BInventoryButton(ItemStack item) { setBuilder(new ItemBuilder(item)); } @@ -80,11 +121,23 @@ public BInventoryButton(String name, String[] lore, ItemStack item) { setBuilder(new ItemBuilder(item).setName(name).setLore(lore)); } + /** + * Add data to this button. + * + * @param key the key + * @param object the value + * @return this button + */ public BInventoryButton addData(String key, Object object) { getData().put(key, object); return this; } + /** + * Set this button to not close the inventory after click. + * + * @return this button + */ public BInventoryButton dontClose() { closeInv = false; return this; @@ -97,6 +150,11 @@ public ItemBuilder getBuilder() { return builder; } + /** + * Get this button. + * + * @return this button + */ public BInventoryButton getButton() { return this; } @@ -108,10 +166,23 @@ public HashMap getData() { return data; } + /** + * Get data by key. + * + * @param key the key + * @return the data value + */ public Object getData(String key) { return data.get(key); } + /** + * Get data by key with default value. + * + * @param key the key + * @param defaultValue the default value if key is not found + * @return the data value or default value + */ public Object getData(String key, Object defaultValue) { if (data.containsKey(key)) { return data.get(key); @@ -131,19 +202,45 @@ public ItemStack getItem() { return builder.toItemStack(); } + /** + * Gets the item. + * + * @param player the player + * @return the item + */ public ItemStack getItem(Player player) { return builder.toItemStack(player); } + /** + * Gets the item with placeholders. + * + * @param player the player + * @param placeholders the placeholders + * @return the item + */ public ItemStack getItem(Player player, HashMap placeholders) { return builder.addPlaceholder(placeholders).toItemStack(player); } + /** + * Get the last rewards path for a player. + * + * @param player the player + * @return the rewards path + */ public String getLastRewardsPath(Player player) { String test = builder.getRewardsPath(player); return test; } + /** + * Get meta from player. + * + * @param player the player + * @param str the meta key + * @return the meta value + */ public Object getMeta(Player player, String str) { return PlayerUtils.getPlayerMeta(AdvancedCorePlugin.getInstance(), player, str); } @@ -157,6 +254,11 @@ public int getSlot() { return slot; } + /** + * Load this button for a player. + * + * @param p the player + */ public void load(Player p) { } @@ -167,11 +269,23 @@ public void load(Player p) { */ public abstract void onClick(ClickEvent clickEvent); + /** + * On click with inventory. + * + * @param event the click event + * @param inv the inventory + */ public void onClick(ClickEvent event, BInventory inv) { this.inv = inv; onClick(event); } + /** + * Send a message to a player. + * + * @param player the player + * @param msg the message + */ public void sendMessage(Player player, String msg) { player.sendMessage(MessageAPI.colorize(msg)); } @@ -183,12 +297,23 @@ public void setBuilder(ItemBuilder builder) { this.builder = builder; } + /** + * Set whether the inventory should close after interaction. + * + * @param value whether to close + * @return this button + */ public BInventoryButton setCloseInv(boolean value) { closeInv = value; closeInvSet = true; return this; } + /** + * Sets the item. + * + * @param builder the builder + */ public void setItem(ItemBuilder builder) { this.builder = builder; } @@ -202,6 +327,13 @@ public void setItem(ItemStack item) { builder = new ItemBuilder(item); } + /** + * Set meta for a player. + * + * @param player the player + * @param str the meta key + * @param ob the meta value + */ public void setMeta(Player player, String str, Object ob) { PlayerUtils.setPlayerMeta(AdvancedCorePlugin.getInstance(), player, str, ob); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryListener.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryListener.java index 238c3188c0..6e6dc705c5 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryListener.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/BInventoryListener.java @@ -13,13 +13,26 @@ import com.bencodez.advancedcore.AdvancedCorePlugin; import com.bencodez.simpleapi.messages.MessageAPI; +/** + * Listener for inventory interactions. + */ public class BInventoryListener implements Listener { private AdvancedCorePlugin plugin; + /** + * Instantiates a new BInventory listener. + * + * @param plugin the plugin instance + */ public BInventoryListener(AdvancedCorePlugin plugin) { this.plugin = plugin; } + /** + * Handle inventory click events. + * + * @param event the inventory click event + */ @EventHandler(priority = EventPriority.LOWEST) public void onInventoryClick(InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof Player)) { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/GUISession.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/GUISession.java index 3d377e2cd7..9bd8033218 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/GUISession.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/GUISession.java @@ -7,6 +7,9 @@ import com.bencodez.simpleapi.player.PlayerUtils; +/** + * Session holder for managing GUI state across inventory interactions. + */ public class GUISession implements InventoryHolder { /** * Get the GUISession for a given inventory, or null if none exists for this diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUI.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUI.java index 64d90f1957..8719af591e 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUI.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUI.java @@ -9,12 +9,23 @@ import com.bencodez.advancedcore.api.inventory.BInventory; import com.bencodez.advancedcore.api.inventory.BInventoryButton; +/** + * Edit GUI for sorting and organizing edit buttons. + */ public class EditGUI extends BInventory { + /** + * Constructor for EditGUI. + * + * @param name the inventory name + */ public EditGUI(String name) { super(name); } + /** + * Sorts the edit buttons alphabetically by key. + */ public void sort() { Map map = getButtons(); setButtons(new HashMap<>()); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIButton.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIButton.java index db2d5e365f..b4ee42e61b 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIButton.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIButton.java @@ -18,27 +18,59 @@ import lombok.Getter; import lombok.Setter; +/** + * Button for editing GUI values. + */ public class EditGUIButton extends BInventoryButton { + /** + * The editor for this button. + * + * @return the editor + * @param editor the editor + */ @Getter @Setter private EditGUIValue editor; + /** + * Constructor for EditGUIButton. + * + * @param editer the GUI value editor + */ public EditGUIButton(EditGUIValue editer) { super(new ItemBuilder(Material.PAPER)); this.editor = editer; } + /** + * Constructor for EditGUIButton with custom item. + * + * @param item the item builder + * @param editer the GUI value editor + */ public EditGUIButton(ItemBuilder item, EditGUIValue editer) { super(item); this.editor = editer; } + /** + * Adds a lore line to the button. + * + * @param lore the lore line + * @return this instance + */ public EditGUIButton addLore(String lore) { getEditor().addLore(lore); return this; } + /** + * Adds options to the button. + * + * @param str the options + * @return this instance + */ public EditGUIButton addOptions(String... str) { getEditor().addOptions(str); return this; @@ -84,6 +116,12 @@ public void onClick(ClickEvent clickEvent) { getEditor().onClick(clickEvent); } + /** + * Sets the name of the button. + * + * @param name the name + * @return this instance + */ public EditGUIButton setName(String name) { this.getBuilder().setName(name); return this; diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIValueType.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIValueType.java index 2b5f20c3ed..0e199cdced 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIValueType.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/EditGUIValueType.java @@ -1,5 +1,21 @@ package com.bencodez.advancedcore.api.inventory.editgui; +/** + * Enum representing different types of editable GUI values. + */ public enum EditGUIValueType { - BOOLEAN, CONFIGURATIONSECTION, DOUBLE, INT, LIST, NUMBER, STRING; + /** Boolean value type */ + BOOLEAN, + /** Configuration section value type */ + CONFIGURATIONSECTION, + /** Double value type */ + DOUBLE, + /** Integer value type */ + INT, + /** List value type */ + LIST, + /** Number value type */ + NUMBER, + /** String value type */ + STRING; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValue.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValue.java index 78051ba6de..e09be6e1ed 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValue.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValue.java @@ -10,34 +10,84 @@ import lombok.Getter; import lombok.Setter; +/** + * Abstract base class for GUI edit values. + */ public abstract class EditGUIValue { + /** + * Whether the value can be retrieved. + * + * @return whether the value can be retrieved + * @param canGetValue whether the value can be retrieved + */ @Getter @Setter private boolean canGetValue = true; + /** + * The current value. + * + * @return the current value + * @param currentValue the current value + */ @Getter @Setter private Object currentValue; + /** + * The input method. + * + * @return the input method + * @param inputMethod the input method + */ @Getter @Setter private InputMethod inputMethod; + /** + * The inventory. + * + * @return the inventory + * @param inv the inventory + */ @Getter @Setter private BInventory inv; + /** + * The key. + * + * @return the key + * @param key the key + */ @Getter @Setter private String key; + /** + * The lore lines. + * + * @return the lore lines + * @param lores the lore lines + */ @Getter @Setter private ArrayList lores; + /** + * The options. + * + * @return the options + */ @Getter private ArrayList options = new ArrayList<>(); + /** + * Adds lore lines to this value. + * + * @param lore the lore lines to add + * @return this instance + */ public EditGUIValue addLore(ArrayList lore) { if (lores == null) { lores = new ArrayList<>(); @@ -46,6 +96,12 @@ public EditGUIValue addLore(ArrayList lore) { return this; } + /** + * Adds a lore line to this value. + * + * @param lore the lore line to add + * @return this instance + */ public EditGUIValue addLore(String lore) { if (lores == null) { lores = new ArrayList<>(); @@ -54,6 +110,12 @@ public EditGUIValue addLore(String lore) { return this; } + /** + * Adds options to this value. + * + * @param str the options to add + * @return this instance + */ public EditGUIValue addOptions(String... str) { for (String s : str) { options.add(s); @@ -61,16 +123,38 @@ public EditGUIValue addOptions(String... str) { return this; } + /** + * Checks if the reward edit data contains this key. + * + * @param rewardEditData the reward edit data + * @return true if key exists + */ public boolean containsKey(RewardEditData rewardEditData) { return rewardEditData.hasPath(getKey()); } + /** + * Gets the type of this value. + * + * @return the type + */ public abstract String getType(); + /** + * Sets the input method for this value. + * + * @param inputMethod the input method + * @return this instance + */ public EditGUIValue inputMethod(InputMethod inputMethod) { this.inputMethod = inputMethod; return this; } + /** + * Handles click events for this value. + * + * @param event the click event + */ public abstract void onClick(ClickEvent event); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueBoolean.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueBoolean.java index 2410a9d6c2..7d26f214ab 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueBoolean.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueBoolean.java @@ -7,7 +7,16 @@ import com.bencodez.advancedcore.api.valuerequest.listeners.BooleanListener; import com.bencodez.simpleapi.messages.MessageAPI; +/** + * Abstract GUI value for boolean editing. + */ public abstract class EditGUIValueBoolean extends EditGUIValue { + /** + * Constructor for EditGUIValueBoolean. + * + * @param key the key + * @param value the initial value + */ public EditGUIValueBoolean(String key, Object value) { setKey(key); setCurrentValue(value); @@ -33,6 +42,12 @@ public void onInput(Player player, boolean value) { }).currentValue(getCurrentValue().toString()).usingMethod(getInputMethod()).request(clickEvent.getPlayer()); } + /** + * Sets the boolean value. + * + * @param player the player + * @param value the value to set + */ public abstract void setValue(Player player, boolean value); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueInventory.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueInventory.java index 10fd00b403..7856fb1e59 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueInventory.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueInventory.java @@ -4,15 +4,29 @@ import com.bencodez.advancedcore.api.inventory.BInventory.ClickEvent; +/** + * Abstract GUI value for inventory editing. + */ public abstract class EditGUIValueInventory extends EditGUIValue { private ArrayList keys = new ArrayList<>(); + /** + * Constructor for EditGUIValueInventory. + * + * @param key the key + */ public EditGUIValueInventory(String key) { setKey(key); setCanGetValue(false); keys.add(key); } + /** + * Adds a check key. + * + * @param key the key to add + * @return this instance + */ public EditGUIValueInventory addCheckKey(String key) { keys.add(key); return this; @@ -28,6 +42,11 @@ public void onClick(ClickEvent clickEvent) { openInventory(clickEvent); } + /** + * Opens the inventory for editing. + * + * @param clickEvent the click event + */ public abstract void openInventory(ClickEvent clickEvent); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueList.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueList.java index 5795757f3e..6fee4c9c5c 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueList.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueList.java @@ -14,7 +14,16 @@ import com.bencodez.advancedcore.api.valuerequest.listeners.Listener; import com.bencodez.simpleapi.array.ArrayUtils; +/** + * Abstract GUI value for list editing. + */ public abstract class EditGUIValueList extends EditGUIValue { + /** + * Constructor for EditGUIValueList. + * + * @param key the key + * @param value the initial value + */ public EditGUIValueList(String key, Object value) { setKey(key); setCurrentValue(value); @@ -77,5 +86,11 @@ public void onInput(Player player, String add) { inv.openInventory(clickEvent.getPlayer()); } + /** + * Sets the list value. + * + * @param player the player + * @param value the list to set + */ public abstract void setValue(Player player, ArrayList value); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueNumber.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueNumber.java index 8e1b4b0169..84226df5aa 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueNumber.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueNumber.java @@ -7,8 +7,17 @@ import com.bencodez.advancedcore.api.valuerequest.listeners.Listener; import com.bencodez.simpleapi.messages.MessageAPI; +/** + * Abstract GUI value for number editing. + */ public abstract class EditGUIValueNumber extends EditGUIValue { + /** + * Constructor for EditGUIValueNumber. + * + * @param key the key + * @param value the initial value + */ public EditGUIValueNumber(String key, Object value) { setKey(key); setCurrentValue(value); @@ -36,5 +45,11 @@ public void onInput(Player player, Number number) { .request(clickEvent.getPlayer()); } + /** + * Sets the number value. + * + * @param player the player + * @param num the number to set + */ public abstract void setValue(Player player, Number num); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueString.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueString.java index 70ad95c55f..1626053894 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueString.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/inventory/editgui/valuetypes/EditGUIValueString.java @@ -8,8 +8,17 @@ import com.bencodez.simpleapi.array.ArrayUtils; import com.bencodez.simpleapi.messages.MessageAPI; +/** + * Abstract GUI value for string editing. + */ public abstract class EditGUIValueString extends EditGUIValue { + /** + * Constructor for EditGUIValueString. + * + * @param key the key + * @param value the initial value + */ public EditGUIValueString(String key, Object value) { setKey(key); setCurrentValue(value); @@ -35,5 +44,11 @@ public void onInput(Player player, String value) { .usingMethod(getInputMethod()).request(clickEvent.getPlayer()); } + /** + * Sets the string value. + * + * @param player the player + * @param value the value to set + */ public abstract void setValue(Player player, String value); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/FullInventoryHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/FullInventoryHandler.java index 6cbbe7e868..029cdd8423 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/FullInventoryHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/FullInventoryHandler.java @@ -19,18 +19,41 @@ import lombok.Getter; +/** + * Handler for items when player inventories are full. + */ public class FullInventoryHandler { + /** + * The items waiting to be given. + * + * @return the items waiting to be given + */ @Getter private ConcurrentHashMap> items; private AdvancedCorePlugin plugin; + /** + * The timer executor service. + * + * @return the timer executor service + */ @Getter private ScheduledExecutorService timer; + /** + * The last message time for each player. + * + * @return the last message time for each player + */ @Getter private ConcurrentHashMap lastMessageTime; + /** + * Constructor for FullInventoryHandler. + * + * @param plugin the plugin instance + */ public FullInventoryHandler(AdvancedCorePlugin plugin) { items = new ConcurrentHashMap<>(); lastMessageTime = new ConcurrentHashMap<>(); @@ -39,6 +62,12 @@ public FullInventoryHandler(AdvancedCorePlugin plugin) { startup(); } + /** + * Adds multiple items for a player. + * + * @param uuid the player UUID + * @param item the items to add + */ public void add(UUID uuid, ArrayList item) { if (items.containsKey(uuid)) { ArrayList current = items.get(uuid); @@ -49,6 +78,12 @@ public void add(UUID uuid, ArrayList item) { } } + /** + * Adds a single item for a player. + * + * @param uuid the player UUID + * @param item the item to add + */ public void add(UUID uuid, ItemStack item) { if (items.containsKey(uuid)) { ArrayList current = items.get(uuid); @@ -61,6 +96,9 @@ public void add(UUID uuid, ItemStack item) { } } + /** + * Checks all players for pending items. + */ public void check() { for (UUID entry : items.keySet()) { Player p = Bukkit.getPlayer(entry); @@ -73,6 +111,11 @@ public void check() { } } + /** + * Checks a specific player for pending items. + * + * @param p the player + */ public void check(Player p) { if (p != null && items.containsKey(p.getUniqueId())) { ArrayList extra = new ArrayList<>(); @@ -90,6 +133,12 @@ public void check(Player p) { } } + /** + * Gives items to a player. + * + * @param p the player + * @param item the items to give + */ public void giveItem(Player p, ItemStack... item) { HashMap excess = p.getInventory().addItem(item); boolean full = false; @@ -117,6 +166,9 @@ public void giveItem(Player p, ItemStack... item) { p.updateInventory(); } + /** + * Loads the timer for checking inventories. + */ public void loadTimer() { timer = Executors.newScheduledThreadPool(1); timer.scheduleAtFixedRate(new Runnable() { @@ -128,6 +180,9 @@ public void run() { }, 10, 30, TimeUnit.SECONDS); } + /** + * Saves pending items to disk. + */ public void save() { try { if (plugin.getServerDataFile().getData() == null) { @@ -155,6 +210,9 @@ private void sendMessage(Player p) { } } + /** + * Loads pending items from disk on startup. + */ public void startup() { try { if (plugin.getServerDataFile().getData() == null diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemBuilder.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemBuilder.java index fc788656fe..28e8a8fc84 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemBuilder.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemBuilder.java @@ -450,6 +450,11 @@ public ItemBuilder(Material material, int amount) { is = new ItemStack(material, amount); } + /** + * Constructs an ItemBuilder from a material string. + * + * @param material the material name + */ public ItemBuilder(String material) { String materialStr = material; if (NMSManager.getInstance().isVersion("1.12")) { @@ -467,6 +472,13 @@ public ItemBuilder(String material) { } } + /** + * Adds an attribute modifier to the item. + * + * @param att the attribute + * @param modifier the attribute modifier + * @return this ItemBuilder + */ public ItemBuilder addAttributeModifier(Attribute att, AttributeModifier modifier) { ItemMeta im = is.getItemMeta(); im.addAttributeModifier(att, modifier); @@ -552,6 +564,11 @@ public ItemBuilder addEnchantments(Map enchantments) { return this; } + /** + * Adds a glow effect to the item. + * + * @return this ItemBuilder + */ public ItemBuilder addGlow() { ItemMeta meta = is.getItemMeta(); @@ -575,6 +592,12 @@ public ItemBuilder addGlow() { return this; } + /** + * Adds an item flag to the item. + * + * @param flag the flag name + * @return this ItemBuilder + */ public ItemBuilder addItemFlag(String flag) { try { ItemMeta meta = is.getItemMeta(); @@ -626,6 +649,12 @@ public ItemBuilder addLoreLine(String line, int pos) { return this; } + /** + * Adds a placeholder mapping. + * + * @param placeholders the map of placeholders + * @return this ItemBuilder + */ public ItemBuilder addPlaceholder(HashMap placeholders) { if (placeholders != null) { this.placeholders.putAll(placeholders); @@ -633,11 +662,27 @@ public ItemBuilder addPlaceholder(HashMap placeholders) { return this; } + /** + * Adds a single placeholder. + * + * @param toReplace the text to replace + * @param replaceWith the replacement text + * @return this ItemBuilder + */ public ItemBuilder addPlaceholder(String toReplace, String replaceWith) { placeholders.put(toReplace, replaceWith); return this; } + /** + * Adds a potion effect to the item. + * + * @param type the potion effect type + * @param duration the duration + * @param amplifier the amplifier + * @param color the potion color + * @return this ItemBuilder + */ public ItemBuilder addPotionEffect(PotionEffectType type, int duration, int amplifier, Color color) { PotionMeta meta = (PotionMeta) is.getItemMeta(); meta.addCustomEffect(new PotionEffect(type, duration, amplifier), false); @@ -700,6 +745,11 @@ public ItemBuilder clone() { return new ItemBuilder(is); } + /** + * Creates configuration data from this ItemBuilder. + * + * @return the configuration data map + */ @SuppressWarnings("deprecation") public LinkedHashMap createConfigurationData() { LinkedHashMap data = new LinkedHashMap<>(); @@ -733,6 +783,11 @@ public LinkedHashMap createConfigurationData() { } + /** + * Disables lore length checking. + * + * @return this ItemBuilder + */ public ItemBuilder dontCheckLoreLength() { checkLoreLength = false; return this; @@ -752,18 +807,41 @@ private int getAmount() { return is.getAmount(); } + /** + * Gets the attribute modifiers multimap. + * + * @return the attribute modifiers + */ public Multimap getAttributeModifiers() { return is.getItemMeta().getAttributeModifiers(); } + /** + * Gets the attribute modifiers for a specific attribute. + * + * @param att the attribute + * @return the collection of attribute modifiers + */ public Collection getAttributeModifiers(Attribute att) { return is.getItemMeta().getAttributeModifiers(att); } + /** + * Gets a conditional ItemBuilder based on player conditions. + * + * @param player the player + * @return the conditional ItemBuilder or this if no conditions match + */ public ItemBuilder getConditionItemBuilder(OfflinePlayer player) { return setConditional(new JavascriptEngine().addPlayer(player)); } + /** + * Gets the configuration map. + * + * @param deseralize whether to deserialize the item + * @return the configuration map + */ @SuppressWarnings("deprecation") public Map getConfiguration(boolean deseralize) { if (deseralize) { @@ -801,6 +879,12 @@ public Map getConfiguration(boolean deseralize) { } + /** + * Checks if the ItemMeta has getItemModel method. + * + * @param meta the item meta + * @return true if the method exists, false otherwise + */ public boolean hasGetItemModel(ItemMeta meta) { try { Method method = meta.getClass().getMethod("getItemModel"); @@ -810,6 +894,12 @@ public boolean hasGetItemModel(ItemMeta meta) { } } + /** + * Gets custom data from persistent data container. + * + * @param key the data key + * @return the custom data value + */ public String getCustomData(String key) { NamespacedKey namespace = new NamespacedKey(AdvancedCorePlugin.getInstance(), key); ItemMeta itemMeta = is.getItemMeta(); @@ -820,6 +910,11 @@ public String getCustomData(String key) { return null; } + /** + * Gets the lore of the item. + * + * @return the lore list + */ public ArrayList getLore() { if (hasCustomLore()) { List lore = is.getItemMeta().getLore(); @@ -833,6 +928,11 @@ public ArrayList getLore() { } + /** + * Gets the lore length setting. + * + * @return the lore length + */ public int getLoreLength() { if (loreLength < 0) { return AdvancedCorePlugin.getInstance().getOptions().getNewLoreLength(); @@ -840,6 +940,11 @@ public int getLoreLength() { return loreLength; } + /** + * Gets the item name. + * + * @return the item name + */ public String getName() { if (hasCustomDisplayName()) { return is.getItemMeta().getDisplayName(); @@ -847,6 +952,12 @@ public String getName() { return ""; } + /** + * Gets the rewards path for the player. + * + * @param player the player + * @return the rewards path + */ public String getRewardsPath(Player player) { if (conditional) { JavascriptEngine engine = new JavascriptEngine().addPlayer(player); @@ -871,6 +982,11 @@ public String getSkull() { return ""; } + /** + * Gets the skull owner. + * + * @return the skull owner + */ public OfflinePlayer getSkullOwner() { try { SkullMeta im = (SkullMeta) is.getItemMeta(); @@ -882,14 +998,29 @@ public OfflinePlayer getSkullOwner() { return null; } + /** + * Gets the item material type. + * + * @return the material + */ public Material getType() { return is.getType(); } + /** + * Checks if the item has attributes. + * + * @return true if the item has attributes, false otherwise + */ public boolean hasAttributes() { return is.getItemMeta().hasAttributeModifiers(); } + /** + * Checks if the item has a custom display name. + * + * @return true if the item has a custom display name, false otherwise + */ public boolean hasCustomDisplayName() { if (hasItemMeta()) { return is.getItemMeta().hasDisplayName(); @@ -897,6 +1028,11 @@ public boolean hasCustomDisplayName() { return false; } + /** + * Checks if the item has custom lore. + * + * @return true if the item has lore, false otherwise + */ public boolean hasCustomLore() { if (hasItemMeta()) { return is.getItemMeta().hasLore(); @@ -904,10 +1040,21 @@ public boolean hasCustomLore() { return false; } + /** + * Checks if the item has item meta. + * + * @return true if the item has meta, false otherwise + */ public boolean hasItemMeta() { return is.hasItemMeta(); } + /** + * Parses placeholders in the item for the player. + * + * @param player the player + * @return the itemstack with parsed placeholders + */ public ItemStack parsePlaceholders(OfflinePlayer player) { if (player == null) { return toItemStack(); @@ -934,6 +1081,11 @@ public ItemBuilder removeEnchantment(Enchantment ench) { return this; } + /** + * Removes all lore from the item. + * + * @return this ItemBuilder + */ public ItemBuilder removeLore() { setLore(new String[0]); return this; @@ -975,11 +1127,23 @@ public ItemBuilder removeLoreLine(String line) { return this; } + /** + * Sets the amount of items. + * + * @param amount the amount to set + * @return this ItemBuilder + */ public ItemBuilder setAmount(int amount) { is.setAmount(amount); return this; } + /** + * Sets the amount only if current amount is zero. + * + * @param i the amount to set + * @return this ItemBuilder + */ public ItemBuilder setAmountNone(int i) { if (getAmount() == 0) { setAmount(i); @@ -1003,6 +1167,13 @@ private ItemBuilder setConditional(JavascriptEngine engine) { return null; } + /** + * Sets custom data in the persistent data container. + * + * @param key the data key + * @param value the data value + * @return this ItemBuilder + */ public ItemBuilder setCustomData(String key, String value) { NamespacedKey namespace = new NamespacedKey(AdvancedCorePlugin.getInstance(), key); ItemMeta itemMeta = is.getItemMeta(); @@ -1011,6 +1182,12 @@ public ItemBuilder setCustomData(String key, String value) { return this; } + /** + * Sets the custom model data. + * + * @param data the custom model data + * @return this ItemBuilder + */ @SuppressWarnings("deprecation") public ItemBuilder setCustomModelData(int data) { ItemMeta im = is.getItemMeta(); @@ -1045,6 +1222,12 @@ public ItemBuilder setDyeColor(DyeColor color) { return this; } + /** + * Sets the firework power. + * + * @param power the power level + * @return this ItemBuilder + */ public ItemBuilder setFireworkPower(int power) { try { FireworkMeta meta = (FireworkMeta) is.getItemMeta(); @@ -1057,6 +1240,12 @@ public ItemBuilder setFireworkPower(int power) { return this; } + /** + * Sets the skull head from base64 texture. + * + * @param value the base64 texture value + * @return this ItemBuilder + */ public ItemBuilder setHeadFromBase64(String value) { is = SkullCache.getSkullBase64(value); return this; @@ -1124,6 +1313,12 @@ public ItemBuilder setLore(String... lore) { return setLore(ArrayUtils.convert(lore)); } + /** + * Sets the lore length for wrapping. + * + * @param length the lore length + * @return this ItemBuilder + */ public ItemBuilder setLoreLength(int length) { loreLength = length; return this; @@ -1144,6 +1339,12 @@ public ItemBuilder setName(String name) { return this; } + /** + * Sets the item name only if it doesn't already have a custom display name. + * + * @param name the name to set + * @return this ItemBuilder + */ public ItemBuilder setNameIfNotExist(String name) { if (!hasCustomDisplayName()) { setName(name); @@ -1151,11 +1352,23 @@ public ItemBuilder setNameIfNotExist(String name) { return this; } + /** + * Sets the placeholder mappings. + * + * @param placeholders the placeholders map + * @return this ItemBuilder + */ public ItemBuilder setPlaceholders(HashMap placeholders) { this.placeholders = placeholders; return this; } + /** + * Sets the skull owner by offline player. + * + * @param offlinePlayer the offline player + * @return this ItemBuilder + */ public ItemBuilder setSkullOwner(OfflinePlayer offlinePlayer) { if (offlinePlayer != null) { try { @@ -1188,11 +1401,23 @@ public ItemBuilder setSkullOwner(String owner) { return this; } + /** + * Sets the slot for the item in an inventory. + * + * @param slot the slot number + * @return this ItemBuilder + */ public ItemBuilder setSlot(int slot) { this.slot = slot; return this; } + /** + * Sets whether the item is unbreakable. + * + * @param unbreakable whether the item should be unbreakable + * @return this ItemBuilder + */ public ItemBuilder setUnbreakable(boolean unbreakable) { try { ItemMeta meta = is.getItemMeta(); @@ -1229,6 +1454,12 @@ public ItemStack toItemStack() { return is; } + /** + * Converts the ItemBuilder to an ItemStack with player-specific placeholders. + * + * @param player the offline player for placeholder replacement + * @return the final itemstack + */ public ItemStack toItemStack(OfflinePlayer player) { if (!placeholders.containsKey("player")) { placeholders.put("player", player.getName()); @@ -1243,6 +1474,12 @@ public ItemStack toItemStack(OfflinePlayer player) { return is; } + /** + * Converts the ItemBuilder to an ItemStack with player-specific placeholders. + * + * @param player the player for placeholder replacement + * @return the final itemstack + */ public ItemStack toItemStack(Player player) { if (!placeholders.containsKey("player")) { placeholders.put("player", player.getName()); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemModelHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemModelHandler.java index f7893a5f8e..46bba3ecb6 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemModelHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemModelHandler.java @@ -4,7 +4,17 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +/** + * Handler for item model customization. + */ public class ItemModelHandler { + /** + * Sets a custom model on an item. + * + * @param item the item to modify + * @param model the model identifier + * @return the modified item + */ public static ItemStack getItemWithModel(ItemStack item, String model) { if (item == null || model == null || model.isEmpty()) { return item; @@ -17,6 +27,12 @@ public static ItemStack getItemWithModel(ItemStack item, String model) { return item; } + /** + * Gets the model identifier from an item. + * + * @param item the item to check + * @return the model identifier, or null if none + */ public static String getModel(ItemStack item) { if (item == null) { return null; diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemsAdderHandle.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemsAdderHandle.java index f3818110b8..2497e6e412 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemsAdderHandle.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/item/ItemsAdderHandle.java @@ -4,11 +4,23 @@ import dev.lone.itemsadder.api.CustomStack; +/** + * Handler for ItemsAdder custom items. + */ public class ItemsAdderHandle { + /** + * Creates a new ItemsAdder handler. + */ public ItemsAdderHandle() { } + /** + * Gets a custom item by its identifier. + * + * @param item the item identifier + * @return the custom ItemStack, or null if not found + */ public ItemStack getItem(String item) { CustomStack stack = CustomStack.getInstance(item); if (stack != null) { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java index 766bc3bdc4..e52141c5e2 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptEngineHandler.java @@ -8,10 +8,18 @@ import com.bencodez.simpleapi.nms.ReflectionUtils; +/** + * Handler for Javascript engine creation across different Java versions. + */ public class JavascriptEngineHandler { private static JavascriptEngineHandler instance = new JavascriptEngineHandler(); + /** + * Gets the singleton instance. + * + * @return the instance + */ public static JavascriptEngineHandler getInstance() { return instance; } @@ -22,6 +30,9 @@ public static JavascriptEngineHandler getInstance() { private Method methodToUse; + /** + * Creates a new Javascript engine handler. + */ public JavascriptEngineHandler() { if (Double.parseDouble(System.getProperty("java.specification.version")) < 15) { builtIn = true; @@ -44,6 +55,11 @@ public JavascriptEngineHandler() { } + /** + * Gets a Javascript script engine. + * + * @return the script engine + */ public ScriptEngine getJSScriptEngine() { if (builtIn) { return new ScriptEngineManager().getEngineByName("js"); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptPlaceholderRequest.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptPlaceholderRequest.java index 0dfd7d460d..6c8e3894c7 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptPlaceholderRequest.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/javascript/JavascriptPlaceholderRequest.java @@ -2,14 +2,28 @@ import org.bukkit.OfflinePlayer; +/** + * Abstract class for Javascript placeholder requests. + */ public abstract class JavascriptPlaceholderRequest { private String str; + /** + * Creates a new Javascript placeholder request. + * + * @param str the placeholder string + */ public JavascriptPlaceholderRequest(String str) { this.str = str; } + /** + * Gets the object value for the given player. + * + * @param player the player to get the value for + * @return the object value + */ public abstract Object getObject(OfflinePlayer player); /** diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/MiscUtils.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/MiscUtils.java index b8572c4f06..8174a56436 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/MiscUtils.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/MiscUtils.java @@ -46,6 +46,9 @@ import net.md_5.bungee.api.ChatColor; +/** + * Miscellaneous utility methods. + */ public class MiscUtils { /** The instance. */ static MiscUtils instance = new MiscUtils(); @@ -60,6 +63,13 @@ public static MiscUtils getInstance() { private MiscUtils() { } + /** + * Adds seconds to a date. + * + * @param date the date to add to + * @param seconds the number of seconds to add + * @return the new date + */ public Date addSeconds(Date date, int seconds) { Calendar c = Calendar.getInstance(); c.setTime(new Date()); @@ -76,6 +86,12 @@ public void broadcast(String broadcastMsg) { broadcast(broadcastMsg, new ArrayList<>(Bukkit.getOnlinePlayers())); } + /** + * Broadcasts a message to specific players. + * + * @param broadcastMsg the message to broadcast + * @param players the players to broadcast to + */ public void broadcast(String broadcastMsg, Collection players) { if (broadcastMsg != null && !broadcastMsg.equals("")) { String consoleMsg = broadcastMsg; diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/animation/AnimationAPI.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/animation/AnimationAPI.java index 4dc0a629e4..73cae897e4 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/animation/AnimationAPI.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/animation/AnimationAPI.java @@ -5,13 +5,29 @@ import java.util.Timer; import java.util.TimerTask; +/** + * API for running text animations. + */ public class AnimationAPI { + /** + * Interface for animation callbacks. + */ public interface Animation { + /** + * Called on each animation frame. + * + * @param text the text to display + */ public void onAnimate(String text); } private static AnimationAPI instance = new AnimationAPI(); + /** + * Gets the singleton instance. + * + * @return the animation API instance + */ public static AnimationAPI getInstance() { return instance; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/BossBar.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/BossBar.java index 56e11fa0d2..861b92f676 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/BossBar.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/BossBar.java @@ -19,6 +19,11 @@ */ public class BossBar { + /** + * Gets the boss bar. + * + * @return the boss bar + */ @Getter private org.bukkit.boss.BossBar bossBar; @@ -36,10 +41,21 @@ public BossBar(String msg, String barColor, String barStyle, double progress) { bossBar.setProgress(progress); } + /** + * Adds a player to the boss bar. + * + * @param player the player to add + */ public void addPlayer(Player player) { bossBar.addPlayer(player); } + /** + * Adds a player to the boss bar with delay. + * + * @param player the player to add + * @param delay the delay in seconds before removing + */ public void addPlayer(final Player player, int delay) { try { if (player == null) { @@ -64,10 +80,18 @@ public void run() { } } + /** + * Gets the players viewing the boss bar. + * + * @return the list of players + */ public List getPlayers() { return bossBar.getPlayers(); } + /** + * Hides the boss bar. + */ public void hide() { if (bossBar != null) { bossBar.setVisible(false); @@ -86,14 +110,27 @@ public void run() { }, delay * 50, TimeUnit.MILLISECONDS); } + /** + * Removes a player from the boss bar. + * + * @param player the player to remove + */ public void removePlayer(Player player) { bossBar.removePlayer(player); } + /** + * Sends the boss bar to all players. + */ public void send() { bossBar.setVisible(true); } + /** + * Sends the boss bar with delay. + * + * @param delay the delay in seconds + */ public void send(int delay) { bossBar.setVisible(true); @@ -112,12 +149,22 @@ public void send(Player player, int delay) { hideInDelay(delay); } + /** + * Sets the color of the boss bar. + * + * @param barColor the bar color + */ public void setColor(String barColor) { if (barColor != null) { bossBar.setColor(BarColor.valueOf(barColor)); } } + /** + * Sets the progress of the boss bar. + * + * @param progress the progress (0.0 to 1.0) + */ public void setProgress(double progress) { if (progress > 1) { progress = 1; @@ -128,12 +175,22 @@ public void setProgress(double progress) { bossBar.setProgress(progress); } + /** + * Sets the style of the boss bar. + * + * @param barStyle the bar style + */ public void setStyle(String barStyle) { if (barStyle != null) { bossBar.setStyle(BarStyle.valueOf(barStyle)); } } + /** + * Sets the title of the boss bar. + * + * @param title the title + */ public void setTitle(String title) { if (title != null) { bossBar.setTitle(MessageAPI.colorize(title)); @@ -141,6 +198,11 @@ public void setTitle(String title) { } + /** + * Sets the visibility of the boss bar. + * + * @param visible true to show, false to hide + */ public void setVisible(boolean visible) { bossBar.setVisible(visible); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/FireworkHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/FireworkHandler.java index 55a3ac9889..2efa5a4456 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/FireworkHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/FireworkHandler.java @@ -17,6 +17,9 @@ import com.bencodez.advancedcore.AdvancedCorePlugin; import com.bencodez.advancedcore.api.misc.MiscUtils; +/** + * Handler for launching fireworks. + */ public class FireworkHandler implements Listener { /** The instance. */ @@ -50,6 +53,7 @@ private FireworkHandler() { * @param trail the trail * @param flicker the flicker * @param types the types + * @param detonate whether to detonate immediately */ public void launchFirework(Location loc, int power, ArrayList colors, ArrayList fadeOutColor, boolean trail, boolean flicker, ArrayList types, boolean detonate) { @@ -126,6 +130,11 @@ public void run() { } + /** + * Handles firework damage events. + * + * @param event the damage event + */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onFireworkDamage(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Firework) { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/ItemMessage.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/ItemMessage.java index 53b1e56de4..2f7b153775 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/ItemMessage.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/misc/effects/ItemMessage.java @@ -32,12 +32,23 @@ * up the chat window. */ public class ItemMessage { +/** + * Represents a message record for item messages. + */ public class MessageRecord implements Comparable { private final int duration; private final long id; private final String message; private final int priority; + /** + * Creates a new message record. + * + * @param message the message text + * @param duration the duration in seconds + * @param priority the priority level + * @param id the unique ID + */ public MessageRecord(String message, int duration, int priority, long id) { this.message = message; this.duration = duration; @@ -187,6 +198,11 @@ private void sendItemSlotChange(Player player, int slot, ItemStack stack) { private final Plugin plugin; + /** + * Creates a new item message handler. + * + * @param plugin the plugin instance + */ public ItemMessage(Plugin plugin) { this.plugin = plugin; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/CalculatingPlaceholder.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/CalculatingPlaceholder.java index 5304daa237..5ba0dba9b9 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/CalculatingPlaceholder.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/CalculatingPlaceholder.java @@ -5,23 +5,57 @@ import lombok.Getter; +/** + * Abstract class for calculating placeholders. + * + * @param the user type + */ public abstract class CalculatingPlaceholder extends PlaceHolder { + /** + * Gets the cache data. + * + * @return the cache data map + */ @Getter private ConcurrentHashMap cacheData = new ConcurrentHashMap<>(); + /** + * Instantiates a new calculating placeholder. + * + * @param identifier the identifier + */ public CalculatingPlaceholder(String identifier) { super(identifier); } + /** + * Instantiates a new calculating placeholder. + * + * @param identifier the identifier + * @param useStartsWith whether to use starts with matching + */ public CalculatingPlaceholder(String identifier, boolean useStartsWith) { super(identifier, useStartsWith); } + /** + * Instantiates a new calculating placeholder. + * + * @param identifier the identifier + * @param noValueReturn the no value return string + */ public CalculatingPlaceholder(String identifier, String noValueReturn) { super(identifier, noValueReturn); } + /** + * Instantiates a new calculating placeholder. + * + * @param identifier the identifier + * @param noValueReturn the no value return string + * @param useStartsWith whether to use starts with matching + */ public CalculatingPlaceholder(String identifier, String noValueReturn, boolean useStartsWith) { super(identifier, noValueReturn, useStartsWith); } @@ -36,6 +70,13 @@ public void clearCachePlayer(UUID javaUUID) { cacheData.remove(javaUUID); } + /** + * Placeholder data request. + * + * @param user the user + * @param identifier the identifier + * @return the result string + */ public abstract String placeholderDataRequest(T user, String identifier); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/PlaceHolder.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/PlaceHolder.java index 1dc1c6c6f7..6dfaf0fdab 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/PlaceHolder.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/placeholder/PlaceHolder.java @@ -7,23 +7,63 @@ import lombok.Getter; +/** + * Abstract class for placeholders. + * + * @param the user type + */ public abstract class PlaceHolder { + /** + * Gets the description. + * + * @return the description + */ @Getter private String description; + /** + * Gets the identifier. + * + * @return the identifier + */ @Getter private String identifier; + /** + * Gets use starts with flag. + * + * @return true if uses starts with + */ @Getter private boolean useStartsWith = false; + /** + * Gets the no value return string. + * + * @return the no value return string + */ @Getter private String noValueReturn = "0"; + /** + * Gets the cache. + * + * @return the cache map + */ @Getter private ConcurrentHashMap> cache; + /** + * Gets the update data key. + * + * @return the update data key + */ @Getter private String updateDataKey = ""; + /** + * Gets uses cache flag. + * + * @return true if uses cache + */ @Getter private boolean usesCache = false; @@ -47,6 +87,11 @@ public PlaceHolder(String identifier, String noValueReturn, boolean useStartsWit this.noValueReturn = noValueReturn; } + /** + * Clears cache for a player. + * + * @param javaUUID the player UUID + */ public void clearCachePlayer(UUID javaUUID) { for (String ident : cache.keySet()) { if (cache.get(ident).containsKey(javaUUID)) { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DefinedReward.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DefinedReward.java index b306c69e1e..09b62ab379 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DefinedReward.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DefinedReward.java @@ -2,18 +2,55 @@ import org.bukkit.configuration.ConfigurationSection; +/** + * Interface for defined rewards. + */ public interface DefinedReward { + /** + * Creates a section. + * + * @param key the key + */ public void createSection(String key); + /** + * Gets the file data. + * + * @return the file data + */ public ConfigurationSection getFileData(); + /** + * Gets the full path. + * + * @return the full path + */ public String getFullPath(); + /** + * Gets the path. + * + * @return the path + */ public String getPath(); + /** + * Needs dot separator. + * + * @return the dot string + */ public String needsDot(); + /** + * Saves the configuration. + */ public void save(); + /** + * Sets the data. + * + * @param str the path + * @param value the value + */ public void setData(String str, Object value); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DirectlyDefinedReward.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DirectlyDefinedReward.java index 215b92e522..d22395d93f 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DirectlyDefinedReward.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/DirectlyDefinedReward.java @@ -5,27 +5,56 @@ import lombok.Getter; import lombok.Setter; +/** + * Abstract class for directly defined rewards. + */ public abstract class DirectlyDefinedReward implements DefinedReward { + /** + * Gets the path. + * + * @return the path + * @param path the path to set + */ @Getter @Setter private String path; + /** + * Instantiates a new directly defined reward. + * + * @param path the path + */ public DirectlyDefinedReward(String path) { this.path = path; } public abstract void createSection(String key); + /** + * Creates a local section. + * + * @param key the key + */ public void createSectionLocal(String key) { createSection(getPath() + "." + key); } public abstract ConfigurationSection getFileData(); + /** + * Gets the full path. + * + * @return the full path + */ public String getFullPath() { return path; } + /** + * Gets the reward. + * + * @return the reward + */ public Reward getReward() { if (isDirectlyDefined()) { return new Reward(getPath().replace(".", "_"), getFileData().getConfigurationSection(getPath())) @@ -34,10 +63,21 @@ public Reward getReward() { return null; } + /** + * Gets the value. + * + * @param path the path + * @return the value + */ public Object getValue(String path) { return getFileData().get(getPath() + "." + path); } + /** + * Checks if directly defined. + * + * @return true if directly defined + */ public boolean isDirectlyDefined() { return getFileData().isConfigurationSection(getPath()); } @@ -50,10 +90,21 @@ public String needsDot() { public abstract void setData(String path, Object value); + /** + * Sets the parent value. + * + * @param value the value + */ public void setParentValue(Object value) { setData(getPath(), value); } + /** + * Sets the value. + * + * @param path the path + * @param value the value + */ public void setValue(String path, Object value) { setData(getPath() + "." + path, value); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/Inject.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/Inject.java index b894659a57..9f262a9f7f 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/Inject.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/rewards/Inject.java @@ -7,23 +7,55 @@ import lombok.Getter; import lombok.Setter; +/** + * Represents an injectable reward configuration. + */ public class Inject { + /** + * @return the list of edit buttons + */ @Getter + /** + * @param editButtons the list of edit buttons to set + */ @Setter private ArrayList editButtons = new ArrayList<>(); + /** + * @return true if this is an internal reward, false otherwise + */ @Getter + /** + * @param internalReward whether this is an internal reward + */ @Setter private boolean internalReward = false; + /** + * @return the configuration path + */ @Getter + /** + * @param path the configuration path to set + */ @Setter private String path; + /** + * @return the priority value + */ @Getter + /** + * @param priority the priority value to set + */ @Setter private int priority = 50; + /** + * Constructs a new Inject with the specified path. + * + * @param path the configuration path + */ public Inject(String path) { this.path = path; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DateChangedEvent.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DateChangedEvent.java index 910a34683e..5a2faff35b 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DateChangedEvent.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DateChangedEvent.java @@ -27,6 +27,11 @@ public static HandlerList getHandlerList() { private TimeType timeType; + /** + * Instantiates a new date changed event. + * + * @param time the time type + */ public DateChangedEvent(TimeType time) { super(true); this.timeType = time; @@ -49,10 +54,20 @@ public TimeType getTimeType() { return timeType; } + /** + * Checks if fake. + * + * @return true if fake + */ public boolean isFake() { return fake; } + /** + * Sets fake. + * + * @param fake the fake flag + */ public void setFake(boolean fake) { this.fake = fake; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DayChangeEvent.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DayChangeEvent.java index 598aba12e2..f464797b0c 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DayChangeEvent.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/time/events/DayChangeEvent.java @@ -40,10 +40,20 @@ public HandlerList getHandlers() { return handlers; } + /** + * Checks if fake. + * + * @return true if fake + */ public boolean isFake() { return fake; } + /** + * Sets fake. + * + * @param fake the fake flag + */ public void setFake(boolean fake) { this.fake = fake; } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/AdvancedCoreUser.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/AdvancedCoreUser.java index 0dcb46aa00..7073df9da0 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/AdvancedCoreUser.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/user/AdvancedCoreUser.java @@ -54,9 +54,19 @@ */ public class AdvancedCoreUser { + /** + * User data fetch mode for this user. + * + * @return the user data fetch mode + */ @Getter private UserDataFetchMode userDataFetchMode = UserDataFetchMode.DEFAULT; + /** + * User data for this user. + * + * @param data the user data to set + */ @Setter private UserData data; @@ -65,12 +75,23 @@ public class AdvancedCoreUser { /** The player name. */ private String playerName; + /** + * Plugin instance. + * + * @return the plugin instance + */ @Getter private AdvancedCorePlugin plugin = null; /** The uuid. */ private String uuid; + /** + * Instantiates a new user from an existing user. + * + * @param plugin the plugin + * @param user the user to copy from + */ public AdvancedCoreUser(AdvancedCorePlugin plugin, AdvancedCoreUser user) { this.userDataFetchMode = user.userDataFetchMode; this.data = user.getUserData(); @@ -143,6 +164,14 @@ public AdvancedCoreUser(AdvancedCorePlugin plugin, UUID uuid, boolean loadName) } + /** + * Instantiates a new user. + * + * @param plugin the plugin + * @param uuid the uuid + * @param loadName the load name + * @param loadData the load data + */ @Deprecated public AdvancedCoreUser(AdvancedCorePlugin plugin, UUID uuid, boolean loadName, boolean loadData) { this.plugin = plugin; @@ -157,6 +186,13 @@ public AdvancedCoreUser(AdvancedCorePlugin plugin, UUID uuid, boolean loadName, } + /** + * Instantiates a new user. + * + * @param plugin the plugin + * @param uuid the uuid + * @param playerName the player name + */ @Deprecated public AdvancedCoreUser(AdvancedCorePlugin plugin, UUID uuid, String playerName) { this.plugin = plugin; @@ -168,6 +204,12 @@ public AdvancedCoreUser(AdvancedCorePlugin plugin, UUID uuid, String playerName) setPlayerName(playerName); } + /** + * Adds offline rewards to be given when the player next logs in. + * + * @param reward the reward + * @param placeholders the placeholders + */ public void addOfflineRewards(Reward reward, HashMap placeholders) { synchronized (plugin) { ArrayList offlineRewards = getOfflineRewards(); @@ -176,14 +218,32 @@ public void addOfflineRewards(Reward reward, HashMap placeholder } } + /** + * Adds a permission to the player. + * + * @param permission the permission + */ public void addPermission(String permission) { plugin.getPermissionHandler().addPermission(getPlayer(), permission); } + /** + * Adds a permission to the player with a delay. + * + * @param permission the permission + * @param delay the delay in milliseconds + */ public void addPermission(String permission, long delay) { plugin.getPermissionHandler().addPermission(getPlayer(), permission, delay); } + /** + * Adds a timed reward to be given at a specific time. + * + * @param reward the reward + * @param placeholders the placeholders + * @param epochMilli the epoch time in milliseconds when the reward should be given + */ public synchronized void addTimedReward(Reward reward, HashMap placeholders, long epochMilli) { HashMap timed = getTimedRewards(); String rewardName = reward.getRewardName(); @@ -194,16 +254,27 @@ public synchronized void addTimedReward(Reward reward, HashMap p loadTimedDelayedTimer(epochMilli); } + /** + * Adds an unclaimed choice reward. + * + * @param name the reward name + */ public void addUnClaimedChoiceReward(String name) { ArrayList choices = getUnClaimedChoices(); choices.add(name); setUnClaimedChoice(choices); } + /** + * Caches the user data. + */ public void cache() { plugin.getUserManager().getDataManager().cacheUser(UUID.fromString(uuid), getPlayerName()); } + /** + * Caches the user data asynchronously. + */ public void cacheAsync() { getPlugin().getBukkitScheduler().runTaskAsynchronously(plugin, new Runnable() { @@ -214,10 +285,16 @@ public void run() { }); } + /** + * Caches the user data if needed. + */ public void cacheIfNeeded() { plugin.getUserManager().getDataManager().cacheUserIfNeeded(UUID.fromString(uuid)); } + /** + * Checks and processes delayed/timed rewards. + */ public void checkDelayedTimedRewards() { plugin.debug("Checking timed/delayed for " + getPlayerName()); HashMap timed = getTimedRewards(); @@ -288,16 +365,25 @@ public void checkOfflineRewards() { } + /** + * Clears the user cache. + */ public void clearCache() { if (isCached()) { getCache().clearCache(); } } + /** + * Clears the temporary cache. + */ public void clearTempCache() { getUserData().clearTempCache(); } + /** + * Closes the player's inventory. + */ public void closeInv() { if (plugin.isEnabled()) { getPlugin().getBukkitScheduler().runTask(plugin, new Runnable() { @@ -313,11 +399,20 @@ public void run() { } } + /** + * Sets the user data fetch mode. + * + * @param mode the fetch mode + * @return this user instance + */ public AdvancedCoreUser userDataFetechMode(UserDataFetchMode mode) { this.userDataFetchMode = mode; return this; } + /** + * Forces running of offline rewards without processing checks. + */ public void forceRunOfflineRewards() { if (!plugin.getOptions().isProcessRewards()) { plugin.debug("Processing rewards is disabled"); @@ -350,10 +445,21 @@ public void forceRunOfflineRewards() { } } + /** + * Gets the user data cache. + * + * @return the cache + */ public UserDataCache getCache() { return plugin.getUserManager().getDataManager().getCache(java.util.UUID.fromString(getUUID())); } + /** + * Gets the user's choice preference for a reward. + * + * @param rewardName the reward name + * @return the choice preference + */ public String getChoicePreference(String rewardName) { ArrayList data = getChoicePreferenceData(); @@ -368,10 +474,20 @@ public String getChoicePreference(String rewardName) { return ""; } + /** + * Gets the choice preference data. + * + * @return the choice preference data list + */ public ArrayList getChoicePreferenceData() { return getData().getStringList("ChoicePreference", userDataFetchMode); } + /** + * Gets the user data. + * + * @return the user data + */ public UserData getData() { if (data == null) { loadData(); @@ -379,14 +495,29 @@ public UserData getData() { return data; } + /** + * Gets the input method. + * + * @return the input method string + */ public String getInputMethod() { return getUserData().getString("InputMethod", userDataFetchMode); } + /** + * Gets the Java UUID object. + * + * @return the Java UUID + */ public UUID getJavaUUID() { return UUID.fromString(uuid); } + /** + * Gets the last online time in milliseconds. + * + * @return the last online time + */ public long getLastOnline() { String d = getData().getString("LastOnline", userDataFetchMode); long time = 0; @@ -402,6 +533,11 @@ public long getLastOnline() { return time; } + /** + * Gets the number of days since the player's last login. + * + * @return the number of days since login + */ public int getNumberOfDaysSinceLogin() { long time = getLastOnline(); if (time > 0) { @@ -414,6 +550,11 @@ public int getNumberOfDaysSinceLogin() { return -1; } + /** + * Gets the offline player. + * + * @return the offline player + */ @SuppressWarnings("deprecation") public OfflinePlayer getOfflinePlayer() { if (!plugin.getOptions().isOnlineMode()) { @@ -425,6 +566,11 @@ public OfflinePlayer getOfflinePlayer() { return null; } + /** + * Gets the offline rewards list. + * + * @return the offline rewards + */ public ArrayList getOfflineRewards() { return getUserData().getStringList(plugin.getUserManager().getOfflineRewardsPath(), userDataFetchMode); } @@ -444,6 +590,11 @@ public Player getPlayer() { return null; } + /** + * Gets the player's head as an ItemStack. + * + * @return the player head + */ public ItemStack getPlayerHead() { return PlayerManager.getInstance().getPlayerSkull(getJavaUUID(), getPlayerName(), false); } @@ -463,10 +614,21 @@ public String getPlayerName() { return ""; } + /** + * Gets the repeat amount for a reward. + * + * @param reward the reward + * @return the repeat amount + */ public int getRepeatAmount(Reward reward) { return getData().getInt("Repeat" + reward.getName(), userDataFetchMode); } + /** + * Gets the timed rewards map. + * + * @return the timed rewards + */ public HashMap getTimedRewards() { ArrayList timedReward = getUserData().getStringList("TimedRewards", userDataFetchMode); HashMap timedRewards = new HashMap<>(); @@ -485,10 +647,20 @@ public HashMap getTimedRewards() { return timedRewards; } + /** + * Gets the unclaimed choices list. + * + * @return the unclaimed choices + */ public ArrayList getUnClaimedChoices() { return getData().getStringList("UnClaimedChoices", userDataFetchMode); } + /** + * Gets the user data instance. + * + * @return the user data + */ public UserData getUserData() { if (data == null) { loadData(); @@ -496,6 +668,11 @@ public UserData getUserData() { return data; } + /** + * Gets the user's input method. + * + * @return the input method + */ public InputMethod getUserInputMethod() { String inputMethod = getInputMethod(); if (inputMethod == null) { @@ -526,6 +703,11 @@ public void giveExp(int exp) { } } + /** + * Gives experience levels to the player. + * + * @param num the number of levels to give + */ public void giveExpLevels(int num) { Player p = getPlayer(); if (p != null) { @@ -533,6 +715,11 @@ public void giveExpLevels(int num) { } } + /** + * Gives an item to the player from an ItemBuilder. + * + * @param builder the item builder + */ public void giveItem(ItemBuilder builder) { giveItem(builder.toItemStack(getPlayer())); } @@ -563,10 +750,21 @@ public void run() { } + /** + * Gives an item to the player with placeholders. + * + * @param itemStack the item stack + * @param placeholders the placeholders + */ public void giveItem(ItemStack itemStack, HashMap placeholders) { giveItem(new ItemBuilder(itemStack).setPlaceholders(placeholders).toItemStack(getPlayer())); } + /** + * Gives multiple items to the player. + * + * @param item the items to give + */ public void giveItems(ItemStack... item) { if (item == null) { return; @@ -661,14 +859,32 @@ public void run() { } } + /** + * Gives a reward from a configuration file. + * + * @param data the configuration data + * @param path the path to the reward + * @param rewardOptions the reward options + */ public void giveReward(FileConfiguration data, String path, RewardOptions rewardOptions) { plugin.getRewardHandler().giveReward(this, data, path, rewardOptions); } + /** + * Gives a reward to the user. + * + * @param reward the reward + * @param rewardOptions the reward options + */ public void giveReward(Reward reward, RewardOptions rewardOptions) { reward.giveReward(this, rewardOptions); } + /** + * Checks if the user has unclaimed choices. + * + * @return true if the user has choices + */ public boolean hasChoices() { return getUnClaimedChoices().size() > 0; } @@ -693,10 +909,23 @@ public boolean hasLoggedOnBefore() { return false; } + /** + * Checks if the user has a permission. + * + * @param perm the permission + * @return true if the user has the permission + */ public boolean hasPermission(String perm) { return hasPermission(perm, true); } + /** + * Checks if the user has a permission. + * + * @param perm the permission + * @param offlineCheck whether to check offline permissions + * @return true if the user has the permission + */ public boolean hasPermission(String perm, boolean offlineCheck) { boolean negate = perm != null && perm.startsWith("!"); if (negate) { @@ -727,6 +956,11 @@ public boolean hasPermission(String perm, boolean offlineCheck) { return false; } + /** + * Checks if the player is banned. + * + * @return true if the player is banned + */ public boolean isBanned() { if (plugin.getBannedPlayers().contains(getUUID())) { return true; @@ -734,18 +968,38 @@ public boolean isBanned() { return false; } + /** + * Checks if the player is a Bedrock user. + * + * @return true if the player is a Bedrock user + */ public boolean isBedrockUser() { return getData().getBoolean("isBedrock", userDataFetchMode); } + /** + * Sets whether the player is a Bedrock user. + * + * @param isBedrock true if the player is a Bedrock user + */ public void setBedrockUser(boolean isBedrock) { getData().setBoolean("isBedrock", isBedrock); } + /** + * Checks if the user data is cached. + * + * @return true if cached + */ public boolean isCached() { return plugin.getUserManager().getDataManager().isCached(UUID.fromString(uuid)); } + /** + * Checks if world checking is enabled for the user. + * + * @return true if world checking is enabled + */ public boolean isCheckWorld() { if (!plugin.isLoadUserData()) { return false; @@ -753,6 +1007,12 @@ public boolean isCheckWorld() { return Boolean.valueOf(getData().getString("CheckWorld", userDataFetchMode)); } + /** + * Checks if the player is in any of the specified worlds. + * + * @param worlds the list of world names + * @return true if the player is in one of the worlds + */ public boolean isInWorld(ArrayList worlds) { Player p = getPlayer(); if (p != null) { @@ -766,6 +1026,12 @@ public boolean isInWorld(ArrayList worlds) { return false; } + /** + * Checks if the player is in a specific world. + * + * @param world the world name + * @return true if the player is in the world + */ public boolean isInWorld(String world) { Player p = getPlayer(); if (p != null) { @@ -793,6 +1059,11 @@ public boolean isOnline() { return true; } + /** + * Checks if the player is vanished. + * + * @return true if the player is vanished + */ public boolean isVanished() { Player player = getPlayer(); if (player != null) { @@ -816,14 +1087,25 @@ public boolean isVanished() { return false; } + /** + * Loads the user cache. + */ public void loadCache() { plugin.getUserManager().getDataManager().cacheUser(UUID.fromString(uuid), getPlayerName()); } + /** + * Loads the user data. + */ public void loadData() { data = new UserData(this); } + /** + * Loads a timer for delayed/timed rewards. + * + * @param time the time in milliseconds + */ public void loadTimedDelayedTimer(long time) { long delay = time - System.currentTimeMillis(); if (delay < 0) { @@ -862,6 +1144,14 @@ public void playEffect(String effectName, int data, int particles, int radius) { } } + /** + * Plays a particle effect for the player. + * + * @param effectName the particle effect name + * @param data the data value + * @param particles the number of particles + * @param radius the radius + */ public void playParticle(String effectName, int data, int particles, int radius) { Player player = getPlayer(); if ((player != null) && (effectName != null)) { @@ -880,6 +1170,14 @@ public void playParticle(String effectName, int data, int particles, int radius) } } + /** + * Plays a particle effect for the player. + * + * @param effectName the particle effect name + * @param data the data value + * @param particles the number of particles + * @param radius the radius + */ @Deprecated public void playParticleEffect(String effectName, int data, int particles, int radius) { playParticle(effectName, data, particles, radius); @@ -909,6 +1207,12 @@ public void playSound(String soundName, float volume, float pitch) { } } + /** + * Performs commands as the player with placeholders. + * + * @param commands the list of commands + * @param placeholders the placeholders + */ public void preformCommand(ArrayList commands, HashMap placeholders) { if (commands != null && !commands.isEmpty()) { final ArrayList cmds = PlaceholderUtils.replaceJavascript(getPlayer(), @@ -930,6 +1234,12 @@ public void run() { } } + /** + * Performs a command as the player with placeholders. + * + * @param command the command + * @param placeholders the placeholders + */ public void preformCommand(String command, HashMap placeholders) { if (command != null && !command.isEmpty()) { final String cmd = PlaceholderUtils.replaceJavascript(getPlayer(), @@ -950,15 +1260,28 @@ public void run() { } } + /** + * Removes the user from storage. + */ public void remove() { plugin.debug("Removing " + getUUID() + " (" + getPlayerName() + ") from storage..."); getData().remove(); } + /** + * Removes a permission from the player. + * + * @param permission the permission + */ public void removePermission(String permission) { plugin.getPermissionHandler().removePermission(UUID.fromString(getUUID()), getPlayerName(), permission); } + /** + * Removes an unclaimed choice reward. + * + * @param name the reward name + */ public void removeUnClaimedChoiceReward(String name) { ArrayList choices = getUnClaimedChoices(); choices.remove(name); @@ -1022,6 +1345,12 @@ public void sendJson(ArrayList messages) { sendJson(messages, true); } + /** + * Sends JSON messages to the player. + * + * @param messages the text component messages + * @param javascript whether to process javascript placeholders + */ public void sendJson(ArrayList messages, boolean javascript) { Player player = getPlayer(); if ((player != null) && (messages != null)) { @@ -1066,6 +1395,12 @@ public void sendMessage(ArrayList msg) { sendMessage(ArrayUtils.convert(msg)); } + /** + * Sends a message with placeholders to the player. + * + * @param msg the message list + * @param placeholders the placeholders + */ public void sendMessage(ArrayList msg, HashMap placeholders) { sendMessage(ArrayUtils.convert(PlaceholderUtils.replacePlaceHolder(msg, placeholders))); } @@ -1087,10 +1422,23 @@ public void sendMessage(String msg) { } } + /** + * Sends a message with placeholders to the player. + * + * @param msg the message + * @param placeholders the placeholders + */ public void sendMessage(String msg, HashMap placeholders) { sendMessage(PlaceholderUtils.replacePlaceHolder(msg, placeholders)); } + /** + * Sends a message with a single placeholder replacement to the player. + * + * @param msg the message + * @param toReplace the placeholder to replace + * @param replace the replacement value + */ public void sendMessage(String msg, String toReplace, String replace) { sendMessage(PlaceholderUtils.replacePlaceHolder(msg, toReplace, replace)); } @@ -1147,10 +1495,21 @@ public void sendTitle(String title, String subTitle, int fadeIn, int showTime, i } } + /** + * Sets whether to check the world for the user. + * + * @param b true to enable world checking + */ public void setCheckWorld(boolean b) { getData().setString("CheckWorld", "" + b); } + /** + * Sets the user's choice preference for a reward. + * + * @param reward the reward name + * @param preference the preference + */ public void setChoicePreference(String reward, String preference) { ArrayList data = getChoicePreferenceData(); ArrayList choices = new ArrayList<>(); @@ -1173,14 +1532,29 @@ public void setChoicePreference(String reward, String preference) { getData().setStringList("ChoicePreference", choices); } + /** + * Sets the input method for the user. + * + * @param inputMethod the input method + */ public void setInputMethod(String inputMethod) { data.setString("InputMethod", inputMethod); } + /** + * Sets the last online time for the user. + * + * @param online the last online time in milliseconds + */ public void setLastOnline(long online) { getData().setString("LastOnline", "" + online); } + /** + * Sets the offline rewards list. + * + * @param offlineRewards the offline rewards + */ public void setOfflineRewards(ArrayList offlineRewards) { // MySQL TEXT max length is 65535 bytes int maxLength = 65535; @@ -1195,14 +1569,30 @@ public void setOfflineRewards(ArrayList offlineRewards) { data.setStringList(plugin.getUserManager().getOfflineRewardsPath(), offlineRewards); } + /** + * Sets the player name. + * + * @param playerName the player name + */ public void setPlayerName(String playerName) { this.playerName = playerName; } + /** + * Sets the repeat amount for a reward. + * + * @param reward the reward + * @param amount the repeat amount + */ public void setRepeatAmount(Reward reward, int amount) { getData().setInt("Repeat" + reward.getName(), amount); } + /** + * Sets the timed rewards map. + * + * @param timed the timed rewards + */ public void setTimedRewards(HashMap timed) { ArrayList timedRewards = new ArrayList<>(); for (Entry entry : timed.entrySet()) { @@ -1216,14 +1606,27 @@ public void setTimedRewards(HashMap timed) { data.setStringList("TimedRewards", timedRewards); } + /** + * Sets the unclaimed choice rewards list. + * + * @param rewards the unclaimed rewards + */ public void setUnClaimedChoice(ArrayList rewards) { getData().setStringList("UnClaimedChoices", rewards); } + /** + * Sets the user's input method. + * + * @param method the input method + */ public void setUserInputMethod(InputMethod method) { setInputMethod(method.toString()); } + /** + * Sets the user to not cache data. + */ @Deprecated public void dontCache() { userDataFetchMode = UserDataFetchMode.NO_CACHE; @@ -1238,11 +1641,21 @@ public void setUUID(String uuid) { this.uuid = uuid; } + /** + * Enables temporary caching for this user. + * + * @return this user instance + */ public AdvancedCoreUser tempCache() { getUserData().tempCache(); return this; } + /** + * Updates the player name in storage. + * + * @param force whether to force the update + */ public void updateName(boolean force) { if (getData().hasData() || force) { String playerName = getData().getString("PlayerName", userDataFetchMode); @@ -1252,6 +1665,11 @@ public void updateName(boolean force) { } } + /** + * Updates the temporary cache with specific columns. + * + * @param cols the columns to update + */ public void updateTempCacheWithColumns(ArrayList cols) { getUserData().updateTempCacheWithColumns(cols); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/InputMethod.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/InputMethod.java index b99127d512..d0aa3e3bf4 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/InputMethod.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/InputMethod.java @@ -7,12 +7,24 @@ */ public enum InputMethod { + /** + * Book input method. + */ BOOK, + /** + * Chat input method. + */ CHAT, + /** + * Inventory input method. + */ INVENTORY, + /** + * Sign input method. + */ SIGN; /** diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/BooleanListener.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/BooleanListener.java index b5d542f22b..4805ec38bb 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/BooleanListener.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/BooleanListener.java @@ -2,6 +2,9 @@ import org.bukkit.entity.Player; +/** + * Listener for boolean input from players. + */ public abstract class BooleanListener { /** diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/Listener.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/Listener.java index edbdbff7dd..19df95c4a4 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/Listener.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/valuerequest/listeners/Listener.java @@ -2,8 +2,19 @@ import org.bukkit.entity.Player; +/** + * Abstract listener for value request inputs. + * + * @param the type of value this listener handles + */ public abstract class Listener { + /** + * Called when a player provides input. + * + * @param player the player providing input + * @param value the input value + */ public abstract void onInput(Player player, T value); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/yml/editor/ConfigEditor.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/yml/editor/ConfigEditor.java index 5733a19cec..b35f2a8161 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/yml/editor/ConfigEditor.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/api/yml/editor/ConfigEditor.java @@ -31,6 +31,9 @@ import com.bencodez.simpleapi.file.annotation.ConfigDataListString; import com.bencodez.simpleapi.file.annotation.ConfigDataString; +/** + * Configuration editor GUI handler. + */ public class ConfigEditor { private YMLFile ymlFile; private YMLConfig ymlConfig; @@ -40,12 +43,26 @@ public class ConfigEditor { private AdvancedCorePlugin plugin; private HashMap buttons = new HashMap<>(); + /** + * Instantiates a new config editor. + * + * @param plugin the plugin + * @param ymlFile the yml file + */ public ConfigEditor(AdvancedCorePlugin plugin, YMLFile ymlFile) { this.ymlFile = ymlFile; this.plugin = plugin; load(); } + /** + * Instantiates a new config editor. + * + * @param plugin the plugin + * @param ymlFile the yml file + * @param ymlConfig the yml config + * @param ymlConfigClass the yml config class + */ public ConfigEditor(AdvancedCorePlugin plugin, YMLFile ymlFile, YMLConfig ymlConfig, Class ymlConfigClass) { this.ymlFile = ymlFile; this.ymlConfig = ymlConfig; @@ -54,6 +71,13 @@ public ConfigEditor(AdvancedCorePlugin plugin, YMLFile ymlFile, YMLConfig ymlCon load(); } + /** + * Adds buttons from yml config. + * + * @param ymlConfig the yml config + * @param clazz the class + * @param config the configuration section + */ @SuppressWarnings("unchecked") public void addButtons(YMLConfig ymlConfig, Class clazz, ConfigurationSection config) { @@ -311,6 +335,13 @@ public void setValue(Player player, ArrayList value) { } } + /** + * Adds buttons from yml file. + * + * @param ymlFile the yml file + * @param clazz the class + * @param config the configuration section + */ @SuppressWarnings("unchecked") public void addButtons(YMLFile ymlFile, Class clazz, ConfigurationSection config) { @@ -568,6 +599,9 @@ public void setValue(Player player, ArrayList value) { } } + /** + * Load configuration buttons. + */ public void load() { Class clazz = ymlFile.getClass(); ConfigurationSection config = ymlFile.getData(); @@ -582,6 +616,11 @@ public void load() { } } + /** + * Opens the config editor GUI. + * + * @param player the player + */ public void open(Player player) { EditGUI inv = new EditGUI("EDIT: " + ymlFile.getdFile().getName()); Set configSections = new HashSet<>(); @@ -615,6 +654,12 @@ public void onClick(ClickEvent clickEvent) { inv.openInventory(player); } + /** + * Opens the config editor GUI for a section. + * + * @param player the player + * @param sec the section path + */ public void open(Player player, String sec) { EditGUI inv = new EditGUI("EDIT: " + ymlFile.getdFile().getName()); Set configSections = new HashSet<>(); @@ -668,6 +713,11 @@ public void onClick(ClickEvent clickEvent) { inv.openInventory(player); } + /** + * Opens the non-config section editor GUI. + * + * @param player the player + */ public void openNonConfig(Player player) { EditGUI inv = new EditGUI("EDIT: " + ymlFile.getdFile().getName()); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandler.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandler.java index bb614a1cf7..6ce4b31d6e 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandler.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandler.java @@ -12,14 +12,34 @@ import lombok.Getter; +/** + * Handler for global data across multiple servers. + */ public class GlobalDataHandler { + /** + * The global MySQL instance. + * + * @return the global MySQL instance + */ @Getter private GlobalMySQL globalMysql; + /** + * Constructor for GlobalDataHandler. + * + * @param globalMysql the global MySQL instance + */ public GlobalDataHandler(GlobalMySQL globalMysql) { this.globalMysql = globalMysql; } + /** + * Gets a boolean value from global data. + * + * @param server the server name + * @param key the key + * @return the boolean value + */ public boolean getBoolean(String server, String key) { HashMap data = getExact(server); if (data.containsKey(key)) { @@ -32,6 +52,12 @@ public boolean getBoolean(String server, String key) { return false; } + /** + * Gets exact data for a server. + * + * @param server the server name + * @return the data map + */ public HashMap getExact(String server) { HashMap data = new HashMap<>(); for (Column entry : globalMysql.getExact(server)) { @@ -40,6 +66,13 @@ public HashMap getExact(String server) { return data; } + /** + * Gets an integer value from global data. + * + * @param server the server name + * @param key the key + * @return the integer value + */ public int getInt(String server, String key) { HashMap data = getExact(server); if (data.containsKey(key)) { @@ -51,6 +84,13 @@ public int getInt(String server, String key) { return 0; } + /** + * Gets a string value from global data. + * + * @param server the server name + * @param key the key + * @return the string value + */ public String getString(String server, String key) { HashMap data = getExact(server); if (data.containsKey(key)) { @@ -62,10 +102,23 @@ public String getString(String server, String key) { return ""; } + /** + * Sets a boolean value in global data. + * + * @param server the server name + * @param key the key + * @param data the boolean value + */ public void setBoolean(String server, String key, boolean data) { globalMysql.update(server, key, new DataValueBoolean(data)); } + /** + * Sets multiple data values in global data. + * + * @param server the server name + * @param data the data map + */ public void setData(String server, HashMap data) { ArrayList cols = new ArrayList<>(); for (Entry entry : data.entrySet()) { @@ -74,10 +127,24 @@ public void setData(String server, HashMap data) { globalMysql.update(server, cols, false); } + /** + * Sets an integer value in global data. + * + * @param server the server name + * @param key the key + * @param data the integer value + */ public void setInt(String server, String key, int data) { globalMysql.update(server, key, new DataValueInt(data)); } + /** + * Sets a string value in global data. + * + * @param server the server name + * @param key the key + * @param data the string value + */ public void setString(String server, String key, String data) { globalMysql.update(server, key, new DataValueString(data)); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandlerProxy.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandlerProxy.java index 8404d7c188..429f79554d 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandlerProxy.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalDataHandlerProxy.java @@ -12,15 +12,34 @@ import lombok.Getter; import lombok.Setter; +/** + * Proxy handler for global data with time change support. + */ public abstract class GlobalDataHandlerProxy extends GlobalDataHandler { + /** + * Whether time changed has happened. + * + * @return whether time changed has happened + * @param timeChangedHappened whether time changed has happened + */ @Getter @Setter private boolean timeChangedHappened = false; + /** + * The list of time changes. + * + * @return the list of time changes + */ @Getter private ArrayList timeChanges = new ArrayList<>(); + /** + * The time changed timer. + * + * @return the time changed timer + */ @Getter private ScheduledExecutorService timeChangedTimer; @@ -28,6 +47,12 @@ public abstract class GlobalDataHandlerProxy extends GlobalDataHandler { private GlobalMySQL globalMysql; + /** + * Constructor for GlobalDataHandlerProxy. + * + * @param globalMysql the global MySQL instance + * @param servers the list of servers + */ public GlobalDataHandlerProxy(GlobalMySQL globalMysql, ArrayList servers) { super(globalMysql); timeChangedTimer = Executors.newScheduledThreadPool(1); @@ -73,10 +98,16 @@ public void run() { }, 60, 10, TimeUnit.SECONDS); } + /** + * Shuts down the time changed timer. + */ public void shutdown() { timeChangedTimer.shutdownNow(); } + /** + * Checks for finished time changes across servers. + */ public void checkForFinishedTimeChanges() { try { if (timeChangedHappened) { @@ -143,13 +174,29 @@ private void failedProcess(String server) { } } + /** + * Called when a time change occurs. + * + * @param type the time type + */ public void onTimeChange(TimeType type) { timeChangedHappened = true; timeChanges.add(type); } + /** + * Called when a time change failed on a server. + * + * @param server the server name + * @param type the time type + */ public abstract void onTimeChangedFailed(String server, TimeType type); + /** + * Called when a time change finished successfully. + * + * @param type the time type + */ public abstract void onTimeChangedFinished(TimeType type); } diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalMySQL.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalMySQL.java index 16a57a7256..df21248039 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalMySQL.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/globaldata/GlobalMySQL.java @@ -24,6 +24,9 @@ import com.bencodez.simpleapi.sql.mysql.config.MysqlConfig; import com.bencodez.simpleapi.sql.mysql.queries.Query; +/** + * Abstract class for managing global MySQL database operations across multiple servers. + */ public abstract class GlobalMySQL { private List columns = Collections.synchronizedList(new ArrayList()); @@ -41,6 +44,12 @@ public abstract class GlobalMySQL { private Set servers = ConcurrentHashMap.newKeySet(); + /** + * Constructs a GlobalMySQL instance with the specified table name and MySQL connection. + * + * @param tableName the name of the table + * @param mysql the MySQL instance to use + */ public GlobalMySQL(String tableName, MySQL mysql) { this.mysql = mysql; this.name = tableName; @@ -55,6 +64,12 @@ public GlobalMySQL(String tableName, MySQL mysql) { loadData(); } + /** + * Constructs a GlobalMySQL instance with the specified table name and MySQL configuration. + * + * @param tableName the name of the table + * @param config the MySQL configuration + */ public GlobalMySQL(String tableName, MysqlConfig config) { if (config.hasTableNameSet()) { @@ -169,6 +184,12 @@ private void createTableIfNeeded() { // Column management // ------------------------- + /** + * Adds a new column to the database table. + * + * @param column the name of the column to add + * @param dataType the data type of the column + */ public void addColumn(String column, DataType dataType) { synchronized (object3) { // TEXT works fine for both @@ -291,6 +312,12 @@ private boolean columnNeedsAlter(Connection conn, DbType dbType, String column, } } + /** + * Alters the type of an existing column in the database table. + * + * @param column the name of the column to alter + * @param newType the new data type for the column + */ public void alterColumnType(final String column, final String newType) { checkColumn(column, DataType.STRING); @@ -350,6 +377,12 @@ public void alterColumnType(final String column, final String newType) { } } + /** + * Checks if a column exists in the table, and adds it if it does not. + * + * @param column the name of the column to check + * @param dataType the data type of the column + */ public void checkColumn(String column, DataType dataType) { synchronized (object4) { if (!ArrayUtils.containsIgnoreCase((ArrayList) getColumns(), column)) { @@ -364,6 +397,9 @@ public void checkColumn(String column, DataType dataType) { // Cache / lifecycle // ------------------------- + /** + * Clears the basic cache and reloads columns and servers from the database. + */ public void clearCacheBasic() { debugLog("Clearing cache basic"); columns.clear(); @@ -372,6 +408,9 @@ public void clearCacheBasic() { servers.addAll(getServersQuery()); } + /** + * Closes the database connection. + */ public void close() { mysql.disconnect(); } @@ -380,10 +419,22 @@ public void close() { // Existence checks // ------------------------- + /** + * Checks if the database contains a record for the specified server. + * + * @param server the server name to check + * @return true if the server exists, false otherwise + */ public boolean containsKey(String server) { return servers.contains(server) || containsKeyQuery(server); } + /** + * Queries the database to check if it contains a record for the specified server. + * + * @param index the server name to check + * @return true if the server exists in the database, false otherwise + */ public boolean containsKeyQuery(String index) { // Efficient: WHERE server = ? String sqlStr = "SELECT server FROM " + getName() + " WHERE server = ?;"; @@ -399,14 +450,35 @@ public boolean containsKeyQuery(String index) { return false; } + /** + * Checks if the cached server list contains the specified server. + * + * @param server the server name to check + * @return true if the server is in the cache, false otherwise + */ public boolean containsServer(String server) { return servers.contains(server); } + /** + * Logs an exception for debugging purposes. + * + * @param e the exception to log + */ public abstract void debugEx(Exception e); + /** + * Logs a debug message. + * + * @param text the message to log + */ public abstract void debugLog(String text); + /** + * Deletes a server record from the database. + * + * @param server the server name to delete + */ public void deleteServer(String server) { String q = "DELETE FROM " + getName() + " WHERE server='" + server + "';"; try { @@ -418,6 +490,11 @@ public void deleteServer(String server) { clearCacheBasic(); } + /** + * Executes a SQL query with placeholder replacement. + * + * @param str the SQL query string + */ public void executeQuery(String str) { try { Query q = new Query(mysql, PlaceholderUtils.replacePlaceHolder(str, "tablename", getName())); @@ -427,6 +504,11 @@ public void executeQuery(String str) { } } + /** + * Gets the list of column names in the table. + * + * @return the list of column names + */ public List getColumns() { if (columns == null || columns.isEmpty()) { loadData(); @@ -434,6 +516,11 @@ public List getColumns() { return columns; } + /** + * Queries the database for the list of column names in the table. + * + * @return the list of column names + */ public ArrayList getColumnsQueury() { ArrayList cols = new ArrayList<>(); @@ -469,10 +556,22 @@ public ArrayList getColumnsQueury() { return cols; } + /** + * Gets the exact record for the specified server. + * + * @param server the server name + * @return the list of columns for the server + */ public ArrayList getExact(String server) { return getExactQuery(new Column("server", new DataValueString(server))); } + /** + * Queries the database for records matching the specified column. + * + * @param column the column to match + * @return the list of columns matching the query + */ public ArrayList getExactQuery(Column column) { ArrayList result = new ArrayList<>(); @@ -508,10 +607,20 @@ public ArrayList getExactQuery(Column column) { return result; } + /** + * Gets the table name. + * + * @return the table name + */ public String getName() { return name; } + /** + * Queries the database for all server records. + * + * @return the list of server columns + */ public ArrayList getRowsQuery() { ArrayList result = new ArrayList<>(); String sqlStr = "SELECT server FROM " + getName() + ";"; @@ -531,6 +640,11 @@ public ArrayList getRowsQuery() { return result; } + /** + * Gets the set of server names from cache or database. + * + * @return the set of server names + */ public Set getServers() { if (servers == null || servers.isEmpty()) { servers.clear(); @@ -539,6 +653,11 @@ public Set getServers() { return servers; } + /** + * Queries the database for all server names. + * + * @return the list of server names + */ public ArrayList getServersQuery() { ArrayList out = new ArrayList<>(); @@ -556,12 +675,30 @@ public ArrayList getServersQuery() { return out; } + /** + * Logs an informational message. + * + * @param text the message to log + */ public abstract void info(String text); + /** + * Inserts a single column value for the specified server. + * + * @param index the server name + * @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))); } + /** + * Inserts or updates multiple column values for the specified server. + * + * @param index the server name + * @param cols the list of columns to insert + */ public void insertQuery(String index, List cols) { DbType dbType = dbType(); @@ -631,14 +768,28 @@ public void insertQuery(String index, List cols) { } } + /** + * Checks if the specified column is an integer column. + * + * @param key the column name + * @return true if the column is an integer column, false otherwise + */ public boolean isIntColumn(String key) { return intColumns.contains(key); } + /** + * Checks if batch updates are supported. + * + * @return true if batch updates are supported, false otherwise + */ public boolean isUseBatchUpdates() { return useBatchUpdates; } + /** + * Loads column and batch update support data from the database. + */ public void loadData() { columns = getColumnsQueury(); @@ -649,8 +800,20 @@ public void loadData() { } } + /** + * Logs a severe error message. + * + * @param text the message to log + */ public abstract void logSevere(String text); + /** + * Updates multiple column values for the specified server. + * + * @param index the server name + * @param cols the list of columns to update + * @param runAsync whether to run the update asynchronously + */ public void update(String index, List cols, boolean runAsync) { for (Column col : cols) { checkColumn(col.getName(), col.getDataType()); @@ -705,6 +868,13 @@ public void update(String index, List cols, boolean runAsync) { } } + /** + * Updates a single column value for the specified server. + * + * @param index the server name + * @param column the column name + * @param value the value to update + */ public void update(String index, String column, DataValue value) { if (value == null) { debugLog("Mysql value null: " + column); @@ -741,8 +911,18 @@ public void update(String index, String column, DataValue value) { } } + /** + * Logs a warning message. + * + * @param text the message to log + */ public abstract void warning(String text); + /** + * Wipes all data from the specified column by setting values to NULL. + * + * @param columnName the name of the column to wipe + */ public void wipeColumnData(String columnName) { checkColumn(columnName, DataType.STRING); diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/time/BungeeTimeChecker.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/time/BungeeTimeChecker.java index 73b1fbd1d9..9ba264e672 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/time/BungeeTimeChecker.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/bungeeapi/time/BungeeTimeChecker.java @@ -23,32 +23,75 @@ public abstract class BungeeTimeChecker { private boolean processing = false; + /** + * Gets the timer. + * + * @return the scheduled executor service + */ @Getter private ScheduledExecutorService timer; private boolean timerLoaded = false; + /** + * Gets the time change fail safe bypass. + * + * @return true if bypass is enabled + * @param timeChangeFailSafeBypass the bypass flag to set + */ @Getter @Setter private boolean timeChangeFailSafeBypass = false; + /** + * Gets the time offset. + * + * @return the time offset in hours + */ @Getter private int timeOffSet; + /** + * Gets the time week offset. + * + * @return the time week offset + */ @Getter private int timeWeekOffSet = 0; + /** + * Gets the time zone. + * + * @return the time zone + */ @Getter private String timeZone; + /** + * Instantiates a new bungeecord time checker. + * + * @param timeZone the time zone + * @param timeOffSet the time offset in hours + * @param weekOffSet the week offset + */ public BungeeTimeChecker(String timeZone, int timeOffSet, int weekOffSet) { this.timeOffSet = timeOffSet; this.timeZone = timeZone; this.timeWeekOffSet = weekOffSet; } + /** + * Debug message. + * + * @param text the debug text + */ public abstract void debug(String text); + /** + * Force time change. + * + * @param time the time type + */ public void forceChanged(TimeType time) { timer.execute(new Runnable() { @@ -59,6 +102,14 @@ public void run() { }); } + /** + * Force time change. + * + * @param time the time type + * @param fake whether this is a fake change + * @param preDate whether to run pre-date actions + * @param postDate whether to run post-date actions + */ public void forceChanged(TimeType time, boolean fake, boolean preDate, boolean postDate) { processing = true; try { @@ -88,14 +139,39 @@ public void forceChanged(TimeType time, boolean fake, boolean preDate, boolean p } + /** + * Gets the last updated time. + * + * @return the last updated timestamp + */ public abstract long getLastUpdated(); + /** + * Gets the previous day. + * + * @return the previous day + */ public abstract int getPrevDay(); + /** + * Gets the previous month. + * + * @return the previous month + */ public abstract String getPrevMonth(); + /** + * Gets the previous week. + * + * @return the previous week + */ public abstract int getPrevWeek(); + /** + * Gets the current time with timezone and offset applied. + * + * @return the current local date time + */ public LocalDateTime getTime() { LocalDateTime localNow = LocalDateTime.now(); if (!timeZone.isEmpty()) { @@ -110,6 +186,12 @@ public LocalDateTime getTime() { return localNow.plusHours(timeOffSet); } + /** + * Checks if day has changed. + * + * @param set whether to set the new day + * @return true if day has changed + */ public boolean hasDayChanged(boolean set) { int prevDay = getPrevDay(); int day = getTime().getDayOfMonth(); @@ -123,6 +205,12 @@ public boolean hasDayChanged(boolean set) { return true; } + /** + * Checks if month has changed. + * + * @param set whether to set the new month + * @return true if month has changed + */ public boolean hasMonthChanged(boolean set) { String prevMonth = getPrevMonth(); String month = getTime().getMonth().toString(); @@ -145,10 +233,21 @@ public boolean hasMonthChanged(boolean set) { } + /** + * Checks if time has offset. + * + * @return true if time offset is set + */ public boolean hasTimeOffSet() { return getTimeOffSet() != 0; } + /** + * Checks if week has changed. + * + * @param set whether to set the new week + * @return true if week has changed + */ public boolean hasWeekChanged(boolean set) { int prevDate = getPrevWeek(); LocalDateTime date = getTime().plusDays(timeWeekOffSet); @@ -163,12 +262,30 @@ public boolean hasWeekChanged(boolean set) { return true; } + /** + * Info message. + * + * @param text the info text + */ public abstract void info(String text); + /** + * Checks if time checker is enabled. + * + * @return true if enabled + */ public abstract boolean isEnabled(); + /** + * Checks if time changes should be ignored. + * + * @return true if ignoring time + */ public abstract boolean isIgnoreTime(); + /** + * Load the time checker timer. + */ public void loadTimer() { if (!timerLoaded) { timerLoaded = true; @@ -207,18 +324,52 @@ public void run() { } } + /** + * Sets ignore time flag. + * + * @param ignore whether to ignore time changes + */ public abstract void setIgnoreTime(boolean ignore); + /** + * Sets the last updated time to now. + */ public abstract void setLastUpdated(); + /** + * Sets the previous day. + * + * @param day the day to set + */ public abstract void setPrevDay(int day); + /** + * Sets the previous month. + * + * @param text the month to set + */ public abstract void setPrevMonth(String text); + /** + * Sets the previous week. + * + * @param week the week to set + */ public abstract void setPrevWeek(int week); + /** + * Called when time has changed. + * + * @param type the time type + * @param fake whether this is a fake change + * @param pre whether this is pre-change + * @param post whether this is post-change + */ public abstract void timeChanged(TimeType type, boolean fake, boolean pre, boolean post); + /** + * Shutdown the time checker. + */ public void shutdown() { timer.shutdownNow(); } @@ -263,5 +414,10 @@ public void update() { } } + /** + * Warning message. + * + * @param text the warning text + */ public abstract void warning(String text); } \ No newline at end of file diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/CommandLoader.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/CommandLoader.java index 0be004c462..88c73ba8d8 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/CommandLoader.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/CommandLoader.java @@ -48,6 +48,11 @@ public class CommandLoader { static CommandLoader instance = new CommandLoader(AdvancedCorePlugin.getInstance()); + /** + * Gets the instance. + * + * @return the instance + */ public static CommandLoader getInstance() { return instance; } @@ -60,19 +65,40 @@ private static boolean isBlank(String s) { private AdvancedCorePlugin plugin; + /** + * Gets the value request commands. + * + * @return the value request commands + */ @Getter ArrayList valueRequestCommands = new ArrayList<>(); + /** + * Instantiates a new command loader. + * + * @param plugin the plugin + */ public CommandLoader(AdvancedCorePlugin plugin) { this.plugin = plugin; } + /** + * Adds a permission. + * + * @param perm the permission + */ public void addPermission(String perm) { if (!perms.contains(perm)) { perms.add(perm); } } + /** + * Gets the basic admin commands. + * + * @param permPrefix the permission prefix + * @return the basic admin commands + */ public ArrayList getBasicAdminCommands(String permPrefix) { ArrayList cmds = new ArrayList<>(); @@ -717,6 +743,12 @@ public void execute(CommandSender sender, String[] args) { return cmds; } + /** + * Gets the basic commands. + * + * @param permPrefix the permission prefix + * @return the basic commands + */ public ArrayList getBasicCommands(String permPrefix) { ArrayList cmds = new ArrayList<>(); @@ -757,6 +789,9 @@ public void execute(CommandSender sender, String[] args) { return cmds; } + /** + * Loads value request commands. + */ public void loadValueRequestCommands() { ArrayList cmds = new ArrayList<>(); cmds.add( diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/gui/ChoiceGUI.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/gui/ChoiceGUI.java index 39bcedf26a..e8692b0b09 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/gui/ChoiceGUI.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/command/gui/ChoiceGUI.java @@ -39,6 +39,11 @@ public static ChoiceGUI getInstance() { private ChoiceGUI() { } + /** + * Opens the claim choices GUI. + * + * @param player the player + */ public void openClaimChoices(Player player) { AdvancedCoreUser user = plugin.getUserManager().getUser(player); BInventory inv = new BInventory("UnClaimed Choices"); @@ -67,6 +72,12 @@ public void onClick(ClickEvent clickEvent) { inv.openInventory(player); } + /** + * Opens the claim choices GUI for a reward. + * + * @param player the player + * @param reward the reward + */ public void openClaimChoices(Player player, Reward reward) { if (!reward.getConfig().getEnableChoices()) { player.sendMessage("Choice rewards not enabled"); @@ -113,6 +124,12 @@ public void run() { inv.openInventory(player); } + /** + * Opens the preference reward GUI. + * + * @param player the player + * @param rewardName the reward name + */ public void openPreferenceReward(Player player, String rewardName) { Reward reward = plugin.getRewardHandler().getReward(rewardName); if (!reward.getConfig().getEnableChoices()) { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AdvancedCoreLoginEvent.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AdvancedCoreLoginEvent.java index fde0f42825..4bb066d2e6 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AdvancedCoreLoginEvent.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AdvancedCoreLoginEvent.java @@ -20,25 +20,49 @@ public class AdvancedCoreLoginEvent extends Event { private static final HandlerList handlers = new HandlerList(); + /** + * Gets the handler list for this event. + * + * @return the handler list + */ public static HandlerList getHandlerList() { return handlers; } private boolean cancelled; + /** + * Gets the AdvancedCoreUser associated with this login event. + * + * @return the user + */ @Getter private final AdvancedCoreUser user; + /** + * Gets the Player associated with this login event. + * + * @return the player + */ @Getter private final Player player; /** * UUID to use for storage/cache lookups. In offline-mode this should be the * name-derived UUID (OfflinePlayer:Name). + * + * @return the UUID string */ @Getter private final String uuid; + /** + * Creates a new AdvancedCoreLoginEvent. + * + * @param user the AdvancedCoreUser + * @param uuid the UUID string + * @param player the Player + */ public AdvancedCoreLoginEvent(AdvancedCoreUser user, String uuid, Player player) { super(true); this.user = user; @@ -51,14 +75,29 @@ public HandlerList getHandlers() { return handlers; } + /** + * Gets whether this event is cancelled. + * + * @return true if cancelled, false otherwise + */ public boolean isCancelled() { return cancelled; } + /** + * Sets whether this event is cancelled. + * + * @param bln true to cancel, false otherwise + */ public void setCancelled(boolean bln) { cancelled = bln; } + /** + * Checks if the user is already in storage. + * + * @return true if user exists in storage, false otherwise + */ public boolean isUserInStorage() { if (uuid == null || uuid.isEmpty()) { return false; diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AuthMeLogin.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AuthMeLogin.java index dbc9a47537..df274d446e 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AuthMeLogin.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/AuthMeLogin.java @@ -14,13 +14,26 @@ import fr.xephi.authme.api.v3.AuthMeApi; import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; +/** + * Listens for AuthMe login events and triggers AdvancedCore login events. + */ public class AuthMeLogin implements Listener { private AdvancedCorePlugin plugin; + /** + * Creates a new AuthMe login listener. + * + * @param plugin the plugin instance + */ public AuthMeLogin(AdvancedCorePlugin plugin) { this.plugin = plugin; } + /** + * Handles AuthMe pre-login events. + * + * @param event the AuthMe pre-login event + */ @EventHandler public void authmeLogin(AuthMeAsyncPreLoginEvent event) { plugin.getBukkitScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/LoginSecurityLogin.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/LoginSecurityLogin.java index 12514d45a4..57e3b179cd 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/LoginSecurityLogin.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/listeners/LoginSecurityLogin.java @@ -13,13 +13,26 @@ import com.lenis0012.bukkit.loginsecurity.events.AuthActionEvent; import com.lenis0012.bukkit.loginsecurity.session.AuthActionType; +/** + * Listener for LoginSecurity login events. + */ public class LoginSecurityLogin implements Listener { private AdvancedCorePlugin plugin; + /** + * Creates a new LoginSecurity login listener. + * + * @param plugin the plugin instance + */ public LoginSecurityLogin(AdvancedCorePlugin plugin) { this.plugin = plugin; } + /** + * Handles LoginSecurity login events. + * + * @param event the login event + */ @EventHandler public void loginSecurityLogin(AuthActionEvent event) { if (!event.getType().equals(AuthActionType.LOGIN)) { diff --git a/AdvancedCore/src/main/java/com/bencodez/advancedcore/thread/FileThread.java b/AdvancedCore/src/main/java/com/bencodez/advancedcore/thread/FileThread.java index 72c744db56..d235193e24 100644 --- a/AdvancedCore/src/main/java/com/bencodez/advancedcore/thread/FileThread.java +++ b/AdvancedCore/src/main/java/com/bencodez/advancedcore/thread/FileThread.java @@ -19,6 +19,11 @@ public class FileThread { */ public class ReadThread extends java.lang.Thread { + /** + * Deletes a player file. + * + * @param uuid the player UUID + */ @Deprecated public void deletePlayerFile(String uuid) { synchronized (FileThread.getInstance()) { @@ -35,6 +40,13 @@ public void deletePlayerFile(String uuid) { } } + /** + * Gets data for a player. + * + * @param userData the user data + * @param uuid the player UUID + * @return the file configuration + */ @Deprecated public FileConfiguration getData(UserData userData, String uuid) { synchronized (FileThread.getInstance()) { @@ -54,6 +66,12 @@ public FileConfiguration getData(UserData userData, String uuid) { } + /** + * Gets the player file. + * + * @param uuid the player UUID + * @return the file + */ @Deprecated public File getPlayerFile(String uuid) { synchronized (FileThread.getInstance()) { @@ -74,6 +92,12 @@ public File getPlayerFile(String uuid) { } } + /** + * Checks if a player file exists. + * + * @param uuid the player UUID + * @return true if file exists + */ @Deprecated public boolean hasPlayerFile(String uuid) { synchronized (FileThread.getInstance()) { @@ -113,6 +137,14 @@ public void run(Runnable run) { } + /** + * Sets data for a player. + * + * @param userData the user data + * @param uuid the player UUID + * @param path the data path + * @param value the value to set + */ @Deprecated public void setData(UserData userData, final String uuid, final String path, final Object value) { synchronized (FileThread.getInstance()) {