### Good Code Formatting Example Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/CONTRIBUTING.md This example demonstrates correct code formatting, including proper spacing around parentheses and braces, and consistent indentation. ```Java if (var.func(param1, param2)) { // do things } ``` -------------------------------- ### Bad Code Formatting Example Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/CONTRIBUTING.md This example illustrates incorrect code formatting, highlighting issues such as missing spaces around parentheses and inconsistent brace placement. ```Java if(var.func( param1, param2 )) { // do things } ``` -------------------------------- ### Example Usage: Resolving Player Name to UUID and Adding to Region Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Demonstrates how to find a player by name, get their UUID, and add them to a region's owners domain. Requires WorldGuard instance and region object. ```java ProfileService service = WorldGuard.getInstance() .getProfileService(); // Resolve name to UUID Profile profile = service.findByName("PlayerName"); if (profile != null) { UUID uuid = profile.getUniqueId(); // Add to region DefaultDomain domain = region.getOwners(); domain.addPlayer(uuid); } ``` -------------------------------- ### Query Applicable Regions Example Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Demonstrates querying regions at a position and checking the BUILD flag. ```java ApplicableRegionSet regions = mgr.queryApplicableRegions(pos); if (!regions.testState(null, Flags.BUILD)) { player.sendMessage("You cannot build here"); } ``` -------------------------------- ### WorldGuard Setup Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Initializes WorldGuard after the platform has been set, including creating the executor service and profile cache. ```APIDOC ## setup() ### Description Initialize WorldGuard after platform is set. Creates executor service and profile cache. ### Method ```java public void setup() ``` ### Example ```java wg.setPlatform(new BukkitWorldGuardPlatform()); wg.setup(); ``` ``` -------------------------------- ### Add and Save Region Example Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Demonstrates adding a new cuboid region and then saving all regions. ```java RegionManager mgr = container.get(world); ProtectedCuboidRegion region = new ProtectedCuboidRegion("spawn", pt1, pt2); mgr.addRegion(region); mgr.save(); ``` -------------------------------- ### SessionHandler.onInitialize Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md This method is invoked when a player's session is initially created, providing an opportunity for setup. ```APIDOC ## onInitialize(Session session, LocalPlayer player) ### Description Called when session is created for the player. ### Method ```java void onInitialize(Session session, LocalPlayer player) ``` ### Parameters #### Path Parameters - **session** (Session) - Required - New session - **player** (LocalPlayer) - Required - The player ``` -------------------------------- ### Get WorldGuard Platform Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Obtain the WorldGuard platform instance to access platform-specific configurations and services. ```java WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform(); // Access world-specific configuration WorldConfiguration worldConfig = platform .getGlobalStateManager() .get(world); ``` -------------------------------- ### Get Global Configuration Manager Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieve the global configuration manager to access settings for all worlds. Use this to get a specific world's configuration. ```java ConfigurationManager config = WorldGuard.getInstance() .getPlatform() .getGlobalStateManager(); WorldConfiguration worldConfig = config.get(world); ``` -------------------------------- ### Test State Example Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Checks if a player is allowed to build and place blocks based on region states. ```java if (regions.testState(player, Flags.BUILD, Flags.BLOCK_PLACE)) { // Player can place blocks } ``` -------------------------------- ### Blacklist File Format Example Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Illustrates the YAML format for defining blacklists, including aliases and specific actions for material interactions. ```yaml # Aliases for materials alias: diamondpickaxe: 278 # Blacklist entries on *: - lava bucket - water bucket on break-block: - diamond ore on place-block: - tnt on interact-block: - flint and steel: deny, tell You cannot use flint and steel ``` -------------------------------- ### Initialize WorldGuard Setup Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Initialize WorldGuard after setting the platform. This process creates necessary components like the executor service and profile cache, preparing WorldGuard for use. ```java wg.setPlatform(new BukkitWorldGuardPlatform()); wg.setup(); ``` -------------------------------- ### Get WorldGuard Instance Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/README.md Retrieves the singleton instance of the WorldGuard API. ```APIDOC ## Get the WorldGuard Instance ### Description Retrieves the singleton instance of the WorldGuard API, which serves as the main entry point for accessing its functionalities. ### Method `WorldGuard.getInstance()` ### Endpoint N/A (Java method call) ### Parameters None ### Request Example ```java WorldGuard wg = WorldGuard.getInstance(); ``` ### Response #### Success Response - **wg** (WorldGuard) - The singleton instance of the WorldGuard API. #### Response Example ```java // wg variable now holds the WorldGuard instance ``` ``` -------------------------------- ### Initialize WorldGuard API Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/usage-guide.md Get the singleton instance of WorldGuard and access its platform and region container. The platform must be set before accessing the region container. ```java WorldGuard wg = WorldGuard.getInstance(); WorldGuardPlatform platform = wg.getPlatform(); RegionContainer container = platform.getRegionContainer(); RegionManager manager = container.get(world); ``` -------------------------------- ### Example Custom Session Handler Implementation Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md A basic implementation of the SessionHandler interface. Includes methods for initialization and ticking, along with custom data fields and accessors. ```java public class MyCustomHandler implements SessionHandler { private LocalPlayer player; private String customData; public MyCustomHandler(LocalPlayer player) { this.player = player; this.customData = "default"; } @Override public void onInitialize(Session session, LocalPlayer player) { // Called when session is created this.player = player; } @Override public void tick(Session session, LocalPlayer player) { // Called every tick // Can be used to check conditions and fire events checkPosition(player); } private void checkPosition(LocalPlayer player) { // Custom logic each tick } public String getCustomData() { return customData; } public void setCustomData(String data) { this.customData = data; } } ``` -------------------------------- ### Initialize Region Container Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Initializes the RegionContainer, which is responsible for loading all region data for all worlds. This is a crucial setup step. ```java public void initialize() ``` -------------------------------- ### Get Configuration Directory Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Obtain the path to the WorldGuard configuration directory. This can be used to access or create configuration files. ```java Path configDir = WorldGuard.getInstance() .getPlatform() .getConfigDir(); File blacklistFile = configDir.resolve("blacklist.txt").toFile(); ``` -------------------------------- ### Get Player Domain from DefaultDomain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Retrieves the PlayerDomain component from a DefaultDomain instance. ```java public PlayerDomain getPlayerDomain() ``` -------------------------------- ### WorldGuard Platform Access Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Gets the current platform implementation (e.g., Bukkit, Sponge) that WorldGuard is running on. ```APIDOC ## getPlatform ### Description Get the current platform implementation. ### Method ```java public WorldGuardPlatform getPlatform() ``` ### Returns `WorldGuardPlatform` — The platform (Bukkit, Sponge, etc.) ### Throws - `NullPointerException` if WorldGuard is not enabled ### Example ```java WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform(); ``` ``` -------------------------------- ### Access Global Configuration Manager Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Get the global configuration manager to access world-specific configurations and the selected storage driver. ```java ConfigurationManager globalConfig = platform.getGlobalStateManager(); // World-specific config WorldConfiguration worldConfig = globalConfig.get(world); // Selected storage driver RegionDriver driver = globalConfig.selectedRegionStoreDriver; ``` -------------------------------- ### Get WorldGuard Version Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Retrieve the current version string of the WorldGuard plugin. ```java WorldGuard.getVersion() // Returns version string ``` -------------------------------- ### Track Player Actions in Session Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md Implement a SessionHandler to track player actions like blocks broken and placed, and calculate session duration. The onInitialize method is used to record the session start time. ```java public class ActionTrackingHandler implements SessionHandler { private int blocksBroken = 0; private int blocksPlaced = 0; private long sessionStart; @Override public void onInitialize(Session session, LocalPlayer player) { sessionStart = System.currentTimeMillis(); } public void recordBlockBroke() { blocksBroken++; } public void recordBlockPlaced() { blocksPlaced++; } public int getTotalBlocks() { return blocksBroken + blocksPlaced; } public long getSessionLength() { return System.currentTimeMillis() - sessionStart; } } ``` -------------------------------- ### Get Flag Registry Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Access the default flag registry. This is initialized automatically on WorldGuard startup. ```java FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); ``` -------------------------------- ### Get Player Names from DefaultDomain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Retrieves a set of all player names currently in the domain. ```java public Set getPlayers() ``` -------------------------------- ### Inspect Region Flags Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Get all flags and their values for a given region and print them to the console. ```java Map, Object> flags = region.getFlags(); for (Flag flag : flags.keySet()) { Object value = flags.get(flag); System.out.println(flag.getName() + " = " + value); } ``` -------------------------------- ### Registering Custom Handler in Plugin Initialization Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md Demonstrates how to register a custom session handler when a plugin is enabled. This ensures the handler is available for player sessions from the start. ```java // In your plugin initialization public void onEnable() { SessionManager manager = WorldGuard.getInstance() .getPlatform() .getSessionManager(); manager.registerHandler( MyCustomHandler.class, (session, player) -> new MyCustomHandler(player) ); } ``` -------------------------------- ### Get WorldGuard Platform Implementation Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Obtain the current platform implementation (e.g., Bukkit, Sponge) that WorldGuard is integrated with. This is useful for platform-specific operations. ```java WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform(); ``` -------------------------------- ### Get WorldGuard Instance Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/README.md Obtain the singleton instance of the WorldGuard API. This is the primary entry point for accessing most WorldGuard functionalities. ```java WorldGuard wg = WorldGuard.getInstance(); ``` -------------------------------- ### Block Ore Mining and Placement Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/worldguard-bukkit/src/main/resources/defaults/blacklist.txt Example configuration to block the mining and placement of specific ores. It logs the event and denies the action, while also notifying admins and ignoring certain player groups. ```yaml # Example to block some ore mining and placement: #[coal_ore,gold_ore,iron_ore] #on-break=deny,log,kick #on-place=deny,tell ``` ```yaml # Deny some ore #[coal_ore,gold_ore,iron_ore] #ignore-groups=admins,mods #on-break=notify,deny,log ``` -------------------------------- ### Safely Unmarshalling and Setting Flags Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/errors.md This example shows how to safely unmarshal user input for a flag and set it on a region, catching InvalidFlagFormat exceptions and informing the player. ```java Flag flag = registry.get(flagName); try { Object value = flag.unmarshal(userInput); region.setFlag(flag, value); } catch (InvalidFlagFormat e) { player.sendMessage(ChatColor.RED + "Invalid: " + e.getMessage()); } ``` -------------------------------- ### Get Unique Player IDs from DefaultDomain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Retrieves a set of all unique player UUIDs currently in the domain. ```java public Set getUniqueIds() ``` -------------------------------- ### Get Region Manager Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Access the RegionContainer to get the RegionManager for a specific world. The RegionManager is used to interact with regions within that world. ```java RegionContainer container = wg.getPlatform() .getRegionContainer(); RegionManager manager = container.get(world); ``` -------------------------------- ### Get World Configuration Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieve the WorldConfiguration for a specific world. Returns null if the configuration is not loaded. The 'world' parameter is required. ```java ConfigurationManager config = WorldGuard.getInstance() .getPlatform() .getGlobalStateManager(); WorldConfiguration worldConfig = config.get(world); if (worldConfig == null) { logger.warning("No configuration for world"); return; } ``` -------------------------------- ### Preventing Flag Conflict Before Registration Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/errors.md This example demonstrates how to check if a flag already exists in the registry before attempting to register it, thus preventing a FlagConflictException. ```java FlagRegistry registry = WorldGuard.getInstance() .getFlagRegistry(); StringFlag flag = new StringFlag("my-plugin:custom"); if (registry.get("my-plugin:custom") == null) { registry.register(flag); } ``` -------------------------------- ### Create and Load Regions Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-storage.md Demonstrates how to create a database for a world and load all regions using the RegionDriver and RegionDatabase. ```java RegionDriver driver = container.getDriver(); RegionDatabase db = driver.create("world"); Set regions = db.loadAll(registry); ``` -------------------------------- ### Get Configured World Names Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieve a set of all configured world names. This provides a list of identifiers for worlds with loaded configurations. ```java Set getWorlds() ``` -------------------------------- ### Get World Configuration by Name Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieve the WorldConfiguration using the world's name. Returns null if no configuration is found for the given name. ```java @Nullable WorldConfiguration get(String worldName) ``` -------------------------------- ### Get Player UUID Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieves the unique identifier (UUID) of a player. ```java public UUID getUniqueId() ``` -------------------------------- ### PlayerDomain Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Creates an empty player domain. ```APIDOC ## PlayerDomain() ### Description Create an empty player domain. ### Method PlayerDomain ### Endpoint N/A (Constructor call) ### Parameters None ### Response None ``` -------------------------------- ### LocalPlayer Get Health Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the current health points of the player. ```APIDOC ## getHealth() ### Description Get the player's current health. ### Method ```java double getHealth() ``` ### Returns `double` — Health value (0.0 to max health) ``` -------------------------------- ### Get All Regions Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves an immutable map of all regions, keyed by their IDs. ```java public Map getRegions() ``` -------------------------------- ### Create and Register Custom Flags Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Demonstrates how to create custom state, integer, string, and set flags and register them with the Flag Registry. ```java // State flag (allow/deny) StateFlag customState = new StateFlag("my-state", true); // Integer flag IntegerFlag maxPlayers = new IntegerFlag("max-players"); // String flag StringFlag motd = new StringFlag("motd"); // Set flag SetFlag blockedItems = new SetFlag<>( "blocked-items", new StringFlag(null) ); // Register all FlagRegistry registry = WorldGuard.getInstance() .getFlagRegistry(); try { registry.register(customState); registry.register(maxPlayers); registry.register(motd); registry.register(blockedItems); } catch (FlagConflictException e) { // Handle conflict } ``` -------------------------------- ### Get Build Flag Value Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves the state of the BUILD flag for a given region. This is useful for checking build permissions. ```java State buildState = region.getFlag(Flags.BUILD); ``` -------------------------------- ### WorldGuard Initialization Order Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Provides the correct sequence for initializing WorldGuard, its platform, region container, and loading world regions. ```java // 1. Create and set platform WorldGuard wg = WorldGuard.getInstance(); wg.setPlatform(new BukkitWorldGuardPlatform()); // 2. Initialize (creates cache, executor, etc) wg.setup(); // 3. Initialize region container RegionContainer container = wg.getPlatform() .getRegionContainer(); container.initialize(); // 4. Load world regions for (World world : server.getWorlds()) { RegionManager manager = container.get(world); if (manager != null) { manager.load(); } } // 5. Platform-specific initialization wg.getPlatform().load(); ``` -------------------------------- ### Get Group Domain from DefaultDomain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Retrieves the GroupDomain component from a DefaultDomain instance. ```java public GroupDomain getGroupDomain() ``` -------------------------------- ### Create Player Domain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Creates an empty domain specifically for player membership. ```java public PlayerDomain() ``` -------------------------------- ### Build WorldGuard on Windows Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/COMPILING.md Execute this command in PowerShell within the WorldGuard project folder to build the project on Windows. ```bash gradlew build ``` -------------------------------- ### Get actions for a blacklisted item Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Retrieves a list of actions to be executed when a blacklisted item is encountered for a specific event. This allows for custom responses like denying the action, notifying the player, or logging the event. ```java public List getActions(ItemStack item, BlacklistEvent event) ``` -------------------------------- ### Build WorldGuard on Linux/BSD/Mac OS X Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/COMPILING.md Navigate to the WorldGuard project directory in your terminal and run this command to build the project on Unix-like systems. ```bash ./gradlew build ``` -------------------------------- ### Get Group Names from DefaultDomain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Retrieves a set of all group names currently in the domain. ```java public Set getGroups() ``` -------------------------------- ### Get or Create Player Session Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md Obtain the Session object for a given player. If a session does not exist, it will be created. This is the primary method to access a player's session data and handlers. ```java SessionManager manager = WorldGuard.getInstance() .getPlatform() .getSessionManager(); Session session = manager.get(player); // Use session String data = session.getHandler(CustomHandler.class) .getData(); ``` -------------------------------- ### Get Profile Service Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Obtain the ProfileService for handling player profiles, which includes fetching and caching player data. This is useful for identity-related operations. ```java ProfileService service = wg.getProfileService(); ``` -------------------------------- ### Get All Regions at Position Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/usage-guide.md Queries and lists all applicable regions at a specific block vector position. ```java BlockVector3 pos = player.getLocation().toVector().toBlockPoint(); ApplicableRegionSet regions = manager .queryApplicableRegions(pos); // List all applicable regions for (ProtectedRegion region : regions) { player.sendMessage("Region: " + region.getId()); } ``` -------------------------------- ### Get actions for a blacklist entry and event Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Retrieves the list of actions associated with a BlacklistEntry for a specific BlacklistEvent. This method is used to define what happens when the entry's conditions are met. ```java public List getActions(BlacklistEvent event) ``` -------------------------------- ### Create Profile Service Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Create a profile service for resolving player names and UUIDs, utilizing a provided ProfileCache. The cache parameter is required. ```java ProfileService createProfileService(ProfileCache cache) ``` -------------------------------- ### Get Region by ID Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves a region using its unique ID. Returns the region or null if it does not exist. ```java @Nullable public ProtectedRegion getRegion(String id) ``` -------------------------------- ### DefaultDomain Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Creates a new, empty DefaultDomain instance. ```java public DefaultDomain() ``` -------------------------------- ### Create Region Manager Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Instantiate a RegionManager with a storage driver, a region index factory, and a flag registry. Load existing regions after creation. ```java RegionDatabase store = driver.create("world"); FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); // Create with default index RegionManager manager = new RegionManager( store, name -> new ConcurrentRegionIndex(), registry ); // Load existing regions manager.load(); ``` -------------------------------- ### Get Region Association Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Determines the membership level (OWNER, MEMBER, or NON_MEMBER) for a given list of regions. ```java Association getAssociation(List regions) ``` -------------------------------- ### ProtectedRegion Methods Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Provides methods for interacting with a protected region, such as getting a comparable volume or comparing regions. ```APIDOC ## getComparableVolume() ### Description Get a volume estimate for comparison purposes. ### Returns `long` — Comparable volume ## compareTo(ProtectedRegion other) ### Description Compare regions for sorting (by ID then priority). ### Parameters #### Path Parameters - **other** (ProtectedRegion) - Yes - Region to compare ### Returns `int` — Comparison result (-1, 0, 1) ``` -------------------------------- ### Async Region Loading Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Shows how to load regions asynchronously using an executor service and handle completion with listeners. ```java // Use supervisor for async tasks ListeningExecutorService executor = wg.getExecutorService(); // Load regions async ListenableFuture future = executor.submit( () -> manager.load() ); // Wait for completion future.addListener(() -> { // Loading complete }, MoreExecutors.directExecutor()); ``` -------------------------------- ### KickAction Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Use this to kick a player from the server when a blacklist event occurs. Requires a String message. ```java public KickAction(String message) ``` -------------------------------- ### Add Player to DefaultDomain by LocalPlayer Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Adds a player to the domain using a LocalPlayer object. Requires a LocalPlayer object. ```java public void addPlayer(LocalPlayer player) ``` -------------------------------- ### Add Player to DefaultDomain by Name Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Adds a player to the domain using their name. Requires a String representing the player's name. ```java public void addPlayer(String name) ``` -------------------------------- ### FlagRegistry get Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-flags.md Retrieves a registered flag from the WorldGuard flag registry by its name. Returns null if the flag is not found. ```APIDOC ## get(String name) ### Description Get a flag by name. Returns null if the flag is not found. ### Method ```java @Nullable Flag get(String name) ``` ### Parameters #### Path Parameters - **name** (String) - Required - Flag name ### Response #### Success Response (Flag) - **Flag** - The flag or null ``` -------------------------------- ### addPlayer(String name) Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Adds a player to the domain by their name. ```APIDOC ## addPlayer(String name) ### Description Add a player by name. ### Method void ### Endpoint N/A (Method call) ### Parameters #### Path Parameters - **name** (String) - Required - Player name ### Response None ``` -------------------------------- ### Get Player Saturation Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the player's food saturation level. This affects how quickly hunger depletes. ```java double getSaturation() ``` -------------------------------- ### Check Build Permissions Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Query applicable regions at a position and test if the player has the BUILD flag enabled. ```java ApplicableRegionSet regions = manager .queryApplicableRegions(position); if (!regions.testState(player, Flags.BUILD)) { // Cannot build } ``` -------------------------------- ### RegionManager Methods Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Manages regions for a single world, providing methods to get the manager name and load regions. ```APIDOC ## getName() ### Description Get the displayable name for this region manager. ### Returns `String` — Manager name (typically world name) ## load() ### Description Load all regions from storage. ### Throws - `StorageException` on load failure ``` -------------------------------- ### LogAction Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Use this to log a blacklist event. This action does not require any parameters. ```java public LogAction() ``` -------------------------------- ### GroupDomain Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Creates an empty group domain. ```APIDOC ## GroupDomain() ### Description Create an empty group domain. ### Method GroupDomain ### Endpoint N/A (Constructor call) ### Parameters None ### Response None ``` -------------------------------- ### Get Polygon Points of a Protected Region Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves an immutable list of the 2D points that define the boundary of a ProtectedPolygonalRegion. ```java public List getPoints() ``` -------------------------------- ### TellAction Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Use this to send a message to the player when a blacklist event occurs. Requires a String message. ```java public TellAction(String message) ``` -------------------------------- ### RegionDriver.create Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-storage.md Creates or retrieves a database for a specific world. This is the entry point for interacting with region storage for a given world. ```APIDOC ## RegionDriver.create(String name) ### Description Create or get a database for a world. ### Method ```java public interface RegionDriver ``` ### Parameters #### Path Parameters - **name** (String) - Required - World name ### Returns `RegionDatabase` — Database for world ### Throws - `StorageException` on creation failure ``` -------------------------------- ### Get Player Fire Ticks Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the remaining number of ticks the player will be on fire. A value of 0 means not on fire. ```java int getFireTicks() ``` -------------------------------- ### ConfigurationManager Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Manager for world and global configuration. ```APIDOC ## ConfigurationManager ### Description Manager for world and global configuration settings. ### Methods - **get(World world)** - Parameters: - world (World): Required - World to get config for - Returns: `WorldConfiguration` — Config or null if not loaded - **get(String worldName)** - Parameters: - worldName (String): Required - World identifier - Returns: `WorldConfiguration` — Config or null - **getWorlds()** - Returns: `Set` — World identifiers - **setSelectedRegionStoreDriver(String driver)** - Parameters: - driver (String): Required - Driver name (yaml, sqlite, mysql, etc) - **getSelectedRegionStoreDriver()** - Returns: `String` — Driver name ``` -------------------------------- ### Get Region Members Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/usage-guide.md Retrieves sets of player UUIDs, player names, and group names from a region's members. ```java DefaultDomain domain = region.getMembers(); // Get all player UUIDs Set playerIds = domain.getUniqueIds(); // Get all player names Set names = domain.getPlayers(); // Get all groups Set groups = domain.getGroups(); ``` -------------------------------- ### Get Player Weather Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the player's currently overridden weather type. Returns null if the weather is not overridden. ```java WeatherType getPlayerWeather() ``` -------------------------------- ### Get Player Exhaustion Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the player's food exhaustion level. High exhaustion accelerates hunger depletion. ```java float getExhaustion() ``` -------------------------------- ### Get Player Food Level Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the player's current hunger level. The value ranges from 0 to 20. ```java double getFoodLevel() ``` -------------------------------- ### Get Player Max Health Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the player's maximum health value. This is useful for understanding health limits. ```java double getMaxHealth() ``` -------------------------------- ### Initialize HashMap Cache Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Creates an in-memory cache for profiles. This cache loses data on restart. ```java ProfileCache cache = new HashMapCache(); // In-memory only, loses data on restart ``` -------------------------------- ### WorldGuard Exception Converter Access Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Gets the exception converter responsible for translating internal WorldGuard exceptions into user-friendly messages. ```APIDOC ## getExceptionConverter ### Description Get the exception converter for translating internal exceptions to user-friendly messages. ### Method ```java public WorldGuardExceptionConverter getExceptionConverter() ``` ### Returns `WorldGuardExceptionConverter` — The converter ``` -------------------------------- ### Initialize SQLite Profile Cache Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Attempt to create a SQLite-based profile cache. If an error occurs (e.g., IO error, UnsatisfiedLinkError), fall back to an in-memory HashMap cache. ```java File cacheDir = new File(configDirectory, "cache"); cacheDir.mkdirs(); try { ProfileCache cache = new SQLiteCache( new File(cacheDir, "profiles.sqlite") ); } catch (IOException | UnsatisfiedLinkError e) { // Fallback to memory cache ProfileCache cache = new HashMapCache(); } ``` -------------------------------- ### RegionDatabase.loadAll Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-storage.md Loads all regions from storage for the current world. Requires a FlagRegistry for parsing region flags. ```APIDOC ## RegionDatabase.loadAll(FlagRegistry registry) ### Description Load all regions from storage. ### Method ```java public interface RegionDatabase ``` ### Parameters #### Path Parameters - **registry** (FlagRegistry) - Required - Flag registry for parsing flags ### Returns `Set` — All regions ### Throws - `StorageException` on load failure ### Request Example ```java RegionDriver driver = container.getDriver(); RegionDatabase db = driver.create("world"); Set regions = db.loadAll(registry); ``` ``` -------------------------------- ### sendTitle(String title, String subtitle) Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Displays a title and an optional subtitle to the player on their screen. ```APIDOC ## sendTitle(String title, String subtitle) ### Description Display a title and subtitle to the player. ### Parameters #### Path Parameters - **title** (String) - Yes - Main title text - **subtitle** (String) - Yes - Subtitle text ``` -------------------------------- ### Create SQLite Profile Cache Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Initializes a persistent profile cache using an SQLite database file. Handles potential IO errors during creation and requires the SQLite library. ```java File cacheDir = new File(configDir, "cache"); cacheDir.mkdirs(); try { ProfileCache cache = new SQLiteCache( new File(cacheDir, "profiles.sqlite") ); } catch (IOException | UnsatisfiedLinkError e) { ProfileCache cache = new HashMapCache(); } ``` -------------------------------- ### Get Player Time Offset Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the player's time offset in ticks, used when their time is set relative to the server. ```java long getPlayerTimeOffset() ``` -------------------------------- ### Get Player Session Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieves the session object associated with a specific player. This is useful for accessing player-specific data within WorldGuard. ```java Session session = WorldGuard.getInstance() .getPlatform() .getSessionManager() .get(player); ``` -------------------------------- ### Get Region Store Driver Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieve the name of the currently selected region storage driver. This indicates how region data is being persisted. ```java String getSelectedRegionStoreDriver() ``` -------------------------------- ### Add Player to DefaultDomain by UUID Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Adds a player to the domain using their UUID. Requires a UUID object. ```java public void addPlayer(UUID uuid) ``` -------------------------------- ### Get Region Manager Name Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves the displayable name of the RegionManager, which typically corresponds to the world's name. This is useful for identification. ```java public String getName() ``` -------------------------------- ### HashMapCache Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Initializes a new in-memory profile cache. This cache is volatile and will lose all data upon application restart. ```APIDOC ## HashMapCache() ### Description Create an in-memory cache (loses data on restart). ### Method ```java public HashMapCache() ``` ``` -------------------------------- ### Session Handler Best Practices: Accessing Data Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md Demonstrates how to store and access per-player data within a custom session handler. Data is stored in the handler and accessed via the session manager. ```java // Store per-player data in handler public class PlayerDataHandler implements SessionHandler { private UUID playerUUID; private int killCount = 0; public void incrementKills() { killCount++; } public int getKillCount() { return killCount; } } // Access from anywhere Session session = sessionManager.get(player); PlayerDataHandler handler = session.getHandler( PlayerDataHandler.class ); int kills = handler.getKillCount(); ``` -------------------------------- ### Get Region Storage Driver Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves the RegionDriver instance from the RegionContainer. The driver handles the actual loading and saving of region data. ```java public RegionDriver getDriver() ``` -------------------------------- ### Region Index Options Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Compares the default ConcurrentRegionIndex (spatial tree) with QuadTreeIndex, recommending the latter for very large region counts due to faster queries at the cost of slower writes. ```java // Default: ConcurrentRegionIndex (spatial tree) // Good for medium/large region counts // Alternative for very large region counts: // QuadTreeIndex (slower writes, faster queries) ``` -------------------------------- ### Get Player Health Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieve the current health points of a player. The value ranges from 0.0 to the player's maximum health. ```java double currentHealth = player.getHealth(); ``` -------------------------------- ### Create Group Domain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Creates an empty domain specifically for group membership. ```java public GroupDomain() ``` -------------------------------- ### Get Comparable Volume of a Protected Region Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves an estimated volume of the region for comparison purposes. This is an abstract method in the base class. ```java public abstract long getComparableVolume() ``` -------------------------------- ### Set Player Domain in DefaultDomain Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Sets the PlayerDomain for a DefaultDomain instance. Requires a PlayerDomain object. ```java public void setPlayerDomain(PlayerDomain domain) ``` -------------------------------- ### Access Configuration Manager Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Obtain the ConfigurationManager to access world-specific configurations and a list of all configured worlds. ```java ConfigurationManager config = wg.getPlatform() .getGlobalStateManager(); // Get world config WorldConfiguration worldConfig = config.get(world); // Get all worlds Set worlds = config.getWorlds(); ``` -------------------------------- ### Get Profile Cache Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Access the player profile cache. The cache defaults to SQLite if available, otherwise it uses an in-memory HashMap. ```java ProfileCache cache = WorldGuard.getInstance().getProfileCache(); // Cache is SQLite if available, otherwise in-memory // Get profile for a player Profile profile = cache.getProfile(uuid); ``` -------------------------------- ### Load Regions for All Worlds Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/usage-guide.md Iterate through all server worlds to load their respective regions and log the count or any storage errors. ```java RegionContainer container = wg.getPlatform() .getRegionContainer(); // Load all worlds for (World world : server.getWorlds()) { RegionManager manager = container.get(world); if (manager != null) { try { manager.load(); int regionCount = manager.getRegions().size(); logger.info("Loaded " + regionCount + " regions in " + world.getName()); } catch (StorageException e) { logger.warning("Cannot load regions for " + world.getName()); } } } ``` -------------------------------- ### Get Cached Profile by Name Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieves a player's profile from the cache using their name. Returns null if the profile is not found in the cache. ```java @Nullable Profile get(String name) ``` -------------------------------- ### Get Cached Profile by UUID Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieves a player's profile from the cache using their UUID. Returns null if the profile is not found in the cache. ```java @Nullable Profile get(UUID uuid) ``` -------------------------------- ### Create HashMap Profile Cache Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Initializes an in-memory profile cache. Note that this cache is volatile and will lose all data upon application restart. ```java public HashMapCache() ``` -------------------------------- ### DefaultDomain Copy Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-domains.md Creates a new DefaultDomain instance as a copy of an existing one. Requires an existing DefaultDomain object. ```java public DefaultDomain(DefaultDomain existing) ``` -------------------------------- ### Get WorldGuard Version Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieve the current version string of the WorldGuard plugin. This is useful for debugging, compatibility checks, or displaying version information. ```java String version = WorldGuard.getVersion(); ``` -------------------------------- ### Get Region Container Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Access the region container to manage region data across all worlds. Obtain a RegionManager for a specific world from the container. ```java RegionContainer container = WorldGuard.getInstance() .getPlatform() .getRegionContainer(); RegionManager manager = container.get(world); ``` -------------------------------- ### Register a Custom String Flag Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-flags.md Demonstrates how to register a new custom string flag with the WorldGuard flag registry. Ensure you have access to the FlagRegistry instance. ```java FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); StringFlag customFlag = new StringFlag("my-custom-flag"); registry.register(customFlag); ``` -------------------------------- ### Get Session Manager Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Access the SessionManager to manage player sessions and their associated states. This is crucial for real-time event handling and state tracking. ```java SessionManager sessionManager = wg.getPlatform() .getSessionManager(); ``` -------------------------------- ### BlacklistLoggerHandler Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Use this constructor to initialize the standard file-based logger. Requires a File object representing the log file path and can throw an IOException. ```java public BlacklistLoggerHandler(File file) throws IOException ``` -------------------------------- ### Programmatic Blacklist Check Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Demonstrates how to check if an item is blacklisted and execute associated actions using the Blacklist API. ```java Blacklist blacklist = new Blacklist(config); // Check item ItemStack item = new ItemStack(Material.DIAMOND_ORE); BlacklistEvent event = new BlockBreakBlacklistEvent(...); if (blacklist.isBlacklisted(item, event)) { // Item is blacklisted List actions = blacklist.getActions(item, event); for (Action action : actions) { action.execute(player, result); } } ``` -------------------------------- ### Generate Eclipse Project Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/COMPILING.md Use this Gradle command to generate an Eclipse project for each folder in the WorldGuard project. ```bash gradlew eclipse ``` -------------------------------- ### Access Profile Service Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Get the profile lookup service for resolving player names and UUIDs. This service is crucial for player identification and management. ```java ProfileService profileService = WorldGuard.getInstance().getProfileService(); ``` -------------------------------- ### BanAction Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Use this to ban a player when a blacklist event occurs. Requires a String message. ```java public BanAction(String message) ``` -------------------------------- ### Load Regions with Error Handling Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Attempt to load regions and catch potential storage exceptions. ```java try { manager.load(); } catch (StorageException e) { // Error handling } ``` -------------------------------- ### Get Session Handler Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Retrieves a specific session handler instance from a player's session. Use this to access custom or built-in handler functionalities. ```java @Nullable T getHandler(Class type) ``` -------------------------------- ### SQLiteCache Constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-platform.md Initializes a new SQLite-based profile cache. This cache persists profile data to a specified SQLite database file. ```APIDOC ## SQLiteCache(File dbFile) ### Description Create a SQLite cache. ### Method ```java public SQLiteCache(File dbFile) throws IOException ``` ### Parameters #### Path Parameters - **dbFile** (File) - Yes - SQLite database file ### Throws - `IOException` if database cannot be created - `UnsatisfiedLinkError` if SQLite library not available ### Example ```java File cacheDir = new File(configDir, "cache"); cacheDir.mkdirs(); try { ProfileCache cache = new SQLiteCache( new File(cacheDir, "profiles.sqlite") ); } catch (IOException | UnsatisfiedLinkError e) { ProfileCache cache = new HashMapCache(); } ``` ``` -------------------------------- ### Get Task Supervisor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieve the task supervisor used for managing asynchronous operations within WorldGuard. This is essential for handling background tasks efficiently. ```java Supervisor supervisor = WorldGuard.getInstance().getSupervisor(); ``` -------------------------------- ### getExhaustion() Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Retrieves the player's current food exhaustion level. High exhaustion depletes saturation faster. ```APIDOC ## getExhaustion() ### Description Get the player's food exhaustion. ### Returns `float` — Exhaustion value ``` -------------------------------- ### Convert WorldGuard Exceptions Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Demonstrates using the WorldGuardExceptionConverter to convert caught exceptions into user-friendly messages for players. ```java WorldGuardExceptionConverter converter = wg .getExceptionConverter(); try { // WorldGuard operation } catch (Exception e) { String message = converter.convert(e); player.sendMessage(message); } ``` -------------------------------- ### Get Region Manager for a World Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-regions.md Retrieves the RegionManager responsible for managing regions within a specific World. Returns null if the world's regions are not loaded. ```java public RegionManager get(World world) ``` -------------------------------- ### Set and Get Region Flags Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Modify or retrieve flags associated with a region. Use these methods to apply specific rules or check existing configurations for a region. ```java region.setFlag(flag, value) ``` ```java region.getFlag(flag) ``` ```java region.getFlags() ``` -------------------------------- ### Query Regions Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Retrieve region information from the RegionManager. Use these methods to query applicable regions at a position, get a specific region by ID, or list all regions. ```java manager.queryApplicableRegions(position) ``` ```java manager.getRegion(id) ``` ```java manager.getRegions() ``` -------------------------------- ### Generate IntelliJ IDEA Module Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/COMPILING.md Use this Gradle command to generate an IntelliJ IDEA module for each folder in the WorldGuard project. ```bash gradlew idea ``` -------------------------------- ### Session Handler Best Practices: Lightweight Tick Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md Compares inefficient and efficient implementations of a session handler's tick method. Avoid heavy computations or I/O operations directly in tick; cache data or perform checks less frequently. ```java // Bad: Heavy computation in tick @Override public void tick(Session session, LocalPlayer player) { // Querying database every tick is slow List bans = database.getBans(); for (Ban ban : bans) { if (ban.getUUID().equals(player.getUniqueId())) { player.kick("You are banned"); } } } // Good: Cache data, check once per player private Set bannedUUIDs; @Override public void onInitialize(Session session, LocalPlayer player) { // Load once bannedUUIDs = database.getBannedUUIDs(); } @Override public void tick(Session session, LocalPlayer player) { // Quick set lookup if (bannedUUIDs.contains(player.getUniqueId())) { player.kick("You are banned"); } } ``` -------------------------------- ### AllowAction constructor Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-blacklist.md Creates a new instance of AllowAction. This action permits the blacklisted item or block to proceed without restriction. ```java public AllowAction() ``` -------------------------------- ### Get Exception Converter Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Obtain the exception converter to translate internal WorldGuard exceptions into user-friendly messages. This improves the player experience by providing clearer error feedback. ```java WorldGuardExceptionConverter exceptionConverter = WorldGuard.getInstance().getExceptionConverter(); ``` -------------------------------- ### Core WorldGuard Imports Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Import the main WorldGuard API classes for core functionality, regions, flags, domains, configuration, platform interactions, and storage. ```java import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionQuery; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.flags.RegionGroup; import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.domains.PlayerDomain; import com.sk89q.worldguard.domains.GroupDomain; import com.sk89q.worldguard.domains.Association; import com.sk89q.worldguard.config.ConfigurationManager; import com.sk89q.worldguard.config.WorldConfiguration; import com.sk89q.worldguard.internal.platform.WorldGuardPlatform; import com.sk89q.worldguard.session.Session; import com.sk89q.worldguard.session.SessionManager; import com.sk89q.worldguard.protection.managers.storage.StorageException; import com.sk89q.worldguard.protection.managers.storage.RegionDriver; import com.sk89q.worldguard.protection.managers.storage.RegionDatabase; import com.sk89q.worldguard.blacklist.Blacklist; import com.sk89q.worldguard.blacklist.action.Action; import com.sk89q.worldguard.blacklist.event.EventType; import com.sk89q.worldguard.util.profile.Profile; import com.sk89q.worldguard.util.profile.cache.ProfileCache; import com.sk89q.worldguard.util.profile.resolver.ProfileService; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; ``` -------------------------------- ### Get Executor Service Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Retrieve the bounded executor service used for asynchronous tasks. It is recommended to use the platform's task scheduling instead of this service directly. ```java ListeningExecutorService executor = WorldGuard .getInstance() .getExecutorService(); // Do not use directly unless necessary // Use getPlatform() for task scheduling instead ``` -------------------------------- ### BlockVector3 Creation Methods Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/types.md Provides static methods to create BlockVector3 instances, representing 3D block coordinates. Supports creation from integer or double values for x, y, and z. ```java BlockVector3.at(int x, int y, int z) ``` ```java BlockVector3.at(double x, double y, double z) ``` -------------------------------- ### Get Region Storage Driver Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Retrieve the configured region storage driver from the global state manager. This driver determines how regions are stored (e.g., SQL, YAML). ```java ConfigurationManager config = WorldGuard.getInstance() .getPlatform() .getGlobalStateManager(); // Get the configured driver RegionDriver driver = config.selectedRegionStoreDriver; // Can be SQL, YAML file-based, etc. ``` -------------------------------- ### Send Title and Subtitle to Player Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Displays a main title and an optional subtitle to the player on their screen. ```java void sendTitle(String title, String subtitle) ``` -------------------------------- ### Create Regions Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Instantiate different types of regions: cuboid, polygonal, or global. Use these constructors to define new region boundaries and properties. ```java new ProtectedCuboidRegion(id, pt1, pt2) ``` ```java new ProtectedPolygonalRegion(id, points, minY, maxY) ``` ```java new GlobalProtectedRegion(id) ``` -------------------------------- ### Catching IOException for File I/O Errors Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/errors.md Use this to handle general file input/output errors, such as file not found or permission issues, when creating a cache. It logs a warning with the specific error message. ```java try { profileCache = new SQLiteCache(cacheFile); } catch (IOException e) { logger.warning("Failed to create profile cache: " + e.getMessage()); } ``` -------------------------------- ### Get Global Executor Service Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-worldguard.md Access the global executor service used internally by WorldGuard for its operations. It's recommended to use your own executor service if possible for better control. ```java ListeningExecutorService executorService = WorldGuard.getInstance().getExecutorService(); ``` -------------------------------- ### Register and Set Custom Flag Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/quick-reference.md Define a new string flag, register it with the flag registry, and then set its value on a region. ```java StringFlag flag = new StringFlag("my-flag"); wg.getFlagRegistry().register(flag); region.setFlag(flag, "value"); ``` -------------------------------- ### WorldGuard Shutdown Order Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/configuration.md Outlines the correct sequence for shutting down WorldGuard components, including the platform, region container, and WorldGuard itself. ```java // 1. Disable platform wg.getPlatform().unload(); // 2. Unload regions RegionContainer container = wg.getPlatform() .getRegionContainer(); container.unload(); // 3. Disable WorldGuard wg.disable(); ``` -------------------------------- ### Enforce Build Flag Rules Source: https://github.com/enginehub/worldguard/blob/version/7.0.x/_autodocs/api-reference-sessions.md Implement a SessionHandler to check and enforce custom flag rules, such as denying builds in specific regions. This handler ticks every session update. ```java public class FlagEnforcementHandler implements SessionHandler { @Override public void tick(Session session, LocalPlayer player) { RegionContainer container = WorldGuard.getInstance() .getPlatform() .getRegionContainer(); RegionManager manager = container.get(player.getWorld()); if (manager == null) return; BlockVector3 pos = player.getLocation() .toVector().toBlockPoint(); ApplicableRegionSet regions = manager .queryApplicableRegions(pos); // Check custom flag State buildState = regions.queryState( player, Flags.BUILD ); if (buildState == State.DENY) { player.print("Build disabled in this region"); // Could also prevent block placement } } } ```