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

The following examples show how to use com.sk89q.worldguard.protection.regions.RegionContainer. 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: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 6 votes vote down vote up
private boolean define(Player player, RegionContainer container, String regionId, int radius) {
    Objects.requireNonNull(player, "player");
    Objects.requireNonNull(container, "container");
    Objects.requireNonNull(regionId, "regionId");

    World world = BukkitAdapter.adapt(player.getWorld());
    RegionManager regionManager = container.get(world);
    if (regionManager == null) {
        player.sendMessage(ChatColor.RED + "Sorry, region manager for world " + world.getName() + " is not currently accessible.");
        return false;
    }

    BlockVector3 origin = BukkitAdapter.asBlockVector(player.getLocation());
    this.define(regionManager, this.createCuboid(regionId, origin, radius));
    this.flagGlobal(regionManager, true);
    return true;
}
 
Example #2
Source File: HookWorldGuard_V7_0.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: HookWorldGuard_V7_0.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #4
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 #5
Source File: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
private boolean onSafe(Player sender, String label, String[] args) {
    String usage = ChatColor.RED + "/" + label + " safe <radius>";
    if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "Provide safe-from-radiation zone radius in the first argument. Radius will be relative to your current position.");
        sender.sendMessage(usage);
        return true;
    }

    int radius;
    try {
        radius = Integer.parseInt(args[1]);
    } catch (NumberFormatException e) {
        sender.sendMessage(ChatColor.RED + "Number was expected, but " + args[1] + " was provided.");
        sender.sendMessage(ChatColor.RED + usage);
        return true;
    }

    if (radius <= 0) {
        sender.sendMessage(ChatColor.RED + "Radius must be positive.");
        sender.sendMessage(ChatColor.RED + usage);
        return true;
    }

    RegionContainer container = this.worldGuardMatcher.getRegionContainer();
    if (container == null) {
        sender.sendMessage(ChatColor.RED + "Sorry, region container is not currently accessible.");
        return true;
    }

    if (this.define(sender, container, REGION_ID, radius)) {
        BlockVector2 origin = BukkitAdapter.asBlockVector(sender.getLocation()).toBlockVector2();
        sender.sendMessage(ChatColor.GREEN + "A new safe-from-radiation zone has been created in radius " +
                radius + " at the origin at " + origin + " in world " + sender.getWorld().getName() + ".");
    }
    return true;
}
 
Example #6
Source File: HookWorldGuard_V7_0.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
@Override
default boolean test(Player player) {
    RegionContainer regionContainer = this.getRegionContainer();
    return regionContainer != null && this.test(player, regionContainer);
}
 
Example #8
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
default RegionContainer getRegionContainer() {
    WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
    return platform != null ? platform.getRegionContainer() : null;
}
 
Example #9
Source File: WorldGuardIntegration.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example #10
Source File: WorldGuardIntegration.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example #11
Source File: WorldGuardHelperLatest.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<RegionManager> getLoaded() {
    RegionContainer rc = WorldGuard.getInstance().getPlatform().getRegionContainer();
    return rc.getLoaded();
}
 
Example #12
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 votes vote down vote up
boolean test(Player player, RegionContainer regionContainer);