com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion Java Examples

The following examples show how to use com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion. 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: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
private Location findAirSpawnLocation(Location location, Vector v, ProtectedCuboidRegion islandRegion) {
    // Searches in a cone for an air block
    Location lookAt = new Location(location.getWorld(),
            Math.round(location.getX() + v.getX()),
            Math.round(location.getY() + v.getY()),
            Math.round(location.getZ() + v.getZ()));
    while (v.length() < maxScan) {
        for (Location loc : getLocationsInPlane(lookAt, v)) {
            if (loc.getBlock().getType() == Material.AIR && isAdjacentToSolid(loc)
                    && isInIslandRegion(islandRegion, loc)) {
                return loc;
            }
        }
        double n = v.length();
        v.normalize().multiply(n+1);
    }
    return null;
}
 
Example #2
Source File: WorldGuardSevenCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@Override
public boolean doUnloadChunkFlagCheck(org.bukkit.World world, Chunk chunk) 
{
	for (ProtectedRegion region : this.getRegionContainer().get(world).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16), BlockVector3.at(chunk.getX() * 16 + 15, 256, chunk.getZ() * 16 + 15))))
	{
		if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY)
		{
			if (WorldGuardSevenCommunicator.supportsForceLoad)
			{
				chunk.setForceLoaded(true);
				chunk.load(true);
				
				return true;
			}
			
			return false;
		}
	}
	
	return true;
}
 
Example #3
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isIslandIntersectingSpawn(Location islandLocation) {
    log.entering(CN, "isIslandIntersectingSpawn", islandLocation);
    try {
        int r = Settings.general_spawnSize;
        if (r == 0) {
            return false;
        }
        ProtectedRegion spawn = new ProtectedCuboidRegion("spawn", BlockVector3.at(-r, 0, -r), BlockVector3.at(r, 255, r));
        ProtectedCuboidRegion islandRegion = getIslandRegion(islandLocation);
        return !islandRegion.getIntersectingRegions(Collections.singletonList(spawn)).isEmpty();
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unable to locate intersecting regions", e);
        return false;
    } finally {
        log.exiting(CN, "isIslandIntersectingSpawn");
    }
}
 
Example #4
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 #5
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 #6
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private Location findSolidSpawnLocation(Location location, Vector v, ProtectedCuboidRegion islandRegion) {
    // Searches in a cone for an air block
    while (v.length() < maxScan) {
        for (Location loc : getLocationsInPlane(location, v)) {
            if (loc.getBlock().getType() == Material.AIR
                    && loc.getBlock().getRelative(BlockFace.DOWN).getType().isSolid()
                    && isInIslandRegion(islandRegion, loc)) {
                return loc;
            }
        }
        double n = v.length();
        v.normalize().multiply(n+1);
    }
    return null;
}
 
Example #7
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void spawnBlock(Material type, Location location, Vector v, ProtectedCuboidRegion islandRegion) {
    Location spawnLoc = null;
    if (MaterialUtil.isFallingMaterial(type)) {
        spawnLoc = findSolidSpawnLocation(location, v, islandRegion);
    } else {
        spawnLoc = findAirSpawnLocation(location, v, islandRegion);
    }
    if (spawnLoc != null) {
        spawnLoc.getWorld().getBlockAt(spawnLoc).setType(type);
    }
}
 
Example #8
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (event == null || !terraformEnabled) {
        return;
    }
    Block block = event.getBlock();
    Player player = event.getPlayer();
    if (!plugin.getWorldManager().isSkyNether(block.getWorld()) || !plugin.getWorldManager().isSkyNether(player.getWorld())) {
        return; // Bail out, not our problem
    }
    if (player.getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    if (!plugin.playerIsOnIsland(player)) {
        return;
    }
    if (!terraFormMap.containsKey(block.getType())) {
        return; // Not a block we terra-form on.
    }
    // TODO: 10/07/2016 - R4zorax: Handle dual-wielding (would break 1.8 compatibility)
    ItemStack tool = event.getPlayer().getItemInHand();
    if (event.getBlock().getDrops(tool).isEmpty()) {
        return; // Only terra-form when stuff is mined correctly
    }
    double toolWeight = getToolWeight(tool);
    Location playerLocation = player.getEyeLocation();
    Location blockLocation = LocationUtil.centerInBlock(block.getLocation());
    Vector v = new Vector(blockLocation.getX(), blockLocation.getY(), blockLocation.getZ());
    v.subtract(new Vector(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ()));
    v.normalize();
    // Disable spawning above the player... enabling the player to clear a region
    if (playerLocation.getPitch() >= minPitch && playerLocation.getPitch() <= maxPitch) {
        ProtectedCuboidRegion islandRegion = WorldGuardHandler.getIslandRegion(playerLocation);
        List<Material> yield = getYield(block.getType(), toolWeight);
        for (Material mat : yield) {
            spawnBlock(mat, blockLocation, v, islandRegion);
        }
    }
}
 
