Search in sources :

Example 1 with State

use of com.sk89q.worldguard.protection.flags.StateFlag.State in project CombatLogX by SirBlobman.

the class ProtectionStonesRegionHandler method isSafeZone.

@Override
public boolean isSafeZone(Player player, Location location, TagType tagType) {
    if (tagType != TagType.PLAYER)
        return false;
    PSRegion region = PSRegion.fromLocation(location);
    if (region == null)
        return false;
    ProtectedRegion wgRegion = region.getWGRegion();
    if (wgRegion == null)
        return false;
    State pvpState = wgRegion.getFlag(Flags.PVP);
    return (pvpState == State.DENY);
}
Also used : State(com.sk89q.worldguard.protection.flags.StateFlag.State) PSRegion(dev.espi.protectionstones.PSRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion)

Example 2 with State

use of com.sk89q.worldguard.protection.flags.StateFlag.State in project WorldGuard by EngineHub.

the class FlagValueCalculator method getEffectiveFlagOf.

@SuppressWarnings("unchecked")
@Nullable
public static <V> V getEffectiveFlagOf(final ProtectedRegion region, Flag<V> flag, @Nullable RegionAssociable subject) {
    if (region.getId().equals(ProtectedRegion.GLOBAL_REGION)) {
        if (flag == Flags.PASSTHROUGH) {
            // Has members/owners -> the global region acts like
            // a regular region without PASSTHROUGH
            State passthrough = region.getFlag(Flags.PASSTHROUGH);
            if (passthrough == State.DENY || passthrough != State.ALLOW && region.hasMembersOrOwners()) {
                return null;
            } else {
                return (V) State.ALLOW;
            }
        } else if (flag instanceof StateFlag && ((StateFlag) flag).preventsAllowOnGlobal()) {
            // Legacy behavior -> we can't let people change BUILD on
            // the global region
            State value = region.getFlag((StateFlag) flag);
            return value != State.ALLOW ? (V) value : null;
        }
    }
    ProtectedRegion current = region;
    List<ProtectedRegion> seen = new ArrayList<>();
    while (current != null) {
        seen.add(current);
        V value = current.getFlag(flag);
        if (value != null) {
            boolean use = true;
            if (flag.getRegionGroupFlag() != null) {
                RegionGroup group = current.getFlag(flag.getRegionGroupFlag());
                if (group == null) {
                    group = flag.getRegionGroupFlag().getDefault();
                }
                if (group == null) {
                    use = false;
                } else if (subject == null) {
                    use = group.contains(Association.NON_MEMBER);
                } else if (!group.contains(subject.getAssociation(seen))) {
                    use = false;
                }
            }
            if (use) {
                return value;
            }
        }
        current = current.getParent();
    }
    return null;
}
Also used : State(com.sk89q.worldguard.protection.flags.StateFlag.State) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) ArrayList(java.util.ArrayList) StateFlag(com.sk89q.worldguard.protection.flags.StateFlag) RegionGroup(com.sk89q.worldguard.protection.flags.RegionGroup) Nullable(javax.annotation.Nullable)

Aggregations

State (com.sk89q.worldguard.protection.flags.StateFlag.State)2 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)2 RegionGroup (com.sk89q.worldguard.protection.flags.RegionGroup)1 StateFlag (com.sk89q.worldguard.protection.flags.StateFlag)1 PSRegion (dev.espi.protectionstones.PSRegion)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1