Search in sources :

Example 51 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class BrushTool method act.

public boolean act(BrushAction action, Player player, LocalSession session) {
    switch(action) {
        case PRIMARY:
            setContext(primary);
            break;
        case SECONDARY:
            setContext(secondary);
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + action);
    }
    BrushSettings current = getContext();
    Brush brush = current.getBrush();
    if (brush == null) {
        return false;
    }
    if (!current.canUse(player)) {
        player.print(Caption.of("fawe.error.no-perm", StringMan.join(current.getPermissions(), ",")));
        return false;
    }
    try (EditSession editSession = session.createEditSession(player, current.toString())) {
        Location target = player.getBlockTrace(getRange(), true, traceMask);
        if (target == null) {
            editSession.cancel();
            player.print(Caption.of("worldedit.tool.no-block"));
            return true;
        }
        BlockBag bag = session.getBlockBag(player);
        Request.request().setEditSession(editSession);
        Mask mask = current.getMask();
        if (mask != null) {
            Mask existingMask = editSession.getMask();
            if (existingMask == null) {
                editSession.setMask(mask);
            } else if (existingMask instanceof MaskIntersection) {
                ((MaskIntersection) existingMask).add(mask);
            } else {
                MaskIntersection newMask = new MaskIntersection(existingMask);
                newMask.add(mask);
                editSession.setMask(newMask);
            }
        }
        Mask sourceMask = current.getSourceMask();
        if (sourceMask != null) {
            editSession.addSourceMask(sourceMask);
        }
        ResettableExtent transform = current.getTransform();
        if (transform != null) {
            editSession.addTransform(transform);
        }
        try {
            new PatternTraverser(current).reset(editSession);
            double size = current.getSize();
            WorldEdit.getInstance().checkMaxBrushRadius(size);
            brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size);
        } catch (MaxChangedBlocksException e) {
            player.print(Caption.of("worldedit.tool.max-block-changes"));
        } finally {
            session.remember(editSession);
            if (bag != null) {
                bag.flushChanges();
            }
        }
    } finally {
        Request.reset();
    }
    return true;
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) Mask(com.sk89q.worldedit.function.mask.Mask) PatternTraverser(com.fastasyncworldedit.core.function.pattern.PatternTraverser) EditSession(com.sk89q.worldedit.EditSession) BrushSettings(com.fastasyncworldedit.core.command.tool.brush.BrushSettings) Brush(com.sk89q.worldedit.command.tool.brush.Brush) ResettableExtent(com.fastasyncworldedit.core.extent.ResettableExtent) Location(com.sk89q.worldedit.util.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 52 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class DistanceWand method actSecondary.

@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
    Location target = getTarget(player);
    if (target == null) {
        return true;
    }
    RegionSelector selector = session.getRegionSelector(player.getWorld());
    BlockVector3 blockPoint = target.toVector().toBlockPoint();
    if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
        selector.explainPrimarySelection(player, session, blockPoint);
    }
    return true;
}
Also used : RegionSelector(com.sk89q.worldedit.regions.RegionSelector) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.sk89q.worldedit.util.Location)

Example 53 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class LocationConverter method convert.

@Override
public ConversionResult<Location> convert(String s, InjectedValueAccess injectedValueAccess) {
    String[] split4 = s.split(",", 4);
    if (split4.length != 4) {
        return FailedConversion.from(new IllegalArgumentException("Must have exactly 1 world and 3 vector components"));
    }
    String[] split2 = s.split(",", 2);
    ConversionResult<World> world = worldConverter.convert(split2[0], injectedValueAccess);
    if (!world.isSuccessful()) {
        return (FailedConversion) world;
    }
    ConversionResult<BlockVector3> vector = vectorConverter.convert(split2[1], injectedValueAccess);
    if (!vector.isSuccessful()) {
        return (FailedConversion) vector;
    }
    Location location = new Location(world.get().iterator().next(), vector.get().iterator().next().toVector3());
    return SuccessfulConversion.fromSingle(location);
}
Also used : FailedConversion(org.enginehub.piston.converter.FailedConversion) World(com.sk89q.worldedit.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.sk89q.worldedit.util.Location)

Example 54 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class SmoothBrush method build.

@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
    Vector3 posDouble = position.toVector3();
    Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size));
    BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint();
    Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max);
    HeightMap heightMap = new HeightMap(editSession, region, mask);
    HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
    heightMap.applyFilter(filter, iterations);
}
Also used : HeightMapFilter(com.sk89q.worldedit.math.convolution.HeightMapFilter) HeightMap(com.sk89q.worldedit.math.convolution.HeightMap) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) GaussianKernel(com.sk89q.worldedit.math.convolution.GaussianKernel) Location(com.sk89q.worldedit.util.Location)

Example 55 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class WorldEditListener method onPlayerInteract.

/**
 * Called when a player interacts.
 *
 * @param event Relevant event details
 */
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!plugin.getInternalPlatform().isHookingEvents()) {
        return;
    }
    if (event.useItemInHand() == Result.DENY) {
        return;
    }
    if (event.getHand() == EquipmentSlot.OFF_HAND) {
        return;
    }
    final Player player = plugin.wrapPlayer(event.getPlayer());
    final World world = player.getWorld();
    final WorldEdit we = plugin.getWorldEdit();
    final Direction direction = BukkitAdapter.adapt(event.getBlockFace());
    Action action = event.getAction();
    if (action == Action.LEFT_CLICK_BLOCK) {
        final Block clickedBlock = event.getClickedBlock();
        final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
        if (we.handleBlockLeftClick(player, pos, direction)) {
            event.setCancelled(true);
        }
        if (we.handleArmSwing(player)) {
            event.setCancelled(true);
        }
    } else if (action == Action.LEFT_CLICK_AIR) {
        if (we.handleArmSwing(player)) {
            event.setCancelled(true);
        }
    } else if (action == Action.RIGHT_CLICK_BLOCK) {
        final Block clickedBlock = event.getClickedBlock();
        final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
        if (we.handleBlockRightClick(player, pos, direction)) {
            event.setCancelled(true);
        }
        if (we.handleRightClick(player)) {
            event.setCancelled(true);
        }
    } else if (action == Action.RIGHT_CLICK_AIR) {
        if (we.handleRightClick(player)) {
            event.setCancelled(true);
        }
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) Action(org.bukkit.event.block.Action) WorldEdit(com.sk89q.worldedit.WorldEdit) Block(org.bukkit.block.Block) World(com.sk89q.worldedit.world.World) Direction(com.sk89q.worldedit.util.Direction) Location(com.sk89q.worldedit.util.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Location (com.sk89q.worldedit.util.Location)75 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)26 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)12 World (com.sk89q.worldedit.world.World)12 CompoundTag (com.sk89q.jnbt.CompoundTag)11 Region (com.sk89q.worldedit.regions.Region)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)9 Command (org.enginehub.piston.annotation.Command)9 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)8 Tag (com.sk89q.jnbt.Tag)8 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)8 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)8 List (java.util.List)8 ListTag (com.sk89q.jnbt.ListTag)7 Player (com.sk89q.worldedit.entity.Player)7 Vector3 (com.sk89q.worldedit.math.Vector3)7 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)7 LocalPlayer (com.sk89q.worldguard.LocalPlayer)7 StringTag (com.sk89q.jnbt.StringTag)6 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)6