com.sk89q.worldguard.protection.managers.RegionManager Java Examples

The following examples show how to use com.sk89q.worldguard.protection.managers.RegionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 6 votes vote down vote up
private boolean define(Player player, RegionContainer container, String regionId, int radius) {
    Objects.requireNonNull(player, "player");
    Objects.requireNonNull(container, "container");
    Objects.requireNonNull(regionId, "regionId");

    World world = BukkitAdapter.adapt(player.getWorld());
    RegionManager regionManager = container.get(world);
    if (regionManager == null) {
        player.sendMessage(ChatColor.RED + "Sorry, region manager for world " + world.getName() + " is not currently accessible.");
        return false;
    }

    BlockVector3 origin = BukkitAdapter.asBlockVector(player.getLocation());
    this.define(regionManager, this.createCuboid(regionId, origin, radius));
    this.flagGlobal(regionManager, true);
    return true;
}
 
Example #2
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public static void updateRegion(IslandInfo islandInfo) {
    try {
        ProtectedCuboidRegion region = setRegionFlags(islandInfo);
        RegionManager regionManager = getRegionManager(uSkyBlock.getInstance().getWorldManager().getWorld());
        regionManager.removeRegion(islandInfo.getName() + "island");
        regionManager.removeRegion(islandInfo.getLeader() + "island");
        regionManager.addRegion(region);
        String netherName = islandInfo.getName() + "nether";
        region = setRegionFlags(islandInfo, netherName);
        World netherWorld = uSkyBlock.getInstance().getWorldManager().getNetherWorld();
        if (netherWorld != null) {
            regionManager = getRegionManager(netherWorld);
            regionManager.removeRegion(netherName);
            regionManager.addRegion(region);
        }
        islandInfo.setRegionVersion(getVersion());
    } catch (Exception e) {
        LogUtil.log(Level.SEVERE, "ERROR: Failed to update region for " + islandInfo.getName(), e);
    }
}
 
Example #3
Source File: Worldguard.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ProtectedRegion getRegion(final com.sk89q.worldguard.LocalPlayer player, final Location loc) {
    RegionManager manager = this.worldguard.getRegionManager(loc.getWorld());
    if (manager == null) {
        if (this.worldguard.getGlobalStateManager().get(loc.getWorld()).useRegions) {
            System.out.println("Region capability is not enabled for WorldGuard.");
        } else {
            System.out.println("WorldGuard is not enabled for that world.");
        }
        return null;
    }
    final ProtectedRegion global = manager.getRegion("__global__");
    if (global != null && isAllowed(player, global)) {
        return global;
    }
    final ApplicableRegionSet regions = manager.getApplicableRegions(loc);
    for (final ProtectedRegion region : regions) {
        if (isAllowed(player, region)) {
            return region;
        }
    }
    return null;
}
 
Example #4
Source File: WorldGuardHook.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public Collection<? extends Region> getRegionsAt_i(@Nullable final Location l) {
	final ArrayList<Region> r = new ArrayList<>();
	
	if (l == null) // Working around possible cause of issue #280
		return Collections.emptyList();
	if (l.getWorld() == null)
		return Collections.emptyList();
	
	WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
	RegionManager manager = platform.getRegionContainer().get(BukkitAdapter.adapt(l.getWorld()));
	if (manager == null)
		return r;
	ApplicableRegionSet applicable = manager.getApplicableRegions(BukkitAdapter.asBlockVector(l));
	if (applicable == null)
		return r;
	for (ProtectedRegion region : applicable)
		r.add(new WorldGuardRegion(l.getWorld(), region));
	return r;
}
 
Example #5
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public static ProtectedRegion getNetherRegionAt(Location location) {
    if (!Settings.nether_enabled || location == null) {
        return null;
    }
    RegionManager regionManager = getRegionManager(location.getWorld());
    if (regionManager == null) {
        return null;
    }
    Iterable<ProtectedRegion> applicableRegions = regionManager.getApplicableRegions(toVector(location));
    for (ProtectedRegion region : applicableRegions) {
        String id = region.getId().toLowerCase();
        if (!id.equalsIgnoreCase("__global__") && id.endsWith("nether")) {
            return region;
        }
    }
    return null;
}
 
