Java源码示例:com.sk89q.worldguard.protection.flags.StateFlag

示例1
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;
}
 
示例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
@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");
}
 
示例4
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);
}
 
示例5
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;
}
 
示例6
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);
}
 
示例7
/**
 * 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;
}
 
示例8
private static void updateLockStatus(ProtectedRegion region, boolean isLocked) {
    if (isLocked) {
        region.setFlag(Flags.ENTRY, StateFlag.State.DENY);
    } else {
        region.setFlag(Flags.ENTRY, null);
    }
}
 
示例9
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);
    }
}
 
示例10
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;
}
 
示例11
@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;
}
 
示例12
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);
}
 
示例13
public static boolean allowsPVP(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, DefaultFlag.PVP);
    return (state != StateFlag.State.DENY);
}
 
示例14
public static boolean allowsMobCombat(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, mobCombatFlag);
    return (state != StateFlag.State.DENY);
}
 
示例15
public static boolean allowsPVP(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, DefaultFlag.PVP);
    return (state != StateFlag.State.DENY);
}
 
示例16
public static boolean allowsMobCombat(Location location) {
    ApplicableRegionSet regions = getRegions(location);
    StateFlag.State state = regions.queryState(null, mobCombatFlag);
    return (state != StateFlag.State.DENY);
}
 
示例17
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);
}