Search in sources :

Example 1 with PlotPlayer

use of com.plotsquared.core.player.PlotPlayer 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

FaweAPI (com.fastasyncworldedit.core.FaweAPI)1 Caption (com.fastasyncworldedit.core.configuration.Caption)1 FaweMask (com.fastasyncworldedit.core.regions.FaweMask)1 FaweMaskManager (com.fastasyncworldedit.core.regions.FaweMaskManager)1 Settings (com.plotsquared.core.configuration.Settings)1 DBFunc (com.plotsquared.core.database.DBFunc)1 PlotPlayer (com.plotsquared.core.player.PlotPlayer)1 Plot (com.plotsquared.core.plot.Plot)1 PlotArea (com.plotsquared.core.plot.PlotArea)1 DoneFlag (com.plotsquared.core.plot.flag.implementations.DoneFlag)1 NoWorldeditFlag (com.plotsquared.core.plot.flag.implementations.NoWorldeditFlag)1 WEManager (com.plotsquared.core.util.WEManager)1 BukkitAdapter (com.sk89q.worldedit.bukkit.BukkitAdapter)1 Player (com.sk89q.worldedit.entity.Player)1 LogManagerCompat (com.sk89q.worldedit.internal.util.LogManagerCompat)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Region (com.sk89q.worldedit.regions.Region)1 RegionIntersection (com.sk89q.worldedit.regions.RegionIntersection)1 World (com.sk89q.worldedit.world.World)1