Example #6
Source File: WorldGuard6Hook.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public Collection<? extends Region> getRegionsAt_i(@Nullable final Location l) {
    final ArrayList<Region> r = new ArrayList<>();
    
    if (l == null) // Working around possible cause of issue #280
        return Collections.emptyList();
    if (l.getWorld() == null)
        return Collections.emptyList();
    RegionManager manager = plugin.getRegionManager(l.getWorld());
    if (manager == null)
        return r;
    ApplicableRegionSet applicable = manager.getApplicableRegions(l);
    if (applicable == null)
        return r;
    final Iterator<ProtectedRegion> i = applicable.iterator();
    while (i.hasNext())
        r.add(new WorldGuardRegion(l.getWorld(), i.next()));
    return r;
}
 
Example #7
Source File: NPCRegionCondition.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Boolean execute(String playerID) throws QuestRuntimeException {
    NPC npc = CitizensAPI.getNPCRegistry().getById(ID);
    if (npc == null) {
        throw new QuestRuntimeException("NPC with ID " + ID + " does not exist");
    }
    Entity npcEntity = npc.getEntity();
    if (npcEntity == null) return false;

    Player player = PlayerConverter.getPlayer(playerID);
    WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform();
    RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld()));
    if (manager == null) {
        return false;
    }
    ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()));

    for (ProtectedRegion compare : set) {
        if (compare.equals(region))
            return true;
    }
    return false;
}
 
Example #8
Source File: RegionObjective.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return true if location is inside region
 *
 * @param loc Location to Check
 * @return boolean True if in region
 */
private boolean isInsideRegion(Location loc) {
    if (loc == null || loc.getWorld() == null) {
        return false;
    }

    WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform();
    RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
    if (manager == null) {
        return false;
    }

    ProtectedRegion region = manager.getRegion(name);
    if (region == null) {
        return false;
    }

    return region.contains(BukkitAdapter.asBlockVector(loc));
}
 
Example #9
Source File: RegionCondition.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Boolean execute(String playerID) {
    Player player = PlayerConverter.getPlayer(playerID);
    WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform();
    RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld()));
    if (manager == null) {
        return false;
    }
    ProtectedRegion region = manager.getRegion(name);
    ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ()));
    for (ProtectedRegion compare : set) {
        if (compare.equals(region))
            return true;
    }
    return false;
}
 
Example #10
Source File: FileManager.java    From AreaShop with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Save all worldGuard regions that need saving.
 */
public void saveWorldGuardRegions() {
	for(String world : worldRegionsRequireSaving) {
		World bukkitWorld = Bukkit.getWorld(world);
		if(bukkitWorld != null) {
			RegionManager manager = plugin.getRegionManager(bukkitWorld);
			if(manager != null) {
				try {
					if(plugin.getWorldGuard().getDescription().getVersion().startsWith("5.")) {
						manager.save();
					} else {
						manager.saveChanges();
					}
				} catch(Exception e) {
					AreaShop.warn("WorldGuard regions in world " + world + " could not be saved");
				}
			}
		}
	}
}
 
Example #11
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static Set<ProtectedRegion> getIntersectingRegions(Location islandLocation) {
    log.entering(CN, "getIntersectingRegions", islandLocation);
    RegionManager regionManager = getRegionManager(islandLocation.getWorld());
    ApplicableRegionSet applicableRegions = regionManager.getApplicableRegions(getIslandRegion(islandLocation));
    Set<ProtectedRegion> regions = getRegions(applicableRegions);
    for (Iterator<ProtectedRegion> iterator = regions.iterator(); iterator.hasNext(); ) {
        if (iterator.next() instanceof GlobalProtectedRegion) {
            iterator.remove();
        }
    }
    log.exiting(CN, "getIntersectingRegions");
    return regions;
}
 
Example #12
Source File: Utils.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get all WorldGuard regions intersecting with a WorldEdit selection.
 * @param selection The selection to check
 * @return A list with all the WorldGuard regions intersecting with the selection
 */
