com.sk89q.worldguard.protection.ApplicableRegionSet Java Examples

The following examples show how to use com.sk89q.worldguard.protection.ApplicableRegionSet. 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: 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 #2
Source File: WorldGuard7FAWEHook.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();
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    if (query == null)
        return r;
    ApplicableRegionSet applicable = query.getApplicableRegions(BukkitAdapter.adapt(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 #3
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 #4
Source File: FaweWorldEditFlagMaskManager.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
public ProtectedRegion getRegion(Player player, Location loc)
{
    final com.sk89q.worldguard.LocalPlayer localplayer = this.plugin.getWorldGuardCommunicator().wrapPlayer(player);
    AbstractRegionManagerWrapper manager = this.plugin.getWorldGuardCommunicator().getRegionContainer().get(player.getWorld());
    final ProtectedRegion global = manager.getRegion("__global__");
    if (global != null && !isDenied(localplayer, global))
    {
        return global;
    }
    
    final ApplicableRegionSet regions = manager.getApplicableRegions(player.getLocation());
    for (final ProtectedRegion region : regions)
    {
        if (!isDenied(localplayer, region))
        {
            return region;
        }
    }
    return null;
}
 
Example #5
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 #6
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 #7
Source File: EssentialsListener.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onGodStatusChangeEvent(GodStatusChangeEvent event)
{
	IUser user = event.getAffected();
	Player player = user.getBase();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	
	State state = WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.GODMODE);
	if (state != null)
	{
		if (this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GodmodeFlagHandler.class).getIsGodmodeEnabled() != null)
		{
			event.setCancelled(true);
		}
	}
}
 
Example #8
Source File: EntityListenerOnePointNine.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityToggleGlideEvent(EntityToggleGlideEvent event)
{
	Entity entity = event.getEntity();
	if (entity instanceof Player)
	{
		Player player = (Player)entity;
		
		ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());

		ForcedState state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.GLIDE);
		if (state != ForcedState.ALLOW)
		{
			event.setCancelled(true);
			
			player.setGliding(state == ForcedState.FORCE);
			
			if (state == ForcedState.DENY)
			{
				player.teleport(player.getLocation());
			}
		}
	}
}
 
Example #9
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 #10
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
{
	Player player = event.getPlayer();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	
	String prefix = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.CHAT_PREFIX);
	String suffix = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.CHAT_SUFFIX);

	if (prefix != null)
	{
		event.setFormat(prefix + event.getFormat());
	}
	
	if (suffix != null)
	{
		event.setFormat(event.getFormat() + suffix);
	}
}
 
Example #11
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 #12
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerRespawnEvent(PlayerRespawnEvent event)
{
	Player player = event.getPlayer();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	
	Object respawnLocation = WorldGuardUtils.queryValueUnchecked(player, player.getWorld(), regions.getRegions(), Flags.RESPAWN_LOCATION);
	if (respawnLocation != null)
	{
		event.setRespawnLocation(WorldEditUtils.toLocation(respawnLocation));
	}
}
 
Example #13
Source File: WorldGuardHook.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public static boolean isInRegion(Location location) {
    ApplicableRegionSet regionSet = getRegionSet(location);
    if (regionSet == null) {
        return false;
    }

    return regionSet.size() != 0;
}
 
Example #14
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 #15
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private static Set<ProtectedRegion> getRegions(ApplicableRegionSet set) {
    Set<ProtectedRegion> regions = new HashSet<>();
    for (ProtectedRegion region : set) {
        regions.add(region);
    }
    return regions;
}
 
Example #16
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 #17
Source File: WorldEditFlagHandler.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException
{
	ApplicableRegionSet regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(this.weWorld).getApplicableRegions(location);

	State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT);
	if (state != State.DENY)
	{
		return super.setBlock(location, block);
	}
	
	return false;
}
 
Example #18
Source File: BlockListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockBreakEvent(BreakBlockEvent event)
{
	Result originalResult = event.getResult();
	Object cause = event.getCause().getRootCause();
	
	if (cause instanceof Player)
	{
		Player player = (Player)cause;

		for(Block block : event.getBlocks())
		{
			ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());

			Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_BREAK);
			if (state != null && state.contains(block.getType()))
			{
				event.setResult(Result.ALLOW);
			}
			else
			{
				Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_BREAK);
				if (state2 != null && state2.contains(block.getType()))
				{
					event.setResult(Result.DENY);
					return;
				}
				else
				{
					event.setResult(originalResult);
					return;
				}
			}
		}
	}
}
 