Example #9
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static ProtectedCuboidRegion getIslandRegion(Location islandLocation) {
    int r = Settings.island_radius;
    BlockVector3 islandCenter = BlockVector3.at(islandLocation.getBlockX(), 0, islandLocation.getBlockZ());
    return new ProtectedCuboidRegion(
            String.format("%d,%disland", islandCenter.getBlockX(), islandLocation.getBlockZ()),
            getProtectionVectorLeft(islandLocation),
            getProtectionVectorRight(islandLocation));
}
 
Example #10
Source File: WorldGuardFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean containsRegion(int mcaX, int mcaZ) {
    if (!large) return super.containsRegion(mcaX, mcaZ);
    BlockVector pos1 = new BlockVector(mcaX << 9, 0, mcaZ << 9);
    BlockVector pos2 = new BlockVector(pos1.getBlockX() + 511, 255, pos1.getBlockZ() + 511);
    ProtectedCuboidRegion regionRegion = new ProtectedCuboidRegion("unimportant", pos1, pos2);
    ApplicableRegionSet set = manager.getApplicableRegions(regionRegion);
    return set.size() > 0 && !set.getRegions().iterator().next().getId().equals("__global__");
}
 
Example #11
Source File: WorldGuardFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean containsChunk(int chunkX, int chunkZ) {
    if (!large) return super.containsChunk(chunkX, chunkZ);
    BlockVector pos1 = new BlockVector(chunkX << 4, 0, chunkZ << 4);
    BlockVector pos2 = new BlockVector(pos1.getBlockX() + 15, 255, pos1.getBlockZ() + 15);
    ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("unimportant", pos1, pos2);
    ApplicableRegionSet set = manager.getApplicableRegions(chunkRegion);
    return set.size() > 0 && !set.getRegions().iterator().next().getId().equals("__global__");
}
 
Example #12
Source File: Worldguard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private static Region adapt(ProtectedRegion region) {
    if (region instanceof ProtectedCuboidRegion) {
        return new CuboidRegion(region.getMinimumPoint(), region.getMaximumPoint());
    }
    if (region instanceof GlobalProtectedRegion) {
        return RegionWrapper.GLOBAL();
    }
    if (region instanceof ProtectedPolygonalRegion) {
        ProtectedPolygonalRegion casted = (ProtectedPolygonalRegion) region;
        BlockVector max = region.getMaximumPoint();
        BlockVector min = region.getMinimumPoint();
        return new Polygonal2DRegion(null, casted.getPoints(), min.getBlockY(), max.getBlockY());
    }
    return new AdaptedRegion(region);
}
 
Example #13
Source File: WorldGuardSixCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public boolean doUnloadChunkFlagCheck(org.bukkit.World world, Chunk chunk) 
{
	for (ProtectedRegion region : this.getRegionContainer().get(world).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", new BlockVector(chunk.getX() * 16, 0, chunk.getZ() * 16), new BlockVector(chunk.getX() * 16 + 15, 256, chunk.getZ() * 16 + 15))))
	{
		if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY)
		{
			return false;
		}
	}
	
	return true;
}
 
Example #14
Source File: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
private ProtectedCuboidRegion createCuboid(String regionId, BlockVector3 origin, int radius) {
    Objects.requireNonNull(regionId, "regionId");
    Objects.requireNonNull(origin, "origin");

    BlockVector3 min = origin.subtract(radius, 0, radius).withY(0);
    BlockVector3 max = origin.add(radius, 0, radius).withY(255);
    return new ProtectedCuboidRegion(regionId, min, max);
}
 
Example #15
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private static ProtectedCuboidRegion setRegionFlags(IslandInfo islandConfig) {
    String regionName = islandConfig.getName() + "island";
    return setRegionFlags(islandConfig, regionName);
}
 
