### Check CommandWhitelist Plugin Availability (Java) Source: https://context7.com/youhavetrouble/commandwhitelist/llms.txt This Java code snippet demonstrates how to check if the CommandWhitelist plugin is installed and enabled within a Bukkit/Spigot server environment. It utilizes the Bukkit API to retrieve the plugin by its name and checks its enabled status. This is crucial for plugins that depend on CommandWhitelist's functionality. ```java import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; public class MyPlugin extends JavaPlugin { private boolean commandWhitelistEnabled = false; @Override public void onEnable() { // Check if CommandWhitelist is installed and enabled Plugin cwPlugin = Bukkit.getPluginManager().getPlugin("CommandWhitelist"); if (cwPlugin != null && cwPlugin.isEnabled()) { commandWhitelistEnabled = true; getLogger().info("CommandWhitelist integration enabled!"); } } public boolean isCommandWhitelistAvailable() { return commandWhitelistEnabled; } } ``` -------------------------------- ### Get Player Commands - Java API Source: https://context7.com/youhavetrouble/commandwhitelist/llms.txt Retrieve commands available to a player and blocked subcommands using the CommandWhitelistBukkit API. This requires the Bukkit API and the CommandWhitelist plugin to be present. It returns HashSets of command names or blocked subcommand strings. ```java import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; import org.bukkit.entity.Player; import java.util.HashSet; public class CommandWhitelistAPI { /** * Get all commands a player can use based on their permissions * @param player The Bukkit player to check * @return HashSet of command names (without leading slash) */ public HashSet getPlayerCommands(Player player) { // Returns commands from default group + any groups the player has permission for return CommandWhitelistBukkit.getCommands(player); } /** * Get subcommands that are blocked for a player * @param player The Bukkit player to check * @return HashSet of blocked subcommand strings (e.g., "help about") */ public HashSet getBlockedSubcommands(Player player) { return CommandWhitelistBukkit.getSuggestions(player); } /** * Get the denied message for a specific command * @param command The command name (without leading slash) * @return The denial message (custom if defined, otherwise global) */ public String getDeniedMessage(String command) { return CommandWhitelistBukkit.getCommandDeniedMessage(command); } /** * Get all commands registered on the server * @return ArrayList of all server command names */ public java.util.ArrayList getAllServerCommands() { return CommandWhitelistBukkit.getServerCommands(); } } ``` -------------------------------- ### Plugin Dependencies - plugin.yml Configuration Source: https://context7.com/youhavetrouble/commandwhitelist/llms.txt Configure your plugin.yml file to establish a soft dependency on the CommandWhitelist plugin. This ensures your plugin can still load and function if CommandWhitelist is not present, but will integrate with it if it is available. ```yaml # plugin.yml for your plugin name: MyPlugin version: 1.0.0 main: com.example.myplugin.MyPlugin api-version: 1.13 # Soft depend - your plugin works without CommandWhitelist softdepend: - CommandWhitelist ``` -------------------------------- ### Java API - Modify Whitelists Programmatically Source: https://context7.com/youhavetrouble/commandwhitelist/llms.txt Add or remove commands from command whitelist groups at runtime using the CommandWhitelistBukkit API. These methods handle updating the group's configuration and saving changes to the config file. They return a boolean indicating success or failure, typically due to a non-existent group. ```java import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.commands.CWCommand; public class WhitelistModification { /** * Add a command to a group's whitelist * @param command The command to add (without leading slash) * @param group The group name to add it to * @return true if successful, false if group doesn't exist */ public boolean addCommandToWhitelist(String command, String group) { ConfigCache configCache = CommandWhitelistBukkit.getConfigCache(); // CWCommand.addToWhitelist handles: // 1. Adding command to group // 2. Saving to config file return CWCommand.addToWhitelist(configCache, command, group); } /** * Remove a command from a group's whitelist * @param command The command to remove (without leading slash) * @param group The group name to remove it from * @return true if successful, false if group doesn't exist */ public boolean removeCommandFromWhitelist(String command, String group) { ConfigCache configCache = CommandWhitelistBukkit.getConfigCache(); return CWCommand.removeFromWhitelist(configCache, command, group); } /** * Example: Dynamically manage commands based on events */ public void dynamicCommandManagement() { ConfigCache config = CommandWhitelistBukkit.getConfigCache(); // Add fly command to VIP group boolean added = CWCommand.addToWhitelist(config, "fly", "vip"); if (added) { System.out.println("Successfully added /fly to VIP group"); } // Remove dangerous command from default group boolean removed = CWCommand.removeFromWhitelist(config, "op", "default"); if (removed) { System.out.println("Successfully removed /op from default group"); } } } ``` -------------------------------- ### Access Config Cache - Java API Source: https://context7.com/youhavetrouble/commandwhitelist/llms.txt Access the plugin's configuration cache to retrieve group information and message strings. This method requires the Bukkit API and the CommandWhitelist plugin. It returns a ConfigCache object containing HashMaps and Strings representing the plugin's configuration. ```java import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.CWGroup; import java.util.HashMap; import java.util.HashSet; public class ConfigCacheExample { public void accessConfigCache() { // Get the config cache instance ConfigCache configCache = CommandWhitelistBukkit.getConfigCache(); // Get all configured groups HashMap groups = configCache.getGroupList(); // Iterate through groups for (String groupName : groups.keySet()) { CWGroup group = groups.get(groupName); // Get group properties String id = group.getId(); // "default", "vip", etc. String permission = group.getPermission(); // "commandwhitelist.group.default" HashSet commands = group.getCommands(); // ["help", "spawn", ...] HashSet subcommands = group.getSubCommands(); // ["help about", ...] String deniedMsg = group.getCommandDeniedMessage(); // Custom denied message or null System.out.println("Group: " + id); System.out.println("Permission: " + permission); System.out.println("Commands: " + commands); System.out.println("Blocked subcommands: " + subcommands); } // Access message strings String prefix = configCache.prefix; String commandDenied = configCache.command_denied; String subcommandDenied = configCache.subcommand_denied; String noPermission = configCache.no_permission; } } ``` -------------------------------- ### Java API - CWGroup Operations Source: https://context7.com/youhavetrouble/commandwhitelist/llms.txt Create and manipulate CWGroup instances programmatically. This API allows for the creation of new groups with specified whitelisted commands, blacklisted subcommands, and custom denied messages. You can also modify these properties at runtime and serialize the group's state for storage. ```java import eu.endermite.commandwhitelist.common.CWGroup; import java.util.Arrays; import java.util.HashSet; import java.util.List; public class CWGroupExample { /** * Create and manipulate a CWGroup instance */ public void workWithGroups() { // Create a new group programmatically List commands = Arrays.asList("help", "spawn", "home"); List subcommands = Arrays.asList("help about", "home delete"); String customDeniedMessage = "You need premium to use this!"; CWGroup premiumGroup = new CWGroup( "premium", // Group ID commands, // Whitelisted commands subcommands, // Blacklisted subcommands customDeniedMessage // Custom denied message ); // Get group information String id = premiumGroup.getId(); // "premium" String permission = premiumGroup.getPermission(); // "commandwhitelist.group.premium" // Modify commands at runtime premiumGroup.addCommand("fly"); premiumGroup.addCommand("heal"); premiumGroup.removeCommand("home"); // Modify subcommands at runtime premiumGroup.addSubCommand("fly toggle"); premiumGroup.removeSubCommand("help about"); // Get current state HashSet currentCommands = premiumGroup.getCommands(); HashSet currentSubcommands = premiumGroup.getSubCommands(); String deniedMessage = premiumGroup.getCommandDeniedMessage(); // Serialize for config storage // Returns HashMap with "commands" and "subcommands" keys java.util.HashMap serialized = premiumGroup.serialize(); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.