com.sk89q.worldguard.protection.flags.StateFlag Java Examples

The following examples show how to use com.sk89q.worldguard.protection.flags.StateFlag. 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: WorldGuardApi.java    From ClaimChunk with MIT License 6 votes vote down vote up
static boolean _init(ClaimChunk claimChunk) {
    FLAG_CHUNK_CLAIM = new StateFlag(CHUNK_CLAIM_FLAG_NAME,
            claimChunk.chConfig().getBool("worldguard", "allowClaimsInRegionsByDefault"));

    try {
        FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
        registry.register(FLAG_CHUNK_CLAIM);
        return true;
    } catch (FlagConflictException ignored) {
        Utils.err("Flag \"%s\" is already registered with WorldGuard. Another plugin conflicts with us!", CHUNK_CLAIM_FLAG_NAME);
    } catch (Exception e) {
        Utils.err("Failed to initialize WorldGuard support");
        e.printStackTrace();
    }
    return false;
}
 
Example #2
Source File: DependencyManager.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() throws Exception {
	if(!Config.REGION_WORLDGUARD.getBoolean()) {
		LoggerUtils.info("Skipping WorldGuardFlag Injector. Disabled in config");
		return;
	}

	plugin.getRegionManager().createWorldGuardFlag();
	FieldAccessor<Flag[]> defaultFlagFlagListField = Reflections.getField(DefaultFlag.class, "flagsList", Flag[].class);
	defaultFlagFlagListField.setNotFinal();
	Flag[] array = defaultFlagFlagListField.get(null);
	List<Flag> list = new ArrayList<>();
	Collections.addAll(list, array);
	list.add((StateFlag) RegionManager.WORLDGUARD_FLAG);
	defaultFlagFlagListField.set(list.toArray(new Flag[list.size()]));
	LoggerUtils.info("Successfully injected WorldGuard Flag");
}
 
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 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 #4
Source File: WorldGuardHook.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public static boolean isInNonPointsRegion(Location location) {
    if (!isInRegion(location)) {
        return false;
    }
    
    for (ProtectedRegion region : getRegionSet(location)) {
        if (region.getFlag(noPointsFlag) == StateFlag.State.ALLOW) {
            return true;
        }
    }

    return false;
}
 
Example #5
Source File: WorldGuardHook.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public static void initWorldGuard() {
    WorldGuardHook.worldGuard = WorldGuardPlugin.inst();
    noPointsFlag = new StateFlag("fg-no-points", false);
    
    try {
        ((FlagRegistry) GET_FLAG_REGISTRY.invoke(GET_INSTANCE.invoke(null))).register(noPointsFlag);
    }
    catch (FlagConflictException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        FunnyGuilds.getInstance().getPluginLogger().error("An error occurred while registering an \"fg-no-points\" worldguard flag", ex);
    }
}
 
Example #6
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private static void updateLockStatus(ProtectedRegion region, boolean isLocked) {
    if (isLocked) {
        region.setFlag(Flags.ENTRY, StateFlag.State.DENY);
    } else {
        region.setFlag(Flags.ENTRY, null);
    }
}
 
Example #7
Source File: RegionManager.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks WorldGuard validity if possible
 *
 * @param selection region selection
 * @return true if valid
 */
private boolean checkWorldGuardValidity(RegionSelection selection) {
	if(!plugin.getDependencyManager().isEnabled(Dependency.WORLDGUARD)) {
		return true;
	}

	WorldGuardPlugin worldGuard = plugin.getDependencyManager().get(Dependency.WORLDGUARD, WorldGuardPlugin.class);
	Area selectionArea = new Area(new Rectangle(
			selection.getCorner(selection.getCorner(0).getBlockX() < selection.getCorner(1).getBlockX() ? 0 : 1).getBlockX(),
			selection.getCorner(selection.getCorner(0).getBlockZ() < selection.getCorner(1).getBlockZ() ? 0 : 1).getBlockZ(),
			selection.getWidth(),
			selection.getLength())
	);

	for(ProtectedRegion region : worldGuard.getRegionManager(selection.getWorld()).getRegions().values()) {
		if(region.getFlag((Flag) RegionManager.WORLDGUARD_FLAG) == StateFlag.State.ALLOW) {
			continue;
		}

		Area regionArea = RegionUtils.toArea(region);

		regionArea.intersect(selectionArea);
		if(!regionArea.isEmpty()) {
			return false;
		}
	}

	return true;
}
 
Example #8
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 #9
Source File: WorldGuardApi.java    From ClaimChunk with MIT License 5 votes vote down vote up
static boolean _isAllowedClaim(ClaimChunk claimChunk, Chunk chunk) {
    try {
        // Generate a region in the given chunk to get all intersecting regions
        int bx = chunk.getX() << 4;
        int bz = chunk.getZ() << 4;
        BlockVector3 pt1 = BlockVector3.at(bx, 0, bz);
        BlockVector3 pt2 = BlockVector3.at(bx + 15, 256, bz + 15);
        ProtectedCuboidRegion region = new ProtectedCuboidRegion("_", pt1, pt2);
        RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(chunk.getWorld()));

        // No regions in this world, claiming should be determined by the config
        if (regionManager == null) {
            return claimChunk.chConfig().getBool("worldguard", "allowClaimingInNonGuardedWorlds");
        }

        // If any regions in the given chunk deny chunk claiming, false is returned
        for (ProtectedRegion regionIn : regionManager.getApplicableRegions(region)) {
            StateFlag.State flag = regionIn.getFlag(FLAG_CHUNK_CLAIM);
            if (flag == StateFlag.State.DENY) return false;
        }

        // No objections
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    // An error occurred, better to be on the safe side so false is returned
    return false;
}
 
Example #10
Source File: HookWorldGuard_V6_2.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static boolean allowsMobCombat(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, mobCombatFlag);
    return (state != StateFlag.State.DENY);
}
 
Example #11
Source File: HookWorldGuard_V6_1.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static boolean allowsPVP(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, DefaultFlag.PVP);
    return (state != StateFlag.State.DENY);
}
 
Example #12
Source File: HookWorldGuard_V6_1.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static boolean allowsMobCombat(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, mobCombatFlag);
    return (state != StateFlag.State.DENY);
}
 
Example #13
Source File: Main.java    From ArmorStandTools with MIT License 4 votes vote down vote up
private boolean getWorldGuardAstFlag(Location l) {
    RegionManager regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(l.getWorld()));
    if(regions == null) return true;
    return regions.getApplicableRegions(BukkitAdapter.asBlockVector(l)).testState(null, (StateFlag) WG_AST_FLAG);
}
 
Example #14
Source File: HookWorldGuard_V6_2.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static boolean allowsPVP(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, DefaultFlag.PVP);
    return (state != StateFlag.State.DENY);
}
 
Example #15
Source File: WorldGuardUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
public static State queryState(Player player, World world, Set<ProtectedRegion> regions, StateFlag flag)
{
	return WorldGuardUtils.createFlagValueCalculator(player, world, regions, flag).queryState(WorldGuardUtils.wrapPlayer(player), flag);
}
 
Example #16
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 #17
Source File: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
private void define(RegionManager regionManager, ProtectedRegion region) {
    Objects.requireNonNull(regionManager, "regionManager");
    Objects.requireNonNull(region, "region");

    String id = region.getId();
    if (regionManager.hasRegion(id)) {
        ProtectedRegion existing = Objects.requireNonNull(regionManager.getRegion(id));
        region.copyFrom(existing);
    }

    this.flag(region, false);
    region.setFlag(Flags.PASSTHROUGH, StateFlag.State.ALLOW);
    regionManager.addRegion(region);
}