Search in sources :

Example 6 with BlockStateHolder

use of com.sk89q.worldedit.world.block.BlockStateHolder in project buildinggame by stefvanschie.

the class WorldEditBoundaryAssertion method onEditSession.

/**
 * Cancels any edits being made for blocks outside the plot the actor is (possibly) on.
 *
 * @param event the event fired when a session is being edited
 * @since 5.8.0
 */
@Subscribe
public void onEditSession(EditSessionEvent event) {
    if (event.getActor() == null || !event.getActor().isPlayer())
        return;
    var player = Bukkit.getPlayer(event.getActor().getUniqueId());
    var arena = ArenaManager.getInstance().getArena(player);
    // don't do anything if the player isn't in an arena
    if (arena == null)
        return;
    event.setExtent(new AbstractDelegateExtent(event.getExtent()) {

        @Override
        public boolean setBlock(BlockVector3 vector, BlockStateHolder block) throws WorldEditException {
            var world = Bukkit.getWorld(event.getWorld().getName());
            var loc = new Location(world, vector.getX(), vector.getY(), vector.getZ());
            if (!arena.getPlot(player).getBoundary().isInside(loc)) {
                return false;
            }
            return super.setBlock(vector, block);
        }
    });
}
Also used : AbstractDelegateExtent(com.sk89q.worldedit.extent.AbstractDelegateExtent) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldEditException(com.sk89q.worldedit.WorldEditException) Location(org.bukkit.Location) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Aggregations

BlockStateHolder (com.sk89q.worldedit.world.block.BlockStateHolder)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 BlobBrush (com.fastasyncworldedit.core.command.tool.brush.BlobBrush)1 CatenaryBrush (com.fastasyncworldedit.core.command.tool.brush.CatenaryBrush)1 CircleBrush (com.fastasyncworldedit.core.command.tool.brush.CircleBrush)1 CommandBrush (com.fastasyncworldedit.core.command.tool.brush.CommandBrush)1 CopyPastaBrush (com.fastasyncworldedit.core.command.tool.brush.CopyPastaBrush)1 ErodeBrush (com.fastasyncworldedit.core.command.tool.brush.ErodeBrush)1 FallingSphere (com.fastasyncworldedit.core.command.tool.brush.FallingSphere)1 FlattenBrush (com.fastasyncworldedit.core.command.tool.brush.FlattenBrush)1 HeightBrush (com.fastasyncworldedit.core.command.tool.brush.HeightBrush)1 ImageBrush (com.fastasyncworldedit.core.command.tool.brush.ImageBrush)1 LayerBrush (com.fastasyncworldedit.core.command.tool.brush.LayerBrush)1 LineBrush (com.fastasyncworldedit.core.command.tool.brush.LineBrush)1 RaiseBrush (com.fastasyncworldedit.core.command.tool.brush.RaiseBrush)1 RecurseBrush (com.fastasyncworldedit.core.command.tool.brush.RecurseBrush)1 ScatterBrush (com.fastasyncworldedit.core.command.tool.brush.ScatterBrush)1 ScatterCommand (com.fastasyncworldedit.core.command.tool.brush.ScatterCommand)1 ScatterOverlayBrush (com.fastasyncworldedit.core.command.tool.brush.ScatterOverlayBrush)1