Example #19
Source File: WorldEditFlagHandler.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException
{
	ApplicableRegionSet regions = WorldGuardPlugin.inst().getRegionContainer().get(this.world).getApplicableRegions(location);
	
	State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT);
	if (state != State.DENY)
	{
		return super.setBlock(location, block);
	}
	
	return false;
}
 
Example #20
Source File: BlockListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockPlaceEvent(PlaceBlockEvent event)
{
	Result originalResult = event.getResult();
	Object cause = event.getCause().getRootCause();

	if (cause instanceof Player)
	{
		Player player = (Player)cause;

		for(Block block : event.getBlocks())
		{
			ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
			
			Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_PLACE);
			if (state != null && state.contains(block.getType()))
			{
				event.setResult(Result.ALLOW);
			}
			else
			{
				Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_PLACE);
				if (state2 != null && state2.contains(block.getType()))
				{
					event.setResult(Result.DENY);
					return;
				}
				else
				{
					event.setResult(originalResult);
					return;
				}
			}
    	}
	}
}
 
Example #21
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 #22
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 #23
Source File: BlockListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityBlockFormEvent(EntityBlockFormEvent event)
{
	if (SupportedFeatures.isFrostwalkerSupported())
	{
		BlockState newState = event.getNewState();
		if (newState.getType() == Material.FROSTED_ICE)
		{
			ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(newState.getLocation());
			
			Entity entity = event.getEntity();
			if (entity instanceof Player)
			{
				Player player = (Player)entity;
				if (WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.FROSTWALKER) == State.DENY)
				{
					event.setCancelled(true);
				}
			}
			else
			{
				if (regions.queryValue(null, Flags.FROSTWALKER) == State.DENY)
				{
					event.setCancelled(true);
				}
			}
		}
	}
}
 
Example #24
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerSpawnLocationEvent(PlayerSpawnLocationEvent event)
{
	Player player = event.getPlayer();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	
	Object location = WorldGuardUtils.queryValueUnchecked(player, player.getWorld(), regions.getRegions(), Flags.JOIN_LOCATION);
	if (location != null)
	{
		event.setSpawnLocation(WorldEditUtils.toLocation(location));
	}
}
 
Example #25
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemDamageEvent(PlayerItemDamageEvent event)
{
	Player player = event.getPlayer();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	if (WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.ITEM_DURABILITY) == State.DENY)
	{
		event.setCancelled(true);
	}
}
 
Example #26
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 #27
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerDeathEvent(PlayerDeathEvent event)
{
	Player player = event.getEntity();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	
	Boolean keepInventory = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.KEEP_INVENTORY);
	if (keepInventory != null)
	{
		event.setKeepInventory(keepInventory);
		
		if (keepInventory)
		{
			event.getDrops().clear();
		}
	}
	
	Boolean keepExp = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.KEEP_EXP);
	if (keepExp != null)
	{
		event.setKeepLevel(keepExp);

		if (keepExp)
		{
			event.setDroppedExp(0);
		}
	}
}
 
Example #28
Source File: EntityListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPortalCreateEvent(PortalCreateEvent event)
{
	for(Block block : event.getBlocks())
	{
		//Unable to get the player who created it....
		
		ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
		if (regions.queryValue(null, Flags.NETHER_PORTALS) == State.DENY)
		{
			event.setCancelled(true);
			break;
		}
	}
}
 
Example #29
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test(Player player, RegionContainer regionContainer) {
    Location location = BukkitAdapter.adapt(player.getLocation());
    location = location.setY(Math.max(0, Math.min(255, location.getY())));
    ApplicableRegionSet regions = regionContainer.createQuery().getApplicableRegions(location);

    Boolean value = regions.queryValue(WorldGuardPlugin.inst().wrapPlayer(player), this.flag);
    return value != null && value;
}
 
Example #30
Source File: HandlerWrapper.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public boolean onCrossBoundary(LocalPlayer localPlayer, com.sk89q.worldedit.util.Location from, com.sk89q.worldedit.util.Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
	//It turns out that this is fired every time player moves
	//The plugin flags assume already that nothing changes unless region is crossed, so ignore when there isn't a region change
	//This optimization is already in place in the FVCH
	if (entered.isEmpty() && exited.isEmpty() && from.getExtent().equals(to.getExtent()))
	{
           return true;
       }
	
	return this.onCrossBoundary(((BukkitPlayer)localPlayer).getPlayer(), BukkitAdapter.adapt(from), BukkitAdapter.adapt(to), toSet, entered, exited, moveType);
}