public static List<ProtectedRegion> getWorldEditRegionsInSelection(WorldEditSelection selection) {
	// Get all regions inside or intersecting with the WorldEdit selection of the player
	World world = selection.getWorld();
	RegionManager regionManager = AreaShop.getInstance().getRegionManager(world);
	ArrayList<ProtectedRegion> result = new ArrayList<>();
	Location selectionMin = selection.getMinimumLocation();
	Location selectionMax = selection.getMaximumLocation();
	for(ProtectedRegion region : regionManager.getRegions().values()) {
		Vector regionMin = AreaShop.getInstance().getWorldGuardHandler().getMinimumPoint(region);
		Vector regionMax = AreaShop.getInstance().getWorldGuardHandler().getMaximumPoint(region);
		if(
				(      // x part, resolves to true if the selection and region overlap anywhere on the x-axis
						(regionMin.getBlockX() <= selectionMax.getBlockX() && regionMin.getBlockX() >= selectionMin.getBlockX())
								|| (regionMax.getBlockX() <= selectionMax.getBlockX() && regionMax.getBlockX() >= selectionMin.getBlockX())
								|| (selectionMin.getBlockX() >= regionMin.getBlockX() && selectionMin.getBlockX() <= regionMax.getBlockX())
								|| (selectionMax.getBlockX() >= regionMin.getBlockX() && selectionMax.getBlockX() <= regionMax.getBlockX())
				) && ( // Y part, resolves to true if the selection and region overlap anywhere on the y-axis
						(regionMin.getBlockY() <= selectionMax.getBlockY() && regionMin.getBlockY() >= selectionMin.getBlockY())
								|| (regionMax.getBlockY() <= selectionMax.getBlockY() && regionMax.getBlockY() >= selectionMin.getBlockY())
								|| (selectionMin.getBlockY() >= regionMin.getBlockY() && selectionMin.getBlockY() <= regionMax.getBlockY())
								|| (selectionMax.getBlockY() >= regionMin.getBlockY() && selectionMax.getBlockY() <= regionMax.getBlockY())
				) && ( // Z part, resolves to true if the selection and region overlap anywhere on the z-axis
						(regionMin.getBlockZ() <= selectionMax.getBlockZ() && regionMin.getBlockZ() >= selectionMin.getBlockZ())
								|| (regionMax.getBlockZ() <= selectionMax.getBlockZ() && regionMax.getBlockZ() >= selectionMin.getBlockZ())
								|| (selectionMin.getBlockZ() >= regionMin.getBlockZ() && selectionMin.getBlockZ() <= regionMax.getBlockZ())
								|| (selectionMax.getBlockZ() >= regionMin.getBlockZ() && selectionMax.getBlockZ() <= regionMax.getBlockZ())
				)
		) {
			result.add(region);
		}
	}
	return result;
}
 
Example #13
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static ProtectedRegion getIslandRegionAt(Location location) {
    RegionManager regionManager = getRegionManager(location.getWorld());
    if (regionManager == null) {
        return null;
    }
    Iterable<ProtectedRegion> applicableRegions = regionManager.getApplicableRegions(toVector(location));
    for (ProtectedRegion region : applicableRegions) {
        String id = region.getId().toLowerCase();
        if (!id.equalsIgnoreCase("__global__") && (id.endsWith("island") || id.endsWith("nether"))) {
            return region;
        }
    }
    return null;
}
 
Example #14
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static String getIslandNameAt(Location location) {
    RegionManager regionManager = getRegionManager(location.getWorld());
    Iterable<ProtectedRegion> applicableRegions = regionManager.getApplicableRegions(toVector(location));
    for (ProtectedRegion region : applicableRegions) {
        String id = region.getId().toLowerCase();
        if (!id.equalsIgnoreCase("__global__") && (id.endsWith("island") || id.endsWith("nether"))) {
            return id.substring(0, id.length() - 6);
        }
    }
    return null;
}
 
Example #15
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static void islandUnlock(final CommandSender sender, final String islandName) {
    try {
        RegionManager regionManager = getRegionManager(uSkyBlock.getInstance().getWorldManager().getWorld());
        if (regionManager.hasRegion(islandName + "island")) {
            ProtectedRegion region = regionManager.getRegion(islandName + "island");
            updateLockStatus(region, false);
            sender.sendMessage(tr("\u00a7eYour island is unlocked and anyone may enter, however only you and your party members may build or remove blocks."));
        } else {
            sender.sendMessage(tr("\u00a74You must be the party leader to unlock your island!"));
        }
    } catch (Exception ex) {
        LogUtil.log(Level.SEVERE, "ERROR: Failed to unlock " + islandName + "'s Island (" + sender.getName() + ")", ex);
    }
}
 
