Search in sources :

Example 1 with NullExtent

use of com.sk89q.worldedit.extent.NullExtent in project PlotSquared by IntellectualSites.

the class WESubscriber method onEditSession.

@Subscribe(priority = Priority.VERY_EARLY)
public void onEditSession(EditSessionEvent event) {
    if (!Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
        WorldEdit.getInstance().getEventBus().unregister(this);
        return;
    }
    if (event.getStage() != EditSession.Stage.BEFORE_HISTORY) {
        return;
    }
    World worldObj = event.getWorld();
    if (worldObj == null) {
        return;
    }
    String world = worldObj.getName();
    Actor actor = event.getActor();
    if (actor != null && actor.isPlayer()) {
        String name = actor.getName();
        final PlotPlayer<?> plotPlayer = PlotSquared.platform().playerManager().getPlayerIfExists(name);
        Set<CuboidRegion> mask;
        if (plotPlayer == null) {
            Player player = (Player) actor;
            Location location = player.getLocation();
            com.plotsquared.core.location.Location pLoc = com.plotsquared.core.location.Location.at(player.getWorld().getName(), location.toVector().toBlockPoint());
            Plot plot = pLoc.getPlot();
            if (plot == null) {
                event.setExtent(new NullExtent());
                return;
            }
            mask = plot.getRegions();
        } else if (plotPlayer.getAttribute("worldedit")) {
            return;
        } else {
            mask = WEManager.getMask(plotPlayer);
            if (mask.isEmpty()) {
                if (Permissions.hasPermission(plotPlayer, "plots.worldedit.bypass")) {
                    plotPlayer.sendMessage(TranslatableCaption.of("worldedit.worldedit_bypass"), Template.of("command", "/plot toggle worldedit"));
                }
                if (this.plotAreaManager.hasPlotArea(world)) {
                    event.setExtent(new NullExtent());
                }
                return;
            }
        }
        if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
            if (this.plotAreaManager.hasPlotArea(world)) {
                event.setExtent(new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(), event.getExtent(), this.worldUtil));
            }
        } else if (this.plotAreaManager.hasPlotArea(world)) {
            event.setExtent(new WEExtent(mask, event.getExtent()));
        }
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) PlotPlayer(com.plotsquared.core.player.PlotPlayer) Plot(com.plotsquared.core.plot.Plot) NullExtent(com.sk89q.worldedit.extent.NullExtent) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) World(com.sk89q.worldedit.world.World) Actor(com.sk89q.worldedit.extension.platform.Actor) Location(com.sk89q.worldedit.util.Location) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 2 with NullExtent

use of com.sk89q.worldedit.extent.NullExtent in project FastAsyncWorldEdit by IntellectualSites.

the class LocalConfiguration method checkDisallowedBlocks.

public boolean checkDisallowedBlocks(BlockStateHolder holder) {
    if (disallowedBlocks.isEmpty()) {
        return false;
    }
    if (disallowedBlocksMask == null) {
        BlockMaskBuilder builder = new BlockMaskBuilder();
        for (String blockRegex : disallowedBlocks) {
            try {
                builder.addRegex(blockRegex);
            } catch (InputParseException e) {
                e.printStackTrace();
            }
        }
        disallowedBlocksMask = builder.build(new NullExtent());
    }
    return disallowedBlocksMask.test(holder.toImmutableState());
}
Also used : InputParseException(com.sk89q.worldedit.extension.input.InputParseException) BlockMaskBuilder(com.fastasyncworldedit.core.function.mask.BlockMaskBuilder) NullExtent(com.sk89q.worldedit.extent.NullExtent)

Example 3 with NullExtent

use of com.sk89q.worldedit.extent.NullExtent in project PlotSquared by IntellectualSites.

the class ProcessedWEExtent method setBlock.

@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
    final boolean isTile = this.worldUtil.getTileEntityTypes().contains(block.getBlockType());
    if (isTile) {
        final Integer[] tileEntityCount = this.tileEntityCount.computeIfAbsent(getChunkKey(location), key -> new Integer[] { this.worldUtil.getTileEntityCount(world, BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4)) });
        if (tileEntityCount[0] >= Settings.Chunk_Processor.MAX_TILES) {
            return false;
        } else {
            tileEntityCount[0]++;
        }
    }
    if (WEManager.maskContains(this.mask, location.getX(), location.getY(), location.getZ())) {
        if (this.count++ > this.max) {
            if (this.parent != null) {
                try {
                    Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
                    field.setAccessible(true);
                    field.set(this.parent, new NullExtent());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                this.parent = null;
            }
            return false;
        }
        return super.setBlock(location, block);
    }
    return !isTile;
}
Also used : Field(java.lang.reflect.Field) NullExtent(com.sk89q.worldedit.extent.NullExtent) WorldEditException(com.sk89q.worldedit.WorldEditException)

Aggregations

NullExtent (com.sk89q.worldedit.extent.NullExtent)3 BlockMaskBuilder (com.fastasyncworldedit.core.function.mask.BlockMaskBuilder)1 PlotPlayer (com.plotsquared.core.player.PlotPlayer)1 Plot (com.plotsquared.core.plot.Plot)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 Player (com.sk89q.worldedit.entity.Player)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 Actor (com.sk89q.worldedit.extension.platform.Actor)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Location (com.sk89q.worldedit.util.Location)1 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)1 World (com.sk89q.worldedit.world.World)1 Field (java.lang.reflect.Field)1