Search in sources :

Example 6 with FaweMask

use of com.fastasyncworldedit.core.regions.FaweMask in project FastAsyncWorldEdit by IntellectualSites.

the class WEManager method getMask.

/**
 * Get a player's mask.
 *
 * @param player      Player to get mask of
 * @param type        Mask type; whether to check if the player is an owner of a member of the regions
 * @param isWhitelist If searching for whitelist or blacklist regions. True if whitelist
 * @return array of allowed regions if whitelist, else of disallowed regions.
 */
public Region[] getMask(Player player, FaweMaskManager.MaskType type, final boolean isWhitelist) {
    if (!Settings.settings().REGION_RESTRICTIONS || player.hasPermission("fawe.bypass") || player.hasPermission("fawe.bypass.regions")) {
        return new Region[] { RegionWrapper.GLOBAL() };
    }
    Location loc = player.getLocation();
    String world = player.getWorld().getName();
    if (!world.equals(player.getMeta("lastMaskWorld"))) {
        player.deleteMeta("lastMaskWorld");
        player.deleteMeta("lastMask");
    }
    player.setMeta("lastMaskWorld", world);
    Set<FaweMask> masks = player.getMeta("lastMask");
    Set<Region> backupRegions = new HashSet<>();
    Set<Region> regions = new HashSet<>();
    if (masks == null || !isWhitelist) {
        masks = new HashSet<>();
    } else {
        synchronized (masks) {
            boolean removed = false;
            if (!masks.isEmpty()) {
                Iterator<FaweMask> iterator = masks.iterator();
                while (iterator.hasNext()) {
                    FaweMask mask = iterator.next();
                    if (mask.isValid(player, type)) {
                        Region region = mask.getRegion();
                        if (region.contains(loc.toBlockPoint())) {
                            regions.add(region);
                        } else {
                            removed = true;
                            backupRegions.add(region);
                        }
                    } else {
                        player.print(Caption.of("fawe.error.region-mask-invalid", mask.getClass().getSimpleName()));
                        removed = true;
                        iterator.remove();
                    }
                }
            }
            if (!removed) {
                return regions.toArray(new Region[0]);
            }
            masks.clear();
        }
    }
    for (FaweMaskManager manager : managers) {
        if (player.hasPermission("fawe." + manager.getKey())) {
            try {
                if (manager.isExclusive() && !masks.isEmpty()) {
                    continue;
                }
                final FaweMask mask = manager.getMask(player, FaweMaskManager.MaskType.getDefaultMaskType(), isWhitelist);
                if (mask != null) {
                    regions.add(mask.getRegion());
                    masks.add(mask);
                    if (manager.isExclusive()) {
                        break;
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        } else {
            player.printError(TextComponent.of("Missing permission " + "fawe." + manager.getKey()));
        }
    }
    if (isWhitelist) {
        regions.addAll(backupRegions);
        if (!masks.isEmpty()) {
            player.setMeta("lastMask", masks);
        } else {
            player.deleteMeta("lastMask");
        }
    }
    return regions.toArray(new Region[0]);
}
Also used : FaweMask(com.fastasyncworldedit.core.regions.FaweMask) Region(com.sk89q.worldedit.regions.Region) FaweMaskManager(com.fastasyncworldedit.core.regions.FaweMaskManager) Location(com.sk89q.worldedit.util.Location) HashSet(java.util.HashSet)

Aggregations

FaweMask (com.fastasyncworldedit.core.regions.FaweMask)6 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)5 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)4 Player (org.bukkit.entity.Player)4 FaweMaskManager (com.fastasyncworldedit.core.regions.FaweMaskManager)2 Region (com.sk89q.worldedit.regions.Region)2 Location (org.bukkit.Location)2 ClaimedResidence (com.bekvon.bukkit.residence.protection.ClaimedResidence)1 CuboidArea (com.bekvon.bukkit.residence.protection.CuboidArea)1 FaweAPI (com.fastasyncworldedit.core.FaweAPI)1 Caption (com.fastasyncworldedit.core.configuration.Caption)1 Claim (com.griefdefender.api.claim.Claim)1 Towny (com.palmergames.bukkit.towny.Towny)1 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)1 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)1 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)1 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)1 Settings (com.plotsquared.core.configuration.Settings)1 DBFunc (com.plotsquared.core.database.DBFunc)1 PlotPlayer (com.plotsquared.core.player.PlotPlayer)1