Example #16
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private static ProtectedCuboidRegion setRegionFlags(IslandInfo islandConfig, String regionName) {
    Location islandLocation = islandConfig.getIslandLocation();
    BlockVector3 minPoint = getProtectionVectorRight(islandLocation);
    BlockVector3 maxPoint = getProtectionVectorLeft(islandLocation);
    if (regionName != null && regionName.endsWith("nether")) {
        minPoint = minPoint.withY(6);
        maxPoint = maxPoint.withY(120);
    }
    ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, minPoint, maxPoint);
    final DefaultDomain owners = new DefaultDomain();
    DefaultDomain members = new DefaultDomain();
    for (UUID member : islandConfig.getMemberUUIDs()) {
        owners.addPlayer(member);
    }
    for (UUID trust : islandConfig.getTrusteeUUIDs()) {
        members.addPlayer(trust);
    }
    region.setOwners(owners);
    region.setMembers(members);
    region.setPriority(100);
    if (uSkyBlock.getInstance().getConfig().getBoolean("worldguard.entry-message", true)) {
        if (owners.size() == 0) {
            region.setFlag(Flags.GREET_MESSAGE, tr("\u00a74** You are entering a protected - but abandoned - island area."));
        } else {
            region.setFlag(Flags.GREET_MESSAGE, tr("\u00a7d** You are entering \u00a7b{0}''s \u00a7disland.", islandConfig.getLeader()));
        }
    } else {
        region.setFlag(Flags.GREET_MESSAGE, null);
    }
    if (uSkyBlock.getInstance().getConfig().getBoolean("worldguard.exit-message", true)) {
        if (owners.size() == 0) {
            region.setFlag(Flags.FAREWELL_MESSAGE, tr("\u00a74** You are leaving an abandoned island."));
        } else {
            region.setFlag(Flags.FAREWELL_MESSAGE, tr("\u00a7d** You are leaving \u00a7b{0}''s \u00a7disland.", islandConfig.getLeader()));
        }
    } else {
        region.setFlag(Flags.FAREWELL_MESSAGE, null);
    }
    region.setFlag(Flags.PVP, null);
    boolean isLocked = islandConfig.isLocked();
    updateLockStatus(region, isLocked);
    return region;
}
 
Example #17
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isInRegion(ProtectedCuboidRegion islandRegion, Location loc) {
    return islandRegion.contains(asVector(loc));
}
 
Example #18
Source File: AbstractRegionManagerWrapper.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
public ApplicableRegionSet getApplicableRegions(ProtectedCuboidRegion protectedCuboidRegion)
{
	return this.regionManager.getApplicableRegions(protectedCuboidRegion);
}
 
Example #19
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private boolean isInIslandRegion(ProtectedCuboidRegion islandRegion, Location loc) {
    return WorldGuardHandler.isInRegion(islandRegion, loc);
}
 
Example #20
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ProtectedCuboidRegion createCuboidRegion(String name, org.bukkit.util.Vector corner1, org.bukkit.util.Vector corner2) {
	return new ProtectedCuboidRegion(name, new BlockVector(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), new BlockVector(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
}
 
Example #21
Source File: WorldGuardHandler7_beta_2.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ProtectedCuboidRegion createCuboidRegion(String name, Vector corner1, Vector corner2) {
	return new ProtectedCuboidRegion(name, BlockVector3.at(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), BlockVector3.at(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
}
 
Example #22
Source File: WorldGuardHandler6.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ProtectedCuboidRegion createCuboidRegion(String name, org.bukkit.util.Vector corner1, org.bukkit.util.Vector corner2) {
	return new ProtectedCuboidRegion(name, new BlockVector(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), new BlockVector(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
}
 
Example #23
Source File: FastAsyncWorldEditWorldGuardHandler.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ProtectedCuboidRegion createCuboidRegion(String name, Vector corner1, Vector corner2) {
	return new ProtectedCuboidRegion(name, new BlockVector(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), new BlockVector(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
}
 
Example #24
Source File: WorldGuardHandler7_beta_1.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ProtectedCuboidRegion createCuboidRegion(String name, org.bukkit.util.Vector corner1, org.bukkit.util.Vector corner2) {
	return new ProtectedCuboidRegion(name, new BlockVector(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), new BlockVector(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
}
 
Example #25
Source File: WorldGuardInterface.java    From AreaShop with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create a CuboidRegion.
 * @param name Name to use in WorldEdit
 * @param min Minimum point
 * @param max Maximum point
 * @return CuboidRegion
 */
public abstract ProtectedCuboidRegion createCuboidRegion(String name, Vector min, Vector max);