Example #16
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static void islandLock(final CommandSender sender, final String islandName) {
    try {
        RegionManager regionManager = getRegionManager(uSkyBlock.getInstance().getWorldManager().getWorld());
        if (regionManager.hasRegion(islandName + "island")) {
            ProtectedRegion region = regionManager.getRegion(islandName + "island");
            updateLockStatus(region, true);
            sender.sendMessage(tr("\u00a7eYour island is now locked. Only your party members may enter."));
        } else {
            sender.sendMessage(tr("\u00a74You must be the party leader to lock your island!"));
        }
    } catch (Exception ex) {
        LogUtil.log(Level.SEVERE, "ERROR: Failed to lock " + islandName + "'s Island (" + sender.getName() + ")", ex);
    }
}
 
Example #17
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private static boolean noOrOldRegion(RegionManager regionManager, String regionId, IslandInfo island) {
    if (!regionManager.hasRegion(regionId)) {
        return true;
    }
    if (regionManager.getRegion(regionId).getOwners().size() == 0) {
        return true;
    }
    return !island.getRegionVersion().equals(getVersion());
}
 
Example #18
Source File: WorldGuardHook.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public static ApplicableRegionSet getRegionSet(Location location) {        
    if (location == null || worldGuard == null) {
        return null;
    }
    
    RegionManager regionManager = worldGuard.getRegionManager(location.getWorld());
    if (regionManager == null) {
        return null;
    }

    return regionManager.getApplicableRegions(location);
}
 
Example #19
Source File: WorldUtil.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
public static boolean allowRegion(Location location) {
    if (EchoPet.getPlugin().getWorldGuardProvider().isHooked()) {
        WorldGuardPlugin wg = EchoPet.getPlugin().getWorldGuardProvider().getDependency();
        if (wg == null) {
            return true;
        }
        RegionManager regionManager = wg.getRegionManager(location.getWorld());

        if (regionManager == null) {
            return true;
        }

        ApplicableRegionSet set = regionManager.getApplicableRegions(location);

        if (set.size() <= 0) {
            return true;
        }

        boolean result = true;
        boolean hasSet = false;
        boolean def = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions.allowByDefault", true);

        ConfigurationSection cs = EchoPet.getPlugin().getMainConfig().getConfigurationSection("worldguard.regions");
        for (ProtectedRegion region : set) {
            for (String key : cs.getKeys(false)) {
                if (!key.equalsIgnoreCase("allowByDefault") && !key.equalsIgnoreCase("regionEnterCheck")) {
                    if (region.getId().equals(key)) {
                        if (!hasSet) {
                            result = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions." + key, true);
                            hasSet = true;
                        }
                    }
                }
            }
        }

        return hasSet ? result : def;
    }
    return true;
}
 
Example #20
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static boolean protectIsland(uSkyBlock plugin, CommandSender sender, IslandInfo islandConfig) {
    try {
        RegionManager regionManager = getRegionManager(plugin.getWorldManager().getWorld());
        String regionName = islandConfig.getName() + "island";
        if (islandConfig != null && noOrOldRegion(regionManager, regionName, islandConfig)) {
            updateRegion(islandConfig);
            islandConfig.setRegionVersion(getVersion());
            return true;
        }
    } catch (Exception ex) {
        String name = islandConfig != null ? islandConfig.getLeader() : "Unknown";
        LogUtil.log(Level.SEVERE, "ERROR: Failed to protect " + name + "'s Island (" + sender.getName() + ")", ex);
    }
    return false;
}
 
Example #21
Source File: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
private void flagGlobal(RegionManager regionManager, boolean value) {
    Objects.requireNonNull(regionManager, "regionMark");

    if (regionManager.hasRegion(GLOBAL_REGION_ID)) {
        ProtectedRegion existing = Objects.requireNonNull(regionManager.getRegion(GLOBAL_REGION_ID));
        this.flag(existing, value);
    } else {
        ProtectedRegion region = new GlobalProtectedRegion(GLOBAL_REGION_ID);
        this.flag(region, value);
        regionManager.addRegion(region);
    }
}
 
