Search in sources :

Example 1 with FaweMask

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

the class TownyFeature method getMask.

@Override
public FaweMask getMask(final com.sk89q.worldedit.entity.Player wePlayer, MaskType type, boolean isWhitelist) {
    final Player player = BukkitAdapter.adapt(wePlayer);
    final Location location = player.getLocation();
    try {
        final PlayerCache cache = ((Towny) this.towny).getCache(player);
        final WorldCoord mycoord = cache.getLastTownBlock();
        if (mycoord == null) {
            return null;
        }
        final TownBlock myplot = mycoord.getTownBlock();
        if (myplot == null) {
            return null;
        }
        boolean isMember = isAllowed(player, myplot);
        if (isMember) {
            final Chunk chunk = location.getChunk();
            final BlockVector3 pos1 = BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16);
            final BlockVector3 pos2 = BlockVector3.at(chunk.getX() * 16 + 15, 156, chunk.getZ() * 16 + 15);
            return new FaweMask(new CuboidRegion(pos1, pos2)) {

                @Override
                public boolean isValid(com.sk89q.worldedit.entity.Player player, MaskType type) {
                    return isAllowed(BukkitAdapter.adapt(player), myplot);
                }
            };
        }
    } catch (Exception ignored) {
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Chunk(org.bukkit.Chunk) BlockVector3(com.sk89q.worldedit.math.BlockVector3) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Towny(com.palmergames.bukkit.towny.Towny) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location)

Example 2 with FaweMask

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

the class GriefPreventionFeature method getMask.

