public static boolean isInRegion(Location location) { ApplicableRegionSet regionSet = getRegionSet(location); if (regionSet == null) { return false; } return regionSet.size() != 0; }
@Nullable @Override public Set<String> getSpellOverrides(RegionAssociable source, ApplicableRegionSet checkSet) { return checkSet.queryValue(source, SPELL_OVERRIDES); }
private void update(LocalPlayer localPlayer, ApplicableRegionSet set, boolean allowed) { if (!allowed) { storedMessage = set.queryValue(localPlayer, Flags.EXIT_DENY_MESSAGE); exitViaTeleport = set.testState(localPlayer, Flags.EXIT_VIA_TELEPORT); } }
@EventHandler public void canBuild(BuildPermissionEvent event) { ApplicableRegionSet regions = getApplicableRegions(event.getSign().getBlock().getLocation()); if (regions != null && Properties.WORLDGUARD_USE_FLAG) { event.allow(regions.queryState(worldGuard.wrapPlayer(event.getPlayer()), WorldGuardFlags.ENABLE_SHOP) == StateFlag.State.ALLOW); } else { event.allow(regions == null || regions.size() != 0); } }
ApplicableRegionSet set = regionManager.getApplicableRegions(player.getLocation().toVector().toBlockPoint()); if (set.size() == 0) { if (allowGlobal) { ProtectedRegion global = checkExistingRegion(regionManager, "__global__", true); "You're not standing in a region." + "Specify an ID if you want to select a specific region."); } else if (set.size() > 1) { StringBuilder builder = new StringBuilder(); boolean first = true; return set.iterator().next();
if (regions.size() > 0) { if (!regions.isOwnerOfAll(player)) { throw new CommandException("This region overlaps with someone else's region.");
/** * Get the (effective) value for a list of state flags. The rules of * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, * and {@code ALLOW} overrides {@code NONE}. One flag may override another. * * <p>{@code player} can be non-null to satisfy region group requirements, * otherwise it will be assumed that the caller that is not a member of any * regions. (FlagUtil on a region can be changed so that they only apply * to certain users.) The player argument is required if the * {@link Flags#BUILD} flag is in the list of flags.</p> * * @param location the location * @param player an optional player, which would be used to determine the region groups that apply * @param flags a list of flags to check * @return a state * @see RegionResultSet#queryState(RegionAssociable, StateFlag...) */ @Nullable public State queryState(Location location, @Nullable LocalPlayer player, StateFlag... flags) { return getApplicableRegions(location).queryState(player, flags); }
public static List<String> getRegionNames(Location location) { ApplicableRegionSet regionSet = getRegionSet(location); return regionSet == null ? null : regionSet.getRegions().stream() .map(ProtectedRegion::getId) .collect(Collectors.toList()); }
@Override public boolean onCrossBoundary(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) { boolean allowed = toSet.testState(player, Flags.ENTRY); if (!getSession().getManager().hasBypass(player, (World) to.getExtent()) && !allowed && moveType.isCancellable()) { String message = toSet.queryValue(player, Flags.ENTRY_DENY_MESSAGE); long now = System.currentTimeMillis(); if ((now - lastMessage) > MESSAGE_THRESHOLD && message != null && !message.isEmpty()) { player.printRaw(CommandUtils.replaceColorMacros(message)); lastMessage = now; } return false; } else { return true; } }
/** * Get the (effective) value for a list of state flags. The rules of * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, * and {@code ALLOW} overrides {@code NONE}. One flag may override another. * * <p>{@code player} can be non-null to satisfy region group requirements, * otherwise it will be assumed that the caller that is not a member of any * regions. (FlagUtil on a region can be changed so that they only apply * to certain users.) The player argument is required if the * {@link Flags#BUILD} flag is in the list of flags.</p> * * @param location the location * @param associable an optional associable * @param flags a list of flags to check * @return a state * @see RegionResultSet#queryState(RegionAssociable, StateFlag...) */ @Nullable public State queryState(Location location, @Nullable RegionAssociable associable, StateFlag... flags) { return getApplicableRegions(location).queryState(associable, flags); }
@Override public Association getAssociation(List<ProtectedRegion> regions) { if (source == null) { ApplicableRegionSet result = query.getApplicableRegions(location); source = result.getRegions(); } for (ProtectedRegion region : regions) { if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) { return Association.OWNER; } } return Association.NON_MEMBER; }
@Test public void testWildernessFlags() { MockApplicableRegionSet mock = new MockApplicableRegionSet(); LocalPlayer player = mock.createPlayer(); ApplicableRegionSet set = mock.getApplicableSet(); assertThat(set.testState(player, Flags.MOB_DAMAGE), is(true)); assertThat(set.testState(player, Flags.ENTRY), is(true)); assertThat(set.testState(player, Flags.EXIT), is(true)); assertThat(set.testState(player, Flags.LEAF_DECAY), is(true)); assertThat(set.testState(player, Flags.RECEIVE_CHAT), is(true)); assertThat(set.testState(player, Flags.SEND_CHAT), is(true)); assertThat(set.testState(player, Flags.INVINCIBILITY), is(false)); assertThat(set.testState(player, Flags.BUILD), is(true)); }
@Nullable @Override public String getDestructible(RegionAssociable source, ApplicableRegionSet checkSet) { return checkSet.queryValue(source, DESTRUCTIBLE); }
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(eventLoc)); if (!set.testState(null, Flags.MOB_SPAWNING)) { event.setCancelled(true); return; Set<com.sk89q.worldedit.world.entity.EntityType> entityTypes = set.queryValue(null, Flags.DENY_SPAWN); if (entityTypes != null && weEntityType != null && entityTypes.contains(weEntityType)) { event.setCancelled(true);
public boolean isRegion(Block block) { try { if (wg == null) { return false; } RegionManager manager = wg.getRegionManager(block.getWorld()); ApplicableRegionSet regions = manager.getApplicableRegions(block.getLocation()); return regions.size() > 0; } catch (Exception ex) { return false; } }
public boolean isPVPAllowed(Player player, Location location) { if (worldGuardPlugin == null || location == null) return true; ApplicableRegionSet checkSet = getRegionSet(location); if (checkSet == null) return true; return checkSet.queryState(getAssociable(player), pvpFlag) != StateFlag.State.DENY; }
public static boolean isInIgnoredRegion(Location location) { if (!isInRegion(location)) { return false; } PluginConfig config = Settings.getConfig(); return getRegionSet(location).getRegions() .stream() .anyMatch(region -> config.assistsRegionsIgnored.contains(region.getId())); }