Java Code Examples for com.sk89q.worldguard.protection.regions.ProtectedRegion#contains()

The following examples show how to use com.sk89q.worldguard.protection.regions.ProtectedRegion#contains() . 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: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public static List<Player> getPlayersInRegion(World world, ProtectedRegion region) {
    // Note: This might be heavy - for large servers...
    List<Player> players = new ArrayList<>();
    if (region == null) {
        return players;
    }
    for (Player player : world.getPlayers()) {
        if (player != null && player.isOnline()) {
            Location p = player.getLocation();
            if (region.contains(p.getBlockX(), p.getBlockY(), p.getBlockZ())) {
                players.add(player);
            }
        }
    }
    return players;
}
 
Example 2
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 3
Source File: WorldGuardSupport.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
public static boolean a(Location loc){
		WorldGuard wGuard = WorldGuard.getInstance();
		for (ProtectedRegion k : wGuard.getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())).getRegions().values()) {
			if (k.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
				if (k.getFlag(Flags.PVP) == com.sk89q.worldguard.protection.flags.StateFlag.State.DENY)
					return false;
			}
		}
	return true;
}
 
Example 4
Source File: WorldGuardSupport.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
public static boolean canExplode(Location loc){
	WorldGuard wGuard = WorldGuard.getInstance();
	for (ProtectedRegion k : wGuard.getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())).getRegions().values()) {
		if (k.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
			if (k.getFlag(Flags.OTHER_EXPLOSION) == com.sk89q.worldguard.protection.flags.StateFlag.State.DENY)
				return false;
		}
	}
	return true;
}
 
Example 5
Source File: uSkyBlock.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public boolean locationIsOnNetherIsland(final Player player, final Location loc) {
    if (!getWorldManager().isSkyNether(loc.getWorld())) {
        return false;
    }
    PlayerInfo playerInfo = playerLogic.getPlayerInfo(player);
    if (playerInfo != null && playerInfo.getHasIsland()) {
        Location p = playerInfo.getIslandNetherLocation();
        if (p == null) {
            return false;
        }
        ProtectedRegion region = WorldGuardHandler.getNetherRegionAt(p);
        return region != null && region.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    }
    return false;
}
 
Example 6
Source File: uSkyBlock.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public boolean locationIsOnIsland(final Player player, final Location loc) {
    if (!getWorldManager().isSkyWorld(loc.getWorld())) {
        return false;
    }
    PlayerInfo playerInfo = playerLogic.getPlayerInfo(player);
    if (playerInfo != null && playerInfo.getHasIsland()) {
        Location p = playerInfo.getIslandLocation();
        if (p == null) {
            return false;
        }
        ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(p);
        return region != null && region.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    }
    return false;
}
 
Example 7
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static List<LivingEntity> getCreaturesInRegion(World world, ProtectedRegion region) {
    List<LivingEntity> livingEntities = world.getLivingEntities();
    List<LivingEntity> creatures = new ArrayList<>();
    for (LivingEntity e : livingEntities) {
        if (region.contains(asVector(e.getLocation()))) {
            creatures.add(e);
        }
    }
    return creatures;
}
 
Example 8
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
	Set<ProtectedRegion> result = new HashSet<>();
	Vector vector = new Vector(location.getX(), location.getY(), location.getZ());
	for(ProtectedRegion region : pluginInterface.getWorldGuard().getRegionManager(location.getWorld()).getRegions().values()) {
		if(region.contains(vector)) {
			result.add(region);
		}
	}
	return result;
}
 
Example 9
Source File: WorldGuardHandler7_beta_2.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
	Set<ProtectedRegion> result = new HashSet<>();
	BlockVector3 vector = BlockVector3.at(location.getX(), location.getY(), location.getZ());
	for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) {
		if(region.contains(vector)) {
			result.add(region);
		}
	}
	return result;
}
 
Example 10
Source File: WorldGuardHandler6.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
	Set<ProtectedRegion> result = new HashSet<>();
	Vector vector = new Vector(location.getX(), location.getY(), location.getZ());
	for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) {
		if(region.contains(vector)) {
			result.add(region);
		}
	}
	return result;
}
 
