Class WorldGuardHook
This hook provides automatic detection and initialization of version-specific WorldGuard API implementations, supporting both WorldGuard 6 and WorldGuard 7 installations. It abstracts away the significant API differences between these versions while providing a unified interface for region operations, PvP queries, and player tracking.
The hook uses lazy initialization to detect the installed WorldGuard version and create the appropriate API wrapper only when first accessed. This approach ensures compatibility with servers that may not have WorldGuard installed while providing full functionality when it is available.
WorldGuard version differences:
- WorldGuard 6: Legacy API with different region management and query systems
- WorldGuard 7: Modern API with improved region handling and new query methods
The hook integrates with the NMS world wrapper system to provide consistent world access patterns across different Minecraft and WorldGuard versions.
Example usage:
// Check if WorldGuard is available
WorldGuardApi api = WorldGuardHook.get();
if (api != null) {
// Perform WorldGuard operations
boolean canPvP = api.canPVP(player, location);
boolean canBuild = api.playerCanBuild(player, location);
Set<Player> playersInRegion = api.getPlayersInRegion(world, regionName);
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable WorldGuardApi
get()
Retrieves the WorldGuard API instance for the installed version.
-
Constructor Details
-
WorldGuardHook
public WorldGuardHook()
-
-
Method Details
-
get
Retrieves the WorldGuard API instance for the installed version.This method performs lazy initialization of the WorldGuard API, detecting the installed version and creating the appropriate implementation on first access. Subsequent calls return the cached instance for optimal performance.
Version detection is performed using the plugin version string, supporting both WorldGuard 6.x and WorldGuard 7.x installations. The method integrates with the NMS world wrapper system to provide consistent world access across different Minecraft versions.
If WorldGuard is not installed, not enabled, or an unsupported version is detected, the method returns
null
to indicate that WorldGuard functionality is not available.- Returns:
- the
WorldGuardApi
instance for the detected version, ornull
if WorldGuard is not available
-