Search in sources :

Example 1 with FaweMaskManager

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

the class FaweBukkit method getMaskManagers.

/**
 * A mask manager handles region restrictions e.g., PlotSquared plots / WorldGuard regions
 */
@Override
public Collection<FaweMaskManager> getMaskManagers() {
    final Plugin worldguardPlugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
    final ArrayList<FaweMaskManager> managers = new ArrayList<>();
    if (worldguardPlugin != null && worldguardPlugin.isEnabled()) {
        try {
            managers.add(new WorldGuardFeature(worldguardPlugin));
            LOGGER.info("Attempting to use plugin 'WorldGuard'");
        } catch (Throwable ignored) {
        }
    }
    final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny");
    if (townyPlugin != null && townyPlugin.isEnabled()) {
        try {
            managers.add(new TownyFeature(townyPlugin));
            LOGGER.info("Attempting to use plugin 'Towny'");
        } catch (Throwable ignored) {
        }
    }
    final Plugin residencePlugin = Bukkit.getServer().getPluginManager().getPlugin("Residence");
    if (residencePlugin != null && residencePlugin.isEnabled()) {
        try {
            managers.add(new ResidenceFeature(residencePlugin, this));
            LOGGER.info("Attempting to use plugin 'Residence'");
        } catch (Throwable ignored) {
        }
    }
    final Plugin griefpreventionPlugin = Bukkit.getServer().getPluginManager().getPlugin("GriefPrevention");
    if (griefpreventionPlugin != null && griefpreventionPlugin.isEnabled()) {
        try {
            managers.add(new GriefPreventionFeature(griefpreventionPlugin));
            LOGGER.info("Attempting to use plugin 'GriefPrevention'");
        } catch (Throwable ignored) {
        }
    }
    final Plugin griefdefenderPlugin = Bukkit.getServer().getPluginManager().getPlugin("GriefDefender");
    if (griefdefenderPlugin != null && griefdefenderPlugin.isEnabled()) {
        try {
            managers.add(new GriefDefenderFeature(griefdefenderPlugin));
            LOGGER.info("Attempting to use plugin 'GriefDefender'");
        } catch (Throwable ignored) {
        }
    }
    return managers;
}
Also used : GriefDefenderFeature(com.fastasyncworldedit.bukkit.regions.GriefDefenderFeature) WorldGuardFeature(com.fastasyncworldedit.bukkit.regions.WorldGuardFeature) GriefPreventionFeature(com.fastasyncworldedit.bukkit.regions.GriefPreventionFeature) TownyFeature(com.fastasyncworldedit.bukkit.regions.TownyFeature) ArrayList(java.util.ArrayList) FaweMaskManager(com.fastasyncworldedit.core.regions.FaweMaskManager) Plugin(org.bukkit.plugin.Plugin) ResidenceFeature(com.fastasyncworldedit.bukkit.regions.ResidenceFeature)

Example 2 with FaweMaskManager

use of com.fastasyncworldedit.core.regions.FaweMaskManager 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

FaweMaskManager (com.fastasyncworldedit.core.regions.FaweMaskManager)2 GriefDefenderFeature (com.fastasyncworldedit.bukkit.regions.GriefDefenderFeature)1 GriefPreventionFeature (com.fastasyncworldedit.bukkit.regions.GriefPreventionFeature)1 ResidenceFeature (com.fastasyncworldedit.bukkit.regions.ResidenceFeature)1 TownyFeature (com.fastasyncworldedit.bukkit.regions.TownyFeature)1 WorldGuardFeature (com.fastasyncworldedit.bukkit.regions.WorldGuardFeature)1 FaweMask (com.fastasyncworldedit.core.regions.FaweMask)1 Region (com.sk89q.worldedit.regions.Region)1 Location (com.sk89q.worldedit.util.Location)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Plugin (org.bukkit.plugin.Plugin)1