diff --git a/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java b/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java index c25c9a9..580b242 100644 --- a/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java +++ b/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java @@ -6,6 +6,9 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.logging.Logger; +/** + * The plugin main class + */ @SuppressWarnings("unused") public final class ClearOnWorldGuard extends JavaPlugin { diff --git a/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java b/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java index 6ba3d82..44bb9bd 100644 --- a/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java +++ b/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java @@ -60,31 +60,42 @@ public class WorldGuardListener implements Listener { continue; } - // Get a region manager for the world - RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(world)); - if (regionManager == null) { - ClearOnWorldGuard.logger().log(Level.WARNING, "Unable to get region manager for world: " + - world.getName()); - continue; - } - - Set regions = new HashSet<>(); - List regionNames = worldsSection.getStringList(worldId); - for (String regionName : regionNames) { - // Register the region if it's valid - ProtectedRegion region = regionManager.getRegion(regionName); - if (region == null) { - ClearOnWorldGuard.logger().log(Level.WARNING, "Region name " + regionName + " is invalid"); - } else { - regions.add(region); - } - } - protectedRegions.put(world, regions); + loadRegions(world, worldsSection, worldId); } } + /** + * Loads clear regions for a world + * + * @param world

The world to load regions for

+ * @param worldsSection

The configuration section listing all worlds and regions

+ * @param worldId

The user-specified identifier for the currently processed world

+ */ + private void loadRegions(@NotNull World world, @NotNull ConfigurationSection worldsSection, @NotNull String worldId) { + // Get a region manager for the world + RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(world)); + if (regionManager == null) { + ClearOnWorldGuard.logger().log(Level.WARNING, "Unable to get region manager for world: " + + world.getName()); + return; + } + + Set regions = new HashSet<>(); + List regionNames = worldsSection.getStringList(worldId); + for (String regionName : regionNames) { + // Register the region if it's valid + ProtectedRegion region = regionManager.getRegion(regionName); + if (region == null) { + ClearOnWorldGuard.logger().log(Level.WARNING, "Region name " + regionName + " is invalid"); + } else { + regions.add(region); + } + } + protectedRegions.put(world, regions); + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onMove(PlayerMoveEvent event) { + public void onMove(@NotNull PlayerMoveEvent event) { if (event.getTo() == null || event.getFrom().getWorld() == null) { return; } @@ -109,7 +120,8 @@ public class WorldGuardListener implements Listener { * @param playerRegions

The regions the player is in or will be in

* @return

All clear regions found in playerRegions

*/ - private Set getOccupiedClearRegions(World playerWorld, Set playerRegions) { + private Set getOccupiedClearRegions(@NotNull World playerWorld, + @NotNull Set playerRegions) { Set possibleRegions = protectedRegions.get(playerWorld); Set result = new HashSet<>(); for (ProtectedRegion region : playerRegions) {