Example 11
Source File: FastAsyncWorldEditWorldGuardHandler.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
	Set<ProtectedRegion> result = new HashSet<>();
	com.sk89q.worldedit.Vector vector = new com.sk89q.worldedit.Vector(location.getX(), location.getY(), location.getZ());
	for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) {
		if(region.contains(vector)) {
			result.add(region);
		}
	}
	return result;
}
 
Example 12
Source File: WorldGuardHandler7_beta_1.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
	Set<ProtectedRegion> result = new HashSet<>();
	Vector vector = new Vector(location.getX(), location.getY(), location.getZ());
	for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) {
		if(region.contains(vector)) {
			result.add(region);
		}
	}
	return result;
}
 
Example 13
Source File: BiomeCommand.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean doExecute(String alias, final Player player, PlayerInfo pi, final IslandInfo island, Map<String, Object> data, final String... args) {
    if (args.length == 0) {
        if (!island.hasPerm(player, "canChangeBiome")) {
            player.sendMessage(tr("\u00a7cYou do not have permission to change the biome of your current island."));
        } else {
            player.openInventory(menu.displayBiomeGUI(player)); // Weird, that we show the UI
        }
    }
    if (args.length >= 1) {
        final String biome = args[0].toLowerCase();
        if (!island.hasPerm(player, "canChangeBiome")) {
            player.sendMessage(tr("\u00a74You do not have permission to change the biome of this island!"));
            return true;
        }
        Location location = player.getLocation();
        ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(location);
        if (!plugin.playerIsOnOwnIsland(player) || region == null) {
            player.sendMessage(tr("\u00a7eYou must be on your island to change the biome!"));
            return true;
        }
        if (!biomeExists(biome)) {
            player.sendMessage(tr("\u00a7cYou have misspelled the biome name. Must be one of {0}", BIOMES.keySet()));
            return true;
        }
        int cooldown = plugin.getCooldownHandler().getCooldown(player, "biome");
        if (cooldown > 0) {
            player.sendMessage(tr("\u00a7eYou can change your biome again in {0,number,#} minutes.", cooldown / 60));
            return true;
        }
        if (!player.hasPermission("usb.biome." + biome.toLowerCase())) {
            player.sendMessage(tr("\u00a7cYou do not have permission to change your biome to that type."));
            return true;
        }
        BlockVector3 minP = region.getMinimumPoint();
        BlockVector3 maxP = region.getMaximumPoint();
        if (args.length == 2 && args[1].matches("[0-9]+")) {
            int radius = Integer.parseInt(args[1], 10);
            Location loc = location.clone().add(-radius, 0, -radius);
            if (region.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
                minP = BlockVector3.at(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
            }
            loc = location.clone().add(radius, 0, radius);
            if (region.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
                maxP = BlockVector3.at(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
            }
            player.sendMessage(tr("\u00a77The pixies are busy changing the biome near you to \u00a79{0}\u00a77, be patient.", biome));
        } else if (args.length == 2 && args[1].equalsIgnoreCase("chunk")) {
            Chunk chunk = location.clone().getChunk();
            minP = BlockVector3.at(chunk.getX() << 4, 0, chunk.getZ() << 4);
            maxP = BlockVector3.at((chunk.getX() << 4) + 15, location.getWorld().getMaxHeight(), (chunk.getZ() << 4) + 15);
            player.sendMessage(tr("\u00a77The pixies are busy changing the biome in your current chunk to \u00a79{0}\u00a77, be patient.", biome));
        } else if (args.length < 2 || args[1].equalsIgnoreCase("all")) {
            player.sendMessage(tr("\u00a77The pixies are busy changing the biome of your island to \u00a79{0}\u00a77, be patient.", biome));
        }
        Biome biomeEnum = BIOMES.get(biome);
        if (biomeEnum == null) {
            player.sendMessage(tr("\u00a7eInvalid biome {0} supplied!", biome));
            return true;
        }
        new SetBiomeTask(plugin, player.getWorld(), minP, maxP, biomeEnum, () -> {
            if (args.length == 1) {
                island.setBiome(biome);
                player.sendMessage(tr("\u00a7aYou have changed your island''s biome to {0}", biome.toUpperCase()));
                island.sendMessageToIslandGroup(true, marktr("{0} changed the island biome to {1}"), player.getName(), biome.toUpperCase());
                plugin.getCooldownHandler().resetCooldown(player, "biome", Settings.general_biomeChange);
            } else {
                player.sendMessage(tr("\u00a7aYou have changed {0} blocks around you to the {1} biome", args[1], biome.toUpperCase()));
                island.sendMessageToIslandGroup(true, marktr("{0} created an area with {1} biome"), player.getName(), biome.toUpperCase());
            }
        }).runTask(plugin);
    }
    return true;
}
 
Example 14
Source File: SetteleportCommand.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
	if(!sender.hasPermission("areashop.setteleport") && !sender.hasPermission("areashop.setteleportall")) {
		plugin.message(sender, "setteleport-noPermission");
		return;
	}
	if(!(sender instanceof Player)) {
		plugin.message(sender, "onlyByPlayer");
		return;
	}
	Player player = (Player)sender;
	GeneralRegion region;
	if(args.length < 2) {
		// get the region by location
		List<GeneralRegion> regions = Utils.getImportantRegions(((Player)sender).getLocation());
		if(regions.isEmpty()) {
			plugin.message(sender, "cmd-noRegionsAtLocation");
			return;
		} else if(regions.size() > 1) {
			plugin.message(sender, "cmd-moreRegionsAtLocation");
			return;
		} else {
			region = regions.get(0);
		}
	} else {
		region = plugin.getFileManager().getRegion(args[1]);
	}

	boolean owner;

	if(region == null) {
		plugin.message(player, "setteleport-noRentOrBuy", args[1]);
		return;
	}
	if(region instanceof RentRegion) {
		owner = player.getUniqueId().equals(((RentRegion)region).getRenter());
	} else {
		owner = player.getUniqueId().equals(((BuyRegion)region).getBuyer());
	}
	if(!player.hasPermission("areashop.setteleport")) {
		plugin.message(player, "setteleport-noPermission", region);
		return;
	} else if(!owner && !player.hasPermission("areashop.setteleportall")) {
		plugin.message(player, "setteleport-noPermissionOther", region);
		return;
	}

	ProtectedRegion wgRegion = region.getRegion();
	if(args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("reset") || args[2].equalsIgnoreCase("yes") || args[2].equalsIgnoreCase("true"))) {
		region.getTeleportFeature().setTeleport(null);
		region.update();
		plugin.message(player, "setteleport-reset", region);
		return;
	}
	if(!player.hasPermission("areashop.setteleportoutsideregion") && (wgRegion == null || !wgRegion.contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
		plugin.message(player, "setteleport-notInside", region);
		return;
	}
	region.getTeleportFeature().setTeleport(player.getLocation());
	region.update();
	plugin.message(player, "setteleport-success", region);
}
 
Example 15
Source File: GeneralRegion.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate the volume of the region (could be expensive for polygon regions).
 * @return Number of blocks in the region
 */
private long calculateVolume() {
	// Use own calculation for polygon regions, as WorldGuard does not implement it and returns 0
	ProtectedRegion region = getRegion();
	if(region instanceof ProtectedPolygonalRegion) {
		Vector min = getMinimumPoint();
		Vector max = getMaximumPoint();

		// Exact, but slow algorithm
		if(getWidth() * getDepth() < 100) {
			long surface = 0;
			for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
				for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
					if (region.contains(x, min.getBlockY(), z)) {
						surface++;
					}
				}
			}
			return surface * getHeight();
		}
		// Estimate, but quick algorithm
		else {
			List<Vector> points = plugin.getWorldGuardHandler().getRegionPoints(region);
			int numPoints = points.size();
			if(numPoints < 3) {
				return 0;
			}

			double area = 0;
			int x1, x2, z1, z2;
			for(int i = 0; i <= numPoints - 2; i++) {
				x1 = points.get(i).getBlockX();
				z1 = points.get(i).getBlockZ();

				x2 = points.get(i + 1).getBlockX();
				z2 = points.get(i + 1).getBlockZ();

				area += ((z1 + z2) * (x1 - x2));
			}

			x1 = points.get(numPoints - 1).getBlockX();
			z1 = points.get(numPoints - 1).getBlockZ();
			x2 = points.get(0).getBlockX();
			z2 = points.get(0).getBlockZ();

			area += ((z1 + z2) * (x1 - x2));
			area = Math.ceil(Math.abs(area) / 2);
			return (long)(area * getHeight());
		}
	} else {
		return region.volume();
	}
}