Example #22
Source File: BridgeImpl.java    From TabooLib with MIT License 5 votes vote down vote up
private RegionManager worldguardRegionManager(World world) {
    if (WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
        return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    } else {
        try {
            return (RegionManager) getRegionManager.invoke(WorldGuardPlugin.inst(), world);
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return null;
    }
}
 
Example #23
Source File: WorldGuardAPI.java    From ActionHealth with MIT License 5 votes vote down vote up
@Nullable
private ApplicableRegionSet getRegionSet(Location location) {
    RegionManager regionManager = getRegionManager(location.getWorld());
    if (regionManager == null) return null;

    try {
        Object vector = vectorConstructorAsAMethodBecauseWhyNot == null
                ? vectorConstructor.newInstance(location.getX(), location.getY(), location.getZ())
                : vectorConstructorAsAMethodBecauseWhyNot.invoke(null, location.getX(), location.getY(), location.getZ());
        return (ApplicableRegionSet) regionManagerGetMethod.invoke(regionManager, vector);
    } catch (Exception ex) {
        main.getLogger().log(Level.SEVERE, "Unable to run WG lookup. SE: 2");
    }
    return null;
}
 
Example #24
Source File: WorldGuardApi.java    From ClaimChunk with MIT License 5 votes vote down vote up
static boolean _isAllowedClaim(ClaimChunk claimChunk, Chunk chunk) {
    try {
        // Generate a region in the given chunk to get all intersecting regions
        int bx = chunk.getX() << 4;
        int bz = chunk.getZ() << 4;
        BlockVector3 pt1 = BlockVector3.at(bx, 0, bz);
        BlockVector3 pt2 = BlockVector3.at(bx + 15, 256, bz + 15);
        ProtectedCuboidRegion region = new ProtectedCuboidRegion("_", pt1, pt2);
        RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(chunk.getWorld()));

        // No regions in this world, claiming should be determined by the config
        if (regionManager == null) {
            return claimChunk.chConfig().getBool("worldguard", "allowClaimingInNonGuardedWorlds");
        }

        // If any regions in the given chunk deny chunk claiming, false is returned
        for (ProtectedRegion regionIn : regionManager.getApplicableRegions(region)) {
            StateFlag.State flag = regionIn.getFlag(FLAG_CHUNK_CLAIM);
            if (flag == StateFlag.State.DENY) return false;
        }

        // No objections
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    // An error occurred, better to be on the safe side so false is returned
    return false;
}
 
Example #25
Source File: WorldUtil.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public static boolean allowRegion(Location location) {
    if (EchoPet.getPlugin().getWorldGuardProvider().isHooked()) {
        WorldGuardPlugin wg = EchoPet.getPlugin().getWorldGuardProvider().getDependency();
        if (wg == null) {
            return true;
        }
        RegionManager regionManager = wg.getRegionManager(location.getWorld());

        if (regionManager == null) {
            return true;
        }

        ApplicableRegionSet set = regionManager.getApplicableRegions(location);

        if (set.size() <= 0) {
            return true;
        }

        boolean result = true;
        boolean hasSet = false;
        boolean def = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions.allowByDefault", true);

        ConfigurationSection cs = EchoPet.getPlugin().getMainConfig().getConfigurationSection("worldguard.regions");
        for (ProtectedRegion region : set) {
            for (String key : cs.getKeys(false)) {
                if (!key.equalsIgnoreCase("allowByDefault") && !key.equalsIgnoreCase("regionEnterCheck")) {
                    if (region.getId().equals(key)) {
                        if (!hasSet) {
                            result = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions." + key, true);
                            hasSet = true;
                        }
                    }
                }
            }
        }

        return hasSet ? result : def;
    }
    return true;
}
 
Example #26
Source File: HookWorldGuard_V6_1.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private static ApplicableRegionSet getRegions(Location location) {
    World world = location.getWorld();

    WorldGuardPlugin api = getAPI();
    RegionManager manager = api.getRegionManager(world);
    return manager.getApplicableRegions(location);
}
 
Example #27
Source File: HookWorldGuard_V6_2.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private static ApplicableRegionSet getRegions(Location location) {
    World world = location.getWorld();

    WorldGuardPlugin api = getAPI();
    RegionManager manager = api.getRegionManager(world);
    return manager.getApplicableRegions(location);
}
 
Example #28
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException {
    final String r = fields.getAndRemoveObject("region", String.class);
    fields.setFields(this);
    RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    final ProtectedRegion region = regionManager.getRegion(r);
    if (region == null)
        throw new StreamCorruptedException("Invalid region " + r + " in world " + world);
    this.region = region;
}
 
Example #29
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Region getRegion_i(final World world, final String name) {
    RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    final ProtectedRegion r = manager.getRegion(name);
    if (r != null)
        return new WorldGuardRegion(world, r);
    return null;
}
 
Example #30
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RegionManager getRegionManager(World world) {
	return WorldGuardPlugin.inst().getRegionManager(world);
}