Java源码示例:com.sk89q.worldguard.protection.regions.RegionQuery

示例1
@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;
}
 
示例2
public static boolean allowsMobCombat(Location location) {
    WorldGuard api = getAPI();
    WorldGuardPlatform platform = api.getPlatform();
    RegionContainer container = platform.getRegionContainer();
    
    RegionQuery query = container.createQuery();
    com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location);
    
    if(MOB_COMBAT_FLAG instanceof StateFlag) {
        StateFlag mobCombatFlag = (StateFlag) MOB_COMBAT_FLAG;
        State state = query.queryState(weLocation, null, mobCombatFlag);
        return (state != State.DENY);
    }
    
    return true;
}
 
示例3
public static boolean allowsTagging(Location location) {
    WorldGuard api = getAPI();
    WorldGuardPlatform platform = api.getPlatform();
    RegionContainer container = platform.getRegionContainer();
    RegionQuery query = container.createQuery();
    
    if(NO_TAGGING_FLAG instanceof BooleanFlag) {
        BooleanFlag noTaggingFlag = (BooleanFlag) NO_TAGGING_FLAG;
        com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location);
        
        Boolean value = query.queryValue(weLocation, null, noTaggingFlag);
        return (value == null || !value);
    }
    
    return true;
}
 
示例4
/**
 * Check if a player can build in a region
 *
 * @param player
 * @param block
 * @return
 */
private boolean canBuild(Player player, Block block) {
    LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(player);
    RegionPermissionModel regionPermissionModel = new RegionPermissionModel(localPlayer);
    if (regionPermissionModel.mayIgnoreRegionProtection(BukkitAdapter.adapt(block.getWorld()))) {
        return true;
    }
    RegionQuery regionQuery = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    return regionQuery.testBuild(BukkitAdapter.adapt(block.getLocation()), localPlayer);
}
 
示例5
public boolean test(Entity entity){
    try {
        RegionQuery rq = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
        return !(rq.testState(BukkitAdapter.adapt(entity.getLocation()), null, ENTITY_FLAG));
    }catch (NullPointerException e){
        return false;
    }
}
 
示例6
@Override
public boolean canBuild_i(final Player p, final Location l) {
    if (p.hasPermission("worldguard.region.bypass." + l.getWorld().getName())) return true;
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer(p);
    return query.testState(BukkitAdapter.adapt(l), player, Flags.BUILD);
}
 
示例7
@Override
public boolean canBuild_i(Player p, Location l) {
	if (p.hasPermission("worldguard.region.bypass." + l.getWorld().getName()))
		return true; // Build access always granted by permission
	WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
	RegionQuery query = platform.getRegionContainer().createQuery();
	return query.testBuild(BukkitAdapter.adapt(l), plugin.wrapPlayer(p));
}
 
示例8
public static boolean allowsPVP(Location location) {
    WorldGuard api = getAPI();
    WorldGuardPlatform platform = api.getPlatform();
    RegionContainer container = platform.getRegionContainer();
    RegionQuery query = container.createQuery();

    com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location);
    StateFlag.State state = query.queryState(weLocation, null, Flags.PVP);
    return (state != StateFlag.State.DENY);
}
 
示例9
@Override
public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) {
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
    com.sk89q.worldedit.util.Location wgLoc = BukkitAdapter.adapt(location);
    boolean canBypass =
            WorldGuard.getInstance()
                    .getPlatform()
                    .getSessionManager()
                    .hasBypass(localPlayer, BukkitAdapter.adapt(location.getWorld()));
    if (canBypass) {
        Util.debugLog(
                "Player "
                        + player.getName()
                        + " bypassing the protection checks, because player have bypass permission in WorldGuard");
        return true;
    }
    RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
    RegionQuery query = container.createQuery();
    if (query.getApplicableRegions(wgLoc).getRegions().isEmpty()) {
        return !whiteList;
    }
    for (WorldGuardFlags flag : createFlags) {
        switch (flag) {
            case BUILD:
                if (query.queryState(wgLoc, localPlayer, Flags.BUILD) == StateFlag.State.DENY) {
                    return false;
                }
                break;
            case FLAG:
                if (query.queryState(wgLoc, localPlayer, this.createFlag) == StateFlag.State.DENY) {
                    return false;
                }
                break;
            case CHEST_ACCESS:
                if (query.queryState(wgLoc, localPlayer, Flags.CHEST_ACCESS) == StateFlag.State.DENY) {
                    return false;
                }
                break;
            case INTERACT:
                if (query.queryState(wgLoc, localPlayer, Flags.INTERACT) == StateFlag.State.DENY) {
                    return false;
                }
                break;
        }
    }
    return true;
}
 
示例10
@Override
public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) {
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
    com.sk89q.worldedit.util.Location wgLoc = BukkitAdapter.adapt(location);
    boolean canBypass =
            WorldGuard.getInstance()
                    .getPlatform()
                    .getSessionManager()
                    .hasBypass(localPlayer, BukkitAdapter.adapt(location.getWorld()));
    if (canBypass) {
        Util.debugLog(
                "Player "
                        + player.getName()
                        + " bypassing the protection checks, because player have bypass permission in WorldGuard");
        return true;
    }
    RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
    RegionQuery query = container.createQuery();
    if (query.getApplicableRegions(wgLoc).getRegions().isEmpty()) {
        return !whiteList;
    }
    for (WorldGuardFlags flag : tradeFlags) {
        switch (flag) {
            case BUILD:
                if (!query.testState(wgLoc, localPlayer, Flags.BUILD)) {
                    return false;
                }

                break;
            case FLAG:
                if (!query.testState(wgLoc, localPlayer, this.tradeFlag)) {
                    return false;
                }
                break;
            case CHEST_ACCESS:
                if (!query.testState(wgLoc, localPlayer, Flags.CHEST_ACCESS)) {
                    return false;
                }
                break;
            case INTERACT:
                if (!query.testState(wgLoc, localPlayer, Flags.INTERACT)) {
                    return false;
                }
                break;
        }
    }
    return true;
}