### Install WorldGuard and WorldEdit Source: https://context7.com/enginehub/worldguarddocs/llms.txt Place the JAR files for WorldGuard and WorldEdit into your server's plugins folder and start the server. WorldGuard will automatically generate its configuration files. ```bash # 1. Place both JARs in your server's plugins folder # - WorldEdit: https://www.enginehub.org/worldedit # - WorldGuard: https://dev.bukkit.org/bukkit-plugins/worldguard/ # 2. Start the server — WorldGuard generates its config files automatically: # plugins/WorldGuard/config.yml (global settings) # plugins/WorldGuard/worlds//config.yml (per-world overrides) # plugins/WorldGuard/worlds//blacklist.txt ``` -------------------------------- ### Install Dependencies and Build Docs Source: https://github.com/enginehub/worldguarddocs/blob/master/README.md Installs project dependencies using pip and provides instructions to auto-rebuild documentation. ```bash pip install -r requirements.txt # Now you can run ./dev.py to auto-rebuild the docs into build/dirhtml, and browse it at the printed address. ``` -------------------------------- ### Example: Whitelist Workbenches Source: https://github.com/enginehub/worldguarddocs/blob/master/source/config.md This example demonstrates how to use the `interaction-whitelist` to disable protection on workbenches, allowing players to interact with them freely. ```yaml interaction-whitelist: [workbench] ``` -------------------------------- ### Example YAML Region File Structure Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/storage.md This is an example of how region data is structured in the YAML file. Player names can be used instead of UUIDs with the -n flag in commands. ```yaml regions: test: min: {x: 1730.0, y: 0.0, z: -169.0} max: {x: 1742.0, y: 255.0, z: -158.0} members: players: [bobby] unique-ids: [0ea8eca3-dbf6-47cc-9d1a-c64551ca975c] flags: {use: allow, greeting: Welcome!, pvp: allow, pvp-group: MEMBERS} owners: groups: [admins] type: cuboid priority: 4 __global__: members: {} flags: {} owners: {} type: global priority: 0 ``` -------------------------------- ### Example: Get Region by ID with Null Check Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/managers.md Demonstrates how to safely retrieve a region by its ID, including a check for a null RegionManager. Handles cases where region support might be unavailable. ```java RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager regions = container.get(world); if (regions != null) { return regions.getRegion("spawn"); } else { // The world has no region support or region data failed to load } ``` -------------------------------- ### Show WorldGuard Version Source: https://github.com/enginehub/worldguarddocs/blob/master/source/commands.md Displays the currently installed version of WorldGuard. ```default /wg version ``` -------------------------------- ### Example: Limited Flag Permissions Source: https://github.com/enginehub/worldguarddocs/blob/master/source/permissions.md Example permissions allowing players to change flags only on regions they own, and only for 'use' and 'chest-access' flags. ```default worldguard.region.flag.regions.own.* worldguard.region.flag.flags.use.* worldguard.region.flag.flags.chest-access.* ``` -------------------------------- ### Domain Management (Members and Owners) Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md Examples of how to add players and groups to a region's members and owners using DefaultDomain. ```APIDOC ## Domain Management ### Description Manages players and groups associated with a region's members and owners using `DefaultDomain`. ### Method Signature ```java DefaultDomain members = region.getMembers(); members.addPlayer(UUID.fromString("0ea8eca3-dbf6-47cc-9d1a-c64551ca975c")); members.addGroup("admins"); ``` ### Notes - It is recommended to use player UUIDs instead of names due to potential name changes. - Methods using player names are deprecated. ``` -------------------------------- ### Example Blacklist File Configuration Source: https://github.com/enginehub/worldguarddocs/blob/master/source/blacklist.md This INI-style configuration demonstrates how to define blacklist rules for various items and blocks, specifying actions to take and groups to ignore. ```ini # Deny lava buckets [lava_bucket] ignore-groups=admins,mods on-use=deny,tell message=Sorry, you can't use lava buckets! # Deny some ore [gold_ore,iron_ore] ignore-groups=admins on-break=deny,tell,notify # No TNT! [tnt] ignore-groups=admins on-place=deny,notify,kick ``` -------------------------------- ### Create a Protected Spawn Region Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/quick-start.md This example demonstrates creating a 'spawn' region and assigning the 'builders' permission group as members, allowing them to build within spawn. ```default /rg define spawn ``` ```default /rg addmember spawn g:builders ``` -------------------------------- ### Region Priority and Parent Management Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md Examples of how to set the priority of a region and manage its parent region. ```APIDOC ## Region Priority and Parent Management ### Description Demonstrates how to set a region's priority and assign or remove a parent region. ### Code Examples #### Setting Priority ```java region.setPriority(100); ``` #### Setting Parent ```java // No parent mall.setParent(null); // Set parent plot.setParent(mall); ``` ### Notes Attempting to create a circular inheritance will result in an exception. ``` -------------------------------- ### Matching Multiple Items/Blocks Source: https://github.com/enginehub/worldguarddocs/blob/master/source/blacklist.md This example shows how to specify multiple items or blocks within a single blacklist entry by separating them with commas. ```default [oak_wood,brick,glass] ``` -------------------------------- ### Player Region Association Example Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/flag-calculation.md Demonstrates how a player's association is determined when they are part of multiple regions with different ownership. ```java List regions = Arrays.asList(spawnRegion, buildersClub); builderPlayer.getAssociation(regions) == Association.OWNER; ``` -------------------------------- ### Configure Block Place Restrictions Source: https://context7.com/enginehub/worldguarddocs/llms.txt Define rules for placing specific blocks. This example denies placing TNT and notifies admins, while another example blocks obsidian placement except for specific groups. ```properties [tnt] ignore-groups=admins on-place=deny,notify,kick ``` ```properties [obsidian] ignore-groups=admins,obsidian on-place=deny,tell on-break=deny,tell ``` -------------------------------- ### Create an Arena with PvP and Passthrough Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/quick-start.md This example creates an 'arena' region where PvP is allowed. The 'passthrough' flag is set to 'allow' so that build checks are ignored, permitting builders to modify the area while PvP is active. ```default /rg define arena ``` ```default /rg flag arena pvp allow ``` ```default /rg flag arena passthrough allow ``` -------------------------------- ### Create an Overlapping Mining Zone Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/quick-start.md This example shows how to create a 'mine' region that allows building for all players, overriding other regions like 'spawn' by setting the 'build' flag to 'allow'. ```default /rg define mine ``` ```default /rg flag mine build allow ``` -------------------------------- ### Configure Block Placement Notifications Source: https://context7.com/enginehub/worldguarddocs/llms.txt Set up notifications for placing specific blocks without denying the action. This example notifies when an enchantment table is placed. ```properties [enchantment_table] on-place=notify comment=Player placed an enchantment table ``` -------------------------------- ### WorldGuard Command: Hospital Healing Setup Source: https://context7.com/enginehub/worldguarddocs/llms.txt Set up a hospital region that automatically heals players over time. Configure the healing delay, amount per tick, and maximum health. ```text # ── Hospital: heal 1 heart/sec up to 10 HP ─────────────────────────────────── /rg define hospital /rg flag hospital heal-delay 1 /rg flag hospital heal-amount 2 /rg flag hospital heal-max-health 10 ``` -------------------------------- ### Flag Management Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md How to get and set region flags using the Flags utility class. ```APIDOC ## Flag Management ### Description Provides methods for retrieving and setting region flags. ### Getting Flags #### Method Signature ```java // Example: Get build flag boolean canBuild = region.getFlag(Flags.BUILD); // Example: Get greeting message String message = region.getFlag(Flags.GREET_MESSAGE); ``` ### Setting Flags #### Method Signature ```java // Example: Set greeting message region.setFlag(Flags.GREET_MESSAGE, "Hi there!"); // Example: Remove greeting message region.setFlag(Flags.GREET_MESSAGE, null); ``` ### Region Group Flags #### Method Signature ```java // Get the region group flag for PVP RegionGroupFlag flag = Flags.PVP.getRegionGroupFlag(); // Example: Set the region group for the 'use' flag to MEMBERS region.setFlag(Flags.USE.getRegionGroupFlag(), RegionGroup.MEMBERS); ``` ### Parameters - `flag` (Flag): The flag to get or set (e.g., `Flags.BUILD`, `Flags.GREET_MESSAGE`). - `value` (?): The value to set for the flag. Must be of the type the flag allows. Use `null` to remove the flag. ``` -------------------------------- ### WorldGuard Command: Public Arena Setup Source: https://context7.com/enginehub/worldguarddocs/llms.txt Configure a public arena where PvP is allowed but block breaking is denied. The 'passthrough allow' flag ensures other flags are applied without blocking movement. ```text # ── Public arena: PvP allowed, blocks cannot be broken by anyone ───────────── /rg define arena /rg flag arena pvp allow /rg flag arena passthrough allow # don't protect area — just apply flags ``` -------------------------------- ### Create and Flag Global Region Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/global-region.md Setting a flag on the global region automatically creates it. This example denies PvP for the entire world. ```default /rg flag __global__ pvp deny ``` -------------------------------- ### Test Build Flag for Player Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/flag-calculation.md Use `testState` to check if a player is allowed to perform an action governed by a `StateFlag`. This example cancels the event if the player does not have build permissions. ```java LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); if (!set.testState(localPlayer, Flags.BUILD)) { event.setCancelled(true); } ``` -------------------------------- ### Region Priority and Inheritance Setup Source: https://context7.com/enginehub/worldguarddocs/llms.txt Configure region priority and inheritance to manage overlapping regions. Higher priority values override lower ones. Inheritance allows flags to be applied hierarchically from parent to child regions. ```bash /rg define spawn /rg define vip /rg setpriority vip 10 ``` ```bash /rg define shop_template -g /rg setparent shop_template mall /rg setparent shop1 shop_template /rg setparent shop2 shop_template /rg flag mall use deny /rg flag shop_template use allow ``` ```bash /rg flag __global__ passthrough deny /rg flag __global__ use allow /rg info __global__ ``` -------------------------------- ### Define Mall Region Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/common-scenarios.md Use this command to define the main outer region for your mall setup. ```default /rg define mall ``` -------------------------------- ### Accessing WorldGuard and Wrapping Bukkit Objects Source: https://context7.com/enginehub/worldguarddocs/llms.txt Get the main WorldGuard instance and convert Bukkit objects to WorldGuard/WorldEdit types. Handle soft dependencies safely. ```java import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldedit.bukkit.BukkitAdapter; // Get the main WorldGuard instance WorldGuard wg = WorldGuard.getInstance(); // Convert Bukkit Player → WorldGuard LocalPlayer LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); // Convert Bukkit Location / World → WorldEdit types com.sk89q.worldedit.util.Location weLoc = BukkitAdapter.adapt(player.getLocation()); com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(player.getWorld()); // Handle soft dependency safely public void onEnable() { try { boolean result = WorldGuard.getInstance().getPlatform() != null; } catch (NoClassDefFoundError e) { getLogger().warning("WorldGuard not found — disabling WG features"); } } ``` -------------------------------- ### Accessing WorldGuard and Wrapping Bukkit Objects Source: https://context7.com/enginehub/worldguarddocs/llms.txt This section shows how to get the main WorldGuard instance and convert Bukkit objects (Player, Location, World) into WorldGuard-compatible types. It also includes a safe way to handle the WorldGuard soft dependency. ```APIDOC ## Accessing WorldGuard and Wrapping Bukkit Objects ### Description Get the main WorldGuard instance and convert Bukkit objects (Player, Location, World) into WorldGuard-compatible types. Includes safe handling for WorldGuard's soft dependency. ### Code Examples ```java import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldedit.bukkit.BukkitAdapter; // Get the main WorldGuard instance WorldGuard wg = WorldGuard.getInstance(); // Convert Bukkit Player → WorldGuard LocalPlayer LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); // Convert Bukkit Location / World → WorldEdit types com.sk89q.worldedit.util.Location weLoc = BukkitAdapter.adapt(player.getLocation()); com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(player.getWorld()); // Handle soft dependency safely public void onEnable() { try { boolean result = WorldGuard.getInstance().getPlatform() != null; } catch (NoClassDefFoundError e) { getLogger().warning("WorldGuard not found — disabling WG features"); } } ``` ``` -------------------------------- ### Grant Info Permission for Own Regions Source: https://github.com/enginehub/worldguarddocs/blob/master/source/permissions.md Example of granting permission to look up information on only regions that a player owns. ```plaintext worldguard.region.info.own.* ``` -------------------------------- ### Get Greeting Message Flag Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md Retrieve the `GREET_MESSAGE` flag from a region. If the flag is not set, `null` is returned. ```java String message = region.getFlag(Flags.GREET_MESSAGE); player.sendMessage(message); ``` -------------------------------- ### RegionContainer and RegionManager Source: https://context7.com/enginehub/worldguarddocs/llms.txt Learn how to access and manipulate region data. This includes getting the region container, retrieving region managers for specific worlds, looking up regions by ID, enumerating all regions, and creating, adding, removing, saving, and loading regions. ```APIDOC ## RegionContainer and RegionManager ### Description Access and manipulate region data programmatically. This covers obtaining the region container, getting world-specific region managers, querying regions, and performing CRUD operations on regions. ### Code Examples ```java import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldedit.math.BlockVector3; RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); // Get the manager for a specific world (may be null if region support is off) RegionManager regions = container.get(BukkitAdapter.adapt(world)); if (regions == null) return; // region data unavailable // Look up a region by ID ProtectedRegion spawn = regions.getRegion("spawn"); // Enumerate all regions for (Map.Entry entry : regions.getRegions().entrySet()) { String id = entry.getKey(); ProtectedRegion region = entry.getValue(); } // Create and register a new cuboid region BlockVector3 min = BlockVector3.at(-10, 64, -10); BlockVector3 max = BlockVector3.at(10, 80, 10); ProtectedCuboidRegion newRegion = new ProtectedCuboidRegion("arena", min, max); newRegion.setPriority(5); regions.addRegion(newRegion); // auto-saved after a short delay // Remove a region (UNSET_PARENT_IN_CHILDREN or REMOVE_CHILDREN) regions.removeRegion("arena", RemovalStrategy.UNSET_PARENT_IN_CHILDREN); // Force-save / force-reload (blocks until done) regions.save(); regions.load(); ``` ``` -------------------------------- ### Get All Greeting Message Flag Values Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/flag-calculation.md Use `queryAllValues` to retrieve all set values for a specific flag from a player's context. Flags are accessed via the `Flags` class. ```java LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); Collection greetings = set.queryAllValues(localPlayer, Flags.GREET_MESSAGE); ``` -------------------------------- ### Event Handling with RegionAssociable Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/flag-calculation.md An example of how to use a created `RegionAssociable` within an event handler to check region states and potentially cancel the event. ```java @EventHandler public void onPlayerBucketFill(PlayerBucketFillEvent event) { Player player = event.getPlayer(); RegionAssociable associable = createRegionAssociable(player); if (!set.testState(associable, /* flags here */)) { event.setCancelled(true); } } ``` -------------------------------- ### Kick Players Using TNT Source: https://github.com/enginehub/worldguarddocs/blob/master/source/blacklist.md Deny the placement of TNT and notify administrators, then kick the player. This example also demonstrates ignoring specific permission groups. ```ini [tnt] ignore-groups=admins on-place=deny,notify,kick ``` -------------------------------- ### Allow Reading Lectern Books Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/common-scenarios.md Ensure WorldGuard version 7.0.1+ is installed. Set the 'use' flag to 'allow' to permit players to read lectern books without being able to take them. ```default /rg flag use allow ``` -------------------------------- ### Get Region Count Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/managers.md Get the total number of regions managed by the RegionManager. ```APIDOC ## Get Region Count ### Description Returns the total number of regions. ### Method ```java regions.size() ``` ### Response #### Success Response - **int** - The number of regions. ``` -------------------------------- ### Convenience Shortcut for Build Flag Query Source: https://context7.com/enginehub/worldguarddocs/llms.txt Use the testBuild convenience method as a shortcut for testing the BUILD flag state at a location for a player. ```java query.testBuild(loc, localPlayer); // equivalent to testState(..., Flags.BUILD) ``` -------------------------------- ### Defining Events and Actions for an Item Source: https://github.com/enginehub/worldguarddocs/blob/master/source/blacklist.md This configuration snippet illustrates how to define specific events (like 'on-place' and 'on-drop') for an item and assign multiple actions to each event. ```default [enchantment_table] on-place=deny,tell on-drop=notify ``` -------------------------------- ### Get All Regions Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/managers.md Obtain an immutable map of all regions managed by the RegionManager. ```APIDOC ## Get All Regions ### Description Returns an immutable map containing all regions. ### Method ```java regions.getRegions() ``` ### Response #### Success Response - **Map** - An immutable map where keys are region IDs and values are `ProtectedRegion` objects. ``` -------------------------------- ### Configure Host Keys in WorldGuard Source: https://github.com/enginehub/worldguarddocs/blob/master/source/host-keys.md Set up host keys by mapping player usernames to their expected connection addresses in the WorldGuard configuration file. This ensures players connect from specific, pre-approved domains. ```yaml host-keys: your_username: bagels.play.example.com moderator1_name: manoverboard.play.example.com ``` -------------------------------- ### Get Region by ID Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/managers.md Retrieve a specific protected region by its unique identifier. ```APIDOC ## Get Region by ID ### Description Retrieves a specific `ProtectedRegion` by its ID. ### Method ```java regions.getRegion(String) ``` ### Parameters #### Path Parameters - **id** (String) - Required - The unique identifier of the region. ### Response #### Success Response - **ProtectedRegion** - The `ProtectedRegion` object if found, otherwise null. ``` -------------------------------- ### Get Polygon Vertices Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md If a region is a `ProtectedPolygonalRegion`, you can retrieve its defining points using `getPoints()`. ```java if (region instanceof ProtectedPolygonalRegion) { ProtectedPolygonalRegion polygon = (ProtectedPolygonalRegion) region; List points = polygon.getPoints(); } ``` -------------------------------- ### Get RegionContainer Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/managers.md Access the main region container object. This is the entry point for all region-related operations. ```java RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); ``` -------------------------------- ### Define and Manage Regions with WorldGuard Source: https://context7.com/enginehub/worldguarddocs/llms.txt Use WorldEdit selections to define regions, then use `/rg` commands to add members, set flags, and manage region properties. Use `/rg info` and `/rg flags` to inspect regions. ```text # 1. Select the area with WorldEdit (use wooden axe or //pos1 / //pos2) # Left-click a corner → right-click the opposite corner # 2. Define the region /rg define spawn # 3. Add members (players who can build) and owners /rg addmember spawn wizjany sk89q g:builders /rg addowner spawn sk89q # 4. Set flags on the region /rg flag spawn pvp deny /rg flag spawn greeting Welcome to Spawn! /rg flag spawn farewell Goodbye! # 5. Inspect the region /rg info spawn /rg flags spawn # interactive in-game flag browser # 6. Remove a member or the whole region /rg removemember spawn g:builders /rg remove spawn ``` -------------------------------- ### Get Region Information Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/quick-start.md Display detailed information about a specific region, including its members, owners, flags, and boundaries. ```default /rg info town ``` -------------------------------- ### WorldGuard Troubleshooting Commands Source: https://context7.com/enginehub/worldguarddocs/llms.txt Commands for generating server reports, profiling performance, and debugging issues by simulating game events. ```text # ── Troubleshooting ─────────────────────────────────────────────────────────── /wg report [-p] # generate server report (or post to pastebin) /wg profile [-p] [-i 20] [-t *] [5] # CPU profile for 5 minutes /wg stopprofile ``` ```text # Simulate events to identify which plugin is blocking an action: /wg debug testbreak [-t] [-s] # simulate block break /wg debug testplace [-t] [-s] # simulate block place /wg debug testinteract [-t] [-s] # simulate right-click /wg debug testdamage [-t] [-s] # simulate PvP damage ``` ```text # Example: find out why PvP is blocked /wg debug testdamage -t other_player_name ``` -------------------------------- ### Get Regions Overlapping a ProtectedRegion Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/spatial-queries.md Find regions that overlap with a given ProtectedRegion. A dummy ID is required for the ProtectedRegion when using this method. ```java BlockVector3 min = BlockVector3.at(0, 0, 0); BlockVector3 max = BlockVector3.at(10, 10, 10); ProtectedRegion test = new ProtectedCuboidRegion("dummy", min, max); ApplicableRegionSet set = regions.getApplicableRegions(test); ``` -------------------------------- ### Querying Build Protection Source: https://context7.com/enginehub/worldguarddocs/llms.txt Demonstrates the standard pattern for checking if a player is permitted to build at a specific location. ```APIDOC ## Developer API: Querying Build Protection Canonical pattern for checking whether a player can build at a location. ```java @EventHandler public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); // Check if the player has the bypass permission first com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(player.getWorld()); boolean hasBypass = WorldGuard.getInstance().getPlatform() .getSessionManager().hasBypass(localPlayer, weWorld); if (hasBypass) return; // Now query the BUILD flag at the placed block's location RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionQuery query = container.createQuery(); com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(event.getBlock().getLocation()); if (!query.testState(loc, localPlayer, Flags.BUILD)) { event.setCancelled(true); player.sendMessage("§cYou don't have permission to build here."); } } ``` ``` -------------------------------- ### Query Build Permission with Cache Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protection-query.md Queries if a player can build at a specific location using the region query cache. Requires wrapping the player and creating a RegionQuery object. ```java LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); Location loc = new Location(world, 10, 64, 100); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionQuery query = container.createQuery(); if (!query.testState(loc, localPlayer, Flags.BUILD)) { // Can't build } ``` -------------------------------- ### Get a Specific Region by ID Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/managers.md Retrieve a ProtectedRegion object using its unique identifier. This is useful for accessing or modifying existing regions. ```java ProtectedRegion region = regions.getRegion("spawn"); ``` -------------------------------- ### Allow Teleport to Specific Region Source: https://github.com/enginehub/worldguarddocs/blob/master/source/permissions.md Example of allowing every player to use `/rg teleport` to a specific region named 'city'. ```plaintext worldguard.region.teleport.city.* ``` -------------------------------- ### Set Region Flags Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/quick-start.md Apply or modify flags for a region to control specific game mechanics. For example, deny PvP within a region. ```default /rg flag town pvp deny ``` -------------------------------- ### Set USE Flag and Region Group Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md Demonstrates setting the `USE` flag to `ALLOW` and its associated region group flag to `MEMBERS`. ```java region.setFlag(Flags.USE, StateFlag.State.ALLOW); region.setFlag(Flags.USE.getRegionGroupFlag(), RegionGroup.MEMBERS); ``` -------------------------------- ### WorldGuard Command: Plot Mall with Template Inheritance Source: https://context7.com/enginehub/worldguarddocs/llms.txt Create a plot mall where individual shops inherit flags from a template and the mall itself has different restrictions. Use 'setparent' for inheritance and 'setpriority' to manage overlapping regions. ```text # ── Plot mall setup with template inheritance ───────────────────────────────── /rg define mall /rg define shop_template -g # non-physical template /rg setpriority mall -1 # or use parent hierarchy /rg define shop1 && /rg define shop2 /rg setparent shop_template mall /rg setparent shop1 shop_template /rg setparent shop2 shop_template /rg flag mall use deny # no lever/door use in public mall area /rg flag shop_template use allow # but allowed inside individual shops ``` -------------------------------- ### Get Applicable Regions at a Point using RegionManager Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/spatial-queries.md Perform a point location query using a RegionManager. Convert a Location to a BlockVector3 point before querying. ```java BlockVector3 position = BlockVector3.at(20, 10, 4); ApplicableRegionSet set = regions.getApplicableRegions(position); ``` ```java Location loc = new com.sk89q.worldedit.util.Location(world, 10, 64, 100); // can also be adapted from Bukkit, as mentioned above RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager regions = container.get(world); // Check to make sure that "regions" is not null ApplicableRegionSet set = regions.getApplicableRegions(loc.toVector().toBlockPoint()); ``` -------------------------------- ### WorldGuard Command: Deny Build Outside Regions Source: https://context7.com/enginehub/worldguarddocs/llms.txt Use the '__global__' region to apply flags to the entire world. Deny building outside of defined regions by setting 'passthrough' to 'deny'. ```text # ── Protect the entire wilderness (no-build outside defined regions) ────────── /rg flag __global__ passthrough deny ``` -------------------------------- ### Define and Set Priority for a 'pub' Region Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/priorities.md Create a new region and set its priority to ensure its specific build permissions override those of an existing region, like 'spawn'. This is useful for creating special areas with unique access rules. ```default /rg define pub ``` ```default /rg setpriority pub 10 ``` -------------------------------- ### Get RegionManager for a World Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/managers.md Retrieve the RegionManager for a specific world from the RegionContainer. The returned value may be null if region support is disabled or data failed to load. ```java RegionManager regions = container.get(world); ``` -------------------------------- ### Configure Blacklist Options Source: https://github.com/enginehub/worldguarddocs/blob/master/source/blacklist.md Use options like 'message' to customize user feedback for denied actions. This configuration applies to specific items or regions. ```default [enchantment_table] on-place=deny,tell message=Sorry, you can\'t use enchantment tables! ``` -------------------------------- ### Configure Multiple Block Placement Denials Source: https://context7.com/enginehub/worldguarddocs/llms.txt Block the placement of multiple specified items simultaneously using a comma-separated list in the configuration. ```properties [oak_wood,brick,glass] on-place=deny,tell ``` -------------------------------- ### WorldGuard Selector Syntax Source: https://context7.com/enginehub/worldguarddocs/llms.txt Syntax for targeting players with commands using selectors like '*', '#', '#near', and '@'. ```text # Selector syntax for player-targeting commands: # * match all players # # all players on a world # #near nearby players # @ exact name match ``` -------------------------------- ### Blacklist Configuration Source: https://context7.com/enginehub/worldguarddocs/llms.txt Configure item restrictions in 'worlds//blacklist.txt'. Specify which groups are ignored and the action to take (e.g., 'deny') with a custom message. ```ini # worlds/world/blacklist.txt # Deny lava buckets for all non-admin/mod players [lava_bucket] ignore-groups=admins,mods on-use=deny,tell message=Sorry, you can't use lava buckets! ``` -------------------------------- ### Wrap Bukkit Player to LocalPlayer Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/native-objects.md Use `wrapPlayer(Player)` from `WorldGuardPlugin` to convert a Bukkit `Player` object to WorldGuard's internal `LocalPlayer` for legacy and cross-platform compatibility. ```java WorldGuardPlugin.inst().wrapPlayer(player); ``` -------------------------------- ### Block Commands with Flag Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/flags.md The `blocked-cmds` flag allows you to specify a comma-separated list of commands that players will be unable to use within a region. This example blocks the /tp and /teleport commands. ```default /rg flag spawn blocked-cmds /tp,/teleport ``` -------------------------------- ### WorldGuard Global Configuration Source: https://context7.com/enginehub/worldguarddocs/llms.txt Configure global settings for WorldGuard in `plugins/WorldGuard/config.yml`. Per-world overrides can be placed in `plugins/WorldGuard/worlds//config.yml`. ```yaml # plugins/WorldGuard/config.yml (global) op-permissions: true use-player-move-event: true # required for greeting/farewell/healing flags mobs: block-creeper-explosions: true block-creeper-block-damage: true block-wither-explosions: true disable-enderman-griefing: true block-zombie-door-destruction: true block-creature-spawn: [PHANTOM, ENDER_DRAGON] player-damage: disable-fall-damage: false disable-lava-damage: false fire: disable-lava-fire-spread: true disable-all-fire-spread: false gameplay: block-potions: [night_vision, speed] physics: disable-water-damage-blocks: [redstone_wire, redstone_torch] dynamics: disable-leaf-decay: false disable-ice-melting: false regions: max-claim-volume: 30000 max-region-count-per-player: default: 7 builders: 20 moderators: 40 # plugins/WorldGuard/worlds/world_nether/config.yml (per-world override) mobs: block-creeper-block-damage: false # allow creeper block damage in the nether ``` -------------------------------- ### Get Region Information Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/commands.md Displays information about a specified region or the current region if none is specified. The -s flag selects the region, and -u shows UUIDs instead of player names. ```text /rg info [-u] [-s] [-w ] [] ``` ```text /rg i (...) ``` ```text /rg info __global__ ``` -------------------------------- ### Get Applicable Regions at a Point using Query Cache Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/spatial-queries.md Use the query cache for fast, repeated point location lookups. Obtain a RegionQuery from a RegionContainer and call getApplicableRegions with a Location. ```java RegionQuery query = container.createQuery(); ApplicableRegionSet set = query.getApplicableRegions(loc); ``` ```java Location loc = new com.sk89q.worldedit.util.Location(world, 10, 64, 100); // can also be adapted from Bukkit, as mentioned above RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionQuery query = container.createQuery(); ApplicableRegionSet set = query.getApplicableRegions(loc); ``` -------------------------------- ### Configure Maven pom.xml for WorldGuard Dependency Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/dependency.md Add WorldGuard's Maven repository and dependency to your pom.xml. Ensure the scope is set to 'provided' as WorldGuard is expected to be present at runtime. ```xml sk89q-repo https://maven.enginehub.org/repo/ com.sk89q.worldguard worldguard-bukkit VERSION provided ``` -------------------------------- ### List All Regions Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/quick-start.md View a list of all regions currently defined on the server. ```default /rg list ``` -------------------------------- ### WorldGuard Region Commands Reference Source: https://context7.com/enginehub/worldguarddocs/llms.txt Reference for WorldGuard commands related to region creation, modification, membership management, and flag manipulation. Use `-g` for groups and `-e` to set flags to an empty string. ```text # ── Create / Modify ────────────────────────────────────────────────────────── /rg define [-w ] [-g] [owner1 ...] # create region from WE selection /rg redefine [-w ] # resize to current WE selection /rg remove [-w ] [-f|-u] # delete region (-f removes children, -u unparents) /rg claim # self-serve player claim # ── Membership ─────────────────────────────────────────────────────────────── /rg addmember [-w lobby] spawn g:builder sk89q # add members (use g: for groups) /rg addowner [-w lobby] spawn g:admins eduardo /rg removemember [-w lobby] [-a] spawn sk89q # -a removes ALL members /rg removeowner [-w lobby] [-a] spawn sk89q # ── Flags ──────────────────────────────────────────────────────────────────── /rg flag [-g ] [-e] [value] # set flag; omit value to unset /rg flag mall pvp -g nonmembers deny # apply flag only to non-members /rg flag mall greeting -e # set flag to empty string /rg flags # browse all flags interactively ``` -------------------------------- ### Set Region Flags Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/flags.md Use the /region flag command to set various flags on a specified region. Examples include setting PvP to deny, a custom greeting, and healing amounts. ```default /region flag spawn pvp deny /region flag spawn greeting Welcome to spawn! /rg flag hospital heal-amount 2 /rg flag hospital heal-delay 1 ``` -------------------------------- ### Get Single Greeting Message Flag Value Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/flag-calculation.md Use `queryValue` to retrieve a single value for a flag, which may be the first found or a 'best' value for `StateFlags`. Returns `null` if the flag is not set. ```java LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); String greeting = set.queryValue(localPlayer, Flags.GREET_MESSAGE); ``` -------------------------------- ### Use String Formatting in Flags Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/flags.md Utilize string formatting options within flags like 'greeting-title' to create dynamic and colorful messages. Supports color codes and placeholders. ```default /rg flag spawn greeting-title `bWelcome to spawn!\n`YEnjoy your stay in `g`n%world%`x, `C%name%`Y! ``` -------------------------------- ### WorldGuard Command: Allow Global Use of Doors/Levers Source: https://context7.com/enginehub/worldguarddocs/llms.txt Enable the use of doors, levers, and other interactable blocks globally across all regions by setting the 'use' flag to 'allow' for the '__global__' region. ```text # ── Allow doors/levers globally ────────────────────────────────────────────── /rg flag __global__ use allow ``` -------------------------------- ### Set Build Permission Deny Message Source: https://github.com/enginehub/worldguarddocs/blob/master/source/config.md Customize the message displayed to players when they are denied permission to build. If not set, a default message will be used. ```yaml deny-message: "&eSorry, but you are not permitted to do that here." ``` -------------------------------- ### RegionContainer and RegionManager Operations Source: https://context7.com/enginehub/worldguarddocs/llms.txt Access and manipulate region data programmatically. Get the manager for a specific world, look up regions by ID, enumerate all regions, create, register, and remove regions. Force-save or reload region data. ```java import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldedit.math.BlockVector3; RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); // Get the manager for a specific world (may be null if region support is off) RegionManager regions = container.get(BukkitAdapter.adapt(world)); if (regions == null) return; // region data unavailable // Look up a region by ID ProtectedRegion spawn = regions.getRegion("spawn"); // Enumerate all regions for (Map.Entry entry : regions.getRegions().entrySet()) { String id = entry.getKey(); ProtectedRegion region = entry.getValue(); } // Create and register a new cuboid region BlockVector3 min = BlockVector3.at(-10, 64, -10); BlockVector3 max = BlockVector3.at(10, 80, 10); ProtectedCuboidRegion newRegion = new ProtectedCuboidRegion("arena", min, max); newRegion.setPriority(5); regions.addRegion(newRegion); // auto-saved after a short delay // Remove a region (UNSET_PARENT_IN_CHILDREN or REMOVE_CHILDREN) regions.removeRegion("arena", RemovalStrategy.UNSET_PARENT_IN_CHILDREN); // Force-save / force-reload (blocks until done) regions.save(); regions.load(); ``` -------------------------------- ### Set Greeting Message Flag Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md Set the `GREET_MESSAGE` flag for a region. The value must be a String. ```java region.setFlag(Flags.GREET_MESSAGE, "Hi there!"); ``` -------------------------------- ### Override Creeper Block Damage in Nether World Source: https://github.com/enginehub/worldguarddocs/blob/master/source/config.md To disable creeper block damage in a specific world, copy the relevant configuration section to that world's `config.yml`. This example shows how to set `block-creeper-block-damage` to false for the nether world. ```default mobs: block-creeper-explosions: false block-creeper-block-damage: true block-wither-explosions: false ``` ```default mobs: block-creeper-block-damage: false ``` -------------------------------- ### Region Management Commands Source: https://context7.com/enginehub/worldguarddocs/llms.txt Commands for managing region priority, parent-child relationships, and saving/loading configurations. Use 'setpriority' to resolve overlapping regions and 'setparent' to establish inheritance. ```bash /rg setpriority spawn 10 /rg setparent plot1 mall /rg setparent plot1 ``` ```bash /rg info [-w ] [id] /rg list [-p ] [-i ] [page] /rg select /rg teleport [-s] ``` ```bash /rg save [-w ] /rg load [-w ] /rg migratedb yaml mysql /rg migrateuuid /rg migrateheights ``` -------------------------------- ### Allow Usage of Doors, Levers, etc. Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/common-scenarios.md Use the 'use' flag to allow players to interact with doors, levers, buttons, and pressure plates. Apply to a specific region or the global region for server-wide effect. ```default /rg flag REGION_NAME use allow ``` ```default /rg flag __global__ use allow ``` -------------------------------- ### Allow Portal Placement Anywhere Source: https://github.com/enginehub/worldguarddocs/blob/master/source/config.md Enable the placement of portal blocks in invalid locations. Use with caution as this can lead to unintended game mechanics. ```yaml physics: allow-portal-anywhere: TRUE ``` -------------------------------- ### WorldGuard Emergency Commands Source: https://context7.com/enginehub/worldguarddocs/llms.txt Commands to manage fire spread and server performance. Includes commands to stop fire, allow fire, and halt server processes as a last resort. ```text # ── Emergency Commands ──────────────────────────────────────────────────────── /stopfire [world] # immediately stop all fire spread /allowfire [world] # lift fire spread suspension /stoplag # remove all entities and freeze physics (last resort!) /stoplag -c # disable stoplag mode /stoplag -i # check stoplag status ``` -------------------------------- ### Asynchronous Domain Input Resolution Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md Using DomainInputResolver to asynchronously resolve player names and groups into a DefaultDomain. ```APIDOC ## Asynchronous Domain Input Resolution ### Description Resolves player names and groups into a `DefaultDomain` asynchronously using `DomainInputResolver`. ### Method Signature ```java // Executor service setup (re-used in your plugin) ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); String[] input = new String[] { "sk89q", "g:admins" }; ProfileService profiles = WorldGuard.getInstance().getProfileService(); DomainInputResolver resolver = new DomainInputResolver(profiles, input); resolver.setLocatorPolicy(UserLocatorPolicy.UUID_AND_NAME); ListenableFuture future = executor.submit(resolver); // Add a callback using Guava Futures.addCallback(future, new FutureCallback() { @Override public void onSuccess(DefaultDomain result) { region.getOwners().addAll(result); } @Override public void onFailure(Throwable throwable) { // Handle error } }); ``` ### Parameters - `input` (String[]): An array of player names or group identifiers. - `profiles` (ProfileService): The WorldGuard profile service. - `resolver` (DomainInputResolver): The resolver instance configured with input and policy. - `executor` (ListeningExecutorService): An executor service for asynchronous operations. ### Notes - Inform the user if UUID lookup does not complete instantly. - Requires Google's Guava library for concurrency utilities. ``` -------------------------------- ### Configure Gradle Build Script for WorldGuard Dependency Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/dependency.md Add the sk89q Maven repository and WorldGuard dependency to your Gradle build script. Use 'compileOnly' to indicate that WorldGuard is provided at compile time. ```groovy repositories { mavenCentral() maven { url "https://maven.enginehub.org/repo/" } } dependencies { compileOnly 'com.sk89q.worldguard:worldguard-bukkit:VERSION' } ``` -------------------------------- ### Enable Build Permission Nodes Source: https://github.com/enginehub/worldguarddocs/blob/master/source/build-perms.md Enable the build permission nodes feature in the WorldGuard configuration. This allows for permission-based control over building actions. ```yaml build-permission-nodes: enable: true deny-message: ``` -------------------------------- ### Claim a Region with WorldGuard Source: https://github.com/enginehub/worldguarddocs/blob/master/source/regions/claiming.md Use this command to claim a selected region. The player running the command is automatically added as an owner. Requires the `worldguard.region.claim` permission. ```default /rg claim region_name ``` -------------------------------- ### Wildcard Region Info Permission Source: https://github.com/enginehub/worldguarddocs/blob/master/source/permissions.md Grants the ability to use /rg info and /rg flags for all regions. ```plaintext worldguard.region.info.* ``` -------------------------------- ### Add Members to Region Domain Source: https://github.com/enginehub/worldguarddocs/blob/master/source/developer/regions/protected-region.md Use `DefaultDomain` methods like `addPlayer()` and `addGroup()` to manage members. Player names are discouraged in favor of UUIDs. ```java DefaultDomain members = region.getMembers(); members.addPlayer(UUID.fromString("0ea8eca3-dbf6-47cc-9d1a-c64551ca975c")); members.addGroup("admins"); ``` -------------------------------- ### Enable WorldGuard Debug Listener in Batch File Source: https://github.com/enginehub/worldguarddocs/blob/master/source/advanced/event-logging.md Add the -Dworldguard.debug.listener=true JVM argument to your server's batch file to output internal WorldGuard events to the server log. This helps in understanding which events are triggered and how WorldGuard handles them. ```default @echo off java -Xmx4096M -Xms4096M -Dworldguard.debug.listener=true -jar server.jar nogui pause ``` -------------------------------- ### Creating ProtectedRegion Objects Source: https://context7.com/enginehub/worldguarddocs/llms.txt Create and configure various types of ProtectedRegion objects, including cuboid, polygonal, and global regions. Set priorities, parents, members, owners, and flags. Test point containment and find overlapping regions. ```java import com.sk89q.worldguard.protection.regions.*; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; // Cuboid region BlockVector3 min = BlockVector3.at(-10, 0, -10); BlockVector3 max = BlockVector3.at(10, 100, 10); ProtectedRegion cuboid = new ProtectedCuboidRegion("spawn", min, max); // 2D polygonal region (extruded vertically) List points = new ArrayList<>(); points.add(BlockVector2.at(0, 0)); points.add(BlockVector2.at(50, 0)); points.add(BlockVector2.at(50, 50)); points.add(BlockVector2.at(0, 50)); ProtectedRegion polygon = new ProtectedPolygonalRegion("market", points, 60, 120); // Global (non-physical) region — useful as a template parent ProtectedRegion template = new GlobalProtectedRegion("shop_template"); // Set priority and parent cuboid.setPriority(10); polygon.setParent(cuboid); // throws CircularInheritanceException on cycles // Add members and owners by UUID (preferred) or permission group DefaultDomain members = cuboid.getMembers(); members.addPlayer(UUID.fromString("0ea8eca3-dbf6-47cc-9d1a-c64551ca975c")); members.addGroup("builders"); DefaultDomain owners = cuboid.getOwners(); owners.addGroup("admins"); // Set flags directly on the region object cuboid.setFlag(Flags.PVP, StateFlag.State.DENY); cuboid.setFlag(Flags.GREET_MESSAGE, "Welcome to Spawn!"); cuboid.setFlag(Flags.USE, StateFlag.State.ALLOW); cuboid.setFlag(Flags.USE.getRegionGroupFlag(), RegionGroup.ALL); // Read a flag value String msg = cuboid.getFlag(Flags.GREET_MESSAGE); // null if not set // Test point containment boolean inside = cuboid.contains(BlockVector3.at(5, 70, 5)); // true // Find intersecting regions from a candidate list List overlapping = cuboid.getIntersectingRegions( Arrays.asList(polygon, template)); ``` -------------------------------- ### WorldGuard Command: Deny Entry with Custom Message Source: https://context7.com/enginehub/worldguarddocs/llms.txt Restrict entry to a region for non-members and display a custom message. Use the 'entry' flag to deny access and 'entry-deny-message' to customize the message. ```text # ── Deny entry to non-members with a custom message ────────────────────────── /rg flag vip entry deny /rg flag vip entry-deny-message &cSorry, VIPs only! ```