@Override
public FaweMask getMask(final com.sk89q.worldedit.entity.Player wePlayer, MaskType type, boolean isWhitelist) {
    final Player player = BukkitAdapter.adapt(wePlayer);
    final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), true, null);
    if (claim != null) {
        if (isAllowed(player, claim, type)) {
            claim.getGreaterBoundaryCorner().getBlockX();
            final BlockVector3 pos1 = BlockVector3.at(claim.getLesserBoundaryCorner().getBlockX(), wePlayer.getWorld().getMinY(), claim.getLesserBoundaryCorner().getBlockZ());
            final BlockVector3 pos2 = BlockVector3.at(claim.getGreaterBoundaryCorner().getBlockX(), wePlayer.getWorld().getMaxY(), claim.getGreaterBoundaryCorner().getBlockZ());
            return new FaweMask(new CuboidRegion(pos1, pos2)) {

                @Override
                public boolean isValid(com.sk89q.worldedit.entity.Player wePlayer, MaskType type) {
                    return isAllowed(player, claim, type);
                }
            };
        }
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Claim(me.ryanhamshire.GriefPrevention.Claim)

Example 3 with FaweMask

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

the class GriefDefenderFeature method getMask.

@Override
public FaweMask getMask(final com.sk89q.worldedit.entity.Player wePlayer, MaskType type, boolean isWhitelist) {
    final Player player = BukkitAdapter.adapt(wePlayer);
    Claim claim = GriefDefender.getCore().getClaimAt(player.getLocation());
    if (claim != null && !claim.isWilderness()) {
        if (isAllowed(player, claim, type)) {
            final BlockVector3 pos1 = BlockVector3.at(claim.getLesserBoundaryCorner().getX(), claim.getLesserBoundaryCorner().getY(), claim.getLesserBoundaryCorner().getZ());
            final BlockVector3 pos2 = BlockVector3.at(claim.getGreaterBoundaryCorner().getX(), claim.getGreaterBoundaryCorner().getY(), claim.getGreaterBoundaryCorner().getZ());
            return new FaweMask(new CuboidRegion(pos1, pos2)) {

                @Override
                public boolean isValid(com.sk89q.worldedit.entity.Player wePlayer, MaskType type) {
                    return isAllowed(player, claim, type);
                }
            };
        }
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Claim(com.griefdefender.api.claim.Claim)

Example 4 with FaweMask

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

the class ResidenceFeature method getMask.

@Override
public FaweMask getMask(final com.sk89q.worldedit.entity.Player wePlayer, final MaskType type, boolean isWhitelist) {
    final Player player = BukkitAdapter.adapt(wePlayer);
    final Location location = player.getLocation();
    ClaimedResidence residence = Residence.getInstance().getResidenceManager().getByLoc(location);
    if (residence != null) {
        boolean isAllowed;
        while (!(isAllowed = isAllowed(player, residence, type)) && residence != null) {
            residence = residence.getSubzoneByLoc(location);
        }
        if (isAllowed) {
            final CuboidArea area = residence.getAreaArray()[0];
            final Location pos1 = area.getLowLoc();
            final Location pos2 = area.getHighLoc();
            final ClaimedResidence finalResidence = residence;
            return new FaweMask(new CuboidRegion(BukkitAdapter.asBlockVector(pos1), BukkitAdapter.asBlockVector(pos2))) {

                @Override
                public boolean isValid(com.sk89q.worldedit.entity.Player player, MaskType type) {
                    return isAllowed(BukkitAdapter.adapt(player), finalResidence, type);
                }
            };
        }
    }
    return null;
}
Also used : Player(org.bukkit.entity.Player) ClaimedResidence(com.bekvon.bukkit.residence.protection.ClaimedResidence) CuboidArea(com.bekvon.bukkit.residence.protection.CuboidArea) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Location(org.bukkit.Location)

Example 5 with FaweMask

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

the class PlotSquaredFeature method getMask.

@Override
public FaweMask getMask(Player player, MaskType type, boolean isWhitelist) {
    final PlotPlayer<org.bukkit.entity.Player> pp = PlotPlayer.from(BukkitAdapter.adapt(player));
    if (pp == null) {
        return null;
    }
    final Set<CuboidRegion> regions;
    Plot plot = pp.getCurrentPlot();
    if (isAllowed(player, plot, type)) {
        regions = plot.getRegions();
    } else {
        plot = null;
        regions = WEManager.getMask(pp);
        if (regions.size() == 1) {
            CuboidRegion region = regions.iterator().next();
            if (region.getMinimumPoint().getX() == Integer.MIN_VALUE && region.getMaximumPoint().getX() == Integer.MAX_VALUE) {
                regions.clear();
            }
        }
    }
    if (regions.isEmpty()) {
        return null;
    }
    PlotArea area = pp.getApplicablePlotArea();
    final Plot finalPlot = plot;
    if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(finalPlot) || regions.isEmpty()) {
        return null;
    }
    Region maskedRegion;
    if (regions.size() == 1) {
        int min = area != null ? area.getMinBuildHeight() : player.getWorld().getMinY();
        int max = area != null ? Math.min(player.getWorld().getMaxY(), area.getMaxBuildHeight()) : player.getWorld().getMaxY();
        final CuboidRegion region = regions.iterator().next();
        final BlockVector3 pos1 = BlockVector3.at(region.getMinimumX(), min, region.getMinimumZ());
        final BlockVector3 pos2 = BlockVector3.at(region.getMaximumX(), max, region.getMaximumZ());
        maskedRegion = new CuboidRegion(pos1, pos2);
    } else {
        World world = FaweAPI.getWorld(area.getWorldName());
        List<Region> weRegions = regions.stream().map(r -> new CuboidRegion(world, BlockVector3.at(r.getMinimumX(), r.getMinimumY(), r.getMinimumZ()), BlockVector3.at(r.getMaximumX(), r.getMaximumY(), r.getMaximumZ()))).collect(Collectors.toList());
        maskedRegion = new RegionIntersection(world, weRegions);
    }
    return new FaweMask(maskedRegion) {

        @Override
        public boolean isValid(Player player, MaskType type) {
            if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(finalPlot)) {
                return false;
            }
            return isAllowed(player, finalPlot, type);
        }
    };
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) Player(com.sk89q.worldedit.entity.Player) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) World(com.sk89q.worldedit.world.World) Caption(com.fastasyncworldedit.core.configuration.Caption) DoneFlag(com.plotsquared.core.plot.flag.implementations.DoneFlag) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) WEManager(com.plotsquared.core.util.WEManager) Locale(java.util.Locale) Region(com.sk89q.worldedit.regions.Region) Bukkit(org.bukkit.Bukkit) DBFunc(com.plotsquared.core.database.DBFunc) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) Plot(com.plotsquared.core.plot.Plot) LogManagerCompat(com.sk89q.worldedit.internal.util.LogManagerCompat) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NoWorldeditFlag(com.plotsquared.core.plot.flag.implementations.NoWorldeditFlag) List(java.util.List) Logger(org.apache.logging.log4j.Logger) PlotPlayer(com.plotsquared.core.player.PlotPlayer) BukkitAdapter(com.sk89q.worldedit.bukkit.BukkitAdapter) FaweMaskManager(com.fastasyncworldedit.core.regions.FaweMaskManager) FaweAPI(com.fastasyncworldedit.core.FaweAPI) Settings(com.plotsquared.core.configuration.Settings) PlotArea(com.plotsquared.core.plot.PlotArea) Player(com.sk89q.worldedit.entity.Player) PlotPlayer(com.plotsquared.core.player.PlotPlayer) PlotArea(com.plotsquared.core.plot.PlotArea) FaweMask(com.fastasyncworldedit.core.regions.FaweMask) Plot(com.plotsquared.core.plot.Plot) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) World(com.sk89q.worldedit.world.World) RegionIntersection(com.sk89q.worldedit.regions.RegionIntersection) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region)

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