Search in sources :

Example 11 with Direction

use of com.sk89q.worldedit.util.Direction 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)

Example 12 with Direction

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

the class HistorySubCommands method summary.

@Command(name = "info", aliases = { "summary", "summarize" }, desc = "Summarize an edit")
@CommandPermissions("worldedit.history.info")
public synchronized void summary(Player player, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index) throws WorldEditException, ExecutionException, InterruptedException {
    RollbackOptimizedHistory edit = database.getEdit(other, index).get();
    if (edit == null) {
        player.print(Caption.of("fawe.worldedit.schematic.schematic.none"));
        return;
    }
    Location origin = player.getLocation();
    String name = Fawe.platform().getName(edit.getUUID());
    String cmd = edit.getCommand();
    BlockVector3 pos1 = edit.getMinimumPoint();
    BlockVector3 pos2 = edit.getMaximumPoint();
    double distanceX = Math.min(Math.abs(pos1.getX() - origin.getX()), Math.abs(pos2.getX() - origin.getX()));
    double distanceZ = Math.min(Math.abs(pos1.getZ() - origin.getZ()), Math.abs(pos2.getZ() - origin.getZ()));
    int distance = (int) Math.sqrt(distanceX * distanceX + distanceZ * distanceZ);
    BlockVector2 dirVec = BlockVector2.at(edit.getOriginX() - origin.getX(), edit.getOriginZ() - origin.getZ());
    Direction direction = Direction.findClosest(dirVec.toVector3(), Direction.Flag.ALL);
    long seconds = (System.currentTimeMillis() - edit.getBDFile().lastModified()) / 1000;
    String timeStr = MainUtil.secToTime(seconds);
    int size = edit.size();
    boolean biomes = edit.getBioFile().exists();
    boolean createdEnts = edit.getEnttFile().exists();
    boolean removedEnts = edit.getEntfFile().exists();
    boolean createdTiles = edit.getNbttFile().exists();
    boolean removedTiles = edit.getNbtfFile().exists();
    TranslatableComponent header = Caption.of("fawe.worldedit.history.find.element", name, timeStr, distance, direction.name(), cmd);
    String sizeStr = StringMan.humanReadableByteCountBin(edit.getSizeOnDisk());
    String extra = "";
    if (biomes) {
        extra += "biomes, ";
    }
    if (createdEnts) {
        extra += "+entity, ";
    }
    if (removedEnts) {
        extra += "-entity, ";
    }
    if (createdTiles) {
        extra += "+tile, ";
    }
    if (removedTiles) {
        extra += "-tile, ";
    }
    TranslatableComponent body = Caption.of("fawe.worldedit.history.find.element.more", size, edit.getMinimumPoint(), edit.getMaximumPoint(), extra.trim(), sizeStr);
    Component distr = TextComponent.of("/history distr").clickEvent(ClickEvent.suggestCommand("//history distr " + other + " " + index));
    TextComponentProducer content = new TextComponentProducer().append(header).newline().append(body).newline().append(distr);
    player.print(content.create());
}
Also used : TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) Direction(com.sk89q.worldedit.util.Direction) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) Component(com.sk89q.worldedit.util.formatting.text.Component) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 13 with Direction

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

the class WorldEdit method getDiagonalDirection.

/**
 * Get the direction vector for a player's direction.
 *
 * @param player the player
 * @param dirStr the direction string
 * @return a direction vector
 * @throws UnknownDirectionException thrown if the direction is not known, or a relative direction is used with null player
 */
public BlockVector3 getDiagonalDirection(@Nullable Player player, String dirStr) throws UnknownDirectionException {
    dirStr = dirStr.toLowerCase(Locale.ROOT);
    final Direction dir = getPlayerDirection(player, dirStr);
    if (dir.isCardinal() || dir.isOrdinal() || dir.isUpright()) {
        return dir.toBlockVector();
    }
    throw new UnknownDirectionException(dir.name());
}
Also used : Direction(com.sk89q.worldedit.util.Direction)

Example 14 with Direction

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

the class Flood method apply.

public void apply(int x, int y, int z, int depth) {
    for (int i = 0, j = 0; i < directions.length && j < maxBranch; i++) {
        final Direction dir = directions[i];
        final int ty = y + dir.getBlockY();
        final int tx = x + dir.getBlockX();
        final int tz = z + dir.getBlockZ();
        int index;
        long[] visit;
        int[] queue;
        final int or = tx | ty | tz;
        if (or > 15 || or < 0) {
            visit = this.visit;
            queue = this.queue;
            index = tx + (tz << 4) + (ty << 8);
        } else {
            int nextX = tx >> 4;
            int nextY = ty >> 4;
            int nextZ = tz >> 4;
            int sectionIndex = nextX + nextZ * 3 + nextZ * 9 + 13;
            visit = visits[sectionIndex];
            queue = queues[sectionIndex];
            if (visit == null || queue == null) {
                long pair = MathMan.pairInt(this.chunkX + nextX, this.chunkZ + nextZ);
                int layer = this.chunkYLayer + nextY;
                if (layer < minSectionPosition || layer > maxSectionPosition) {
                    continue;
                }
                queues[sectionIndex] = queue = getOrCreateQueue(pair, layer);
            }
            index = (tx & 15) + ((tz & 15) << 4) + ((ty & 15) << 8);
        }
        if (!getAndSet(visit, index)) {
            j++;
            push(queue, index + (depth << 12));
        }
    }
}
Also used : Direction(com.sk89q.worldedit.util.Direction)

Example 15 with Direction

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

the class Pre13HangingCompatibilityHandler method updateNBT.

@Override
public CompoundTag updateNBT(EntityType type, CompoundTag tag) {
    boolean hasLegacyDir = tag.containsKey("Dir");
    boolean hasLegacyDirection = tag.containsKey("Direction");
    boolean hasPre113Facing = tag.containsKey("Facing");
    Direction newDirection;
    if (hasLegacyDir) {
        newDirection = MCDirections.fromPre13Hanging(MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")));
    } else if (hasLegacyDirection) {
        newDirection = MCDirections.fromPre13Hanging(tag.asInt("Direction"));
    } else if (hasPre113Facing) {
        newDirection = MCDirections.fromPre13Hanging(tag.asInt("Facing"));
    } else {
        return tag;
    }
    byte hangingByte = (byte) MCDirections.toHanging(newDirection);
    CompoundTagBuilder builder = tag.createBuilder();
    builder.putByte("Facing", hangingByte);
    return builder.build();
}
Also used : Direction(com.sk89q.worldedit.util.Direction) CompoundTagBuilder(com.sk89q.jnbt.CompoundTagBuilder)

Aggregations

Direction (com.sk89q.worldedit.util.Direction)19 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 Tag (com.sk89q.jnbt.Tag)5 DirectionalProperty (com.sk89q.worldedit.registry.state.DirectionalProperty)5 BlockState (com.sk89q.worldedit.world.block.BlockState)5 BlockType (com.sk89q.worldedit.world.block.BlockType)5 Map (java.util.Map)5 Vector3 (com.sk89q.worldedit.math.Vector3)4 BooleanProperty (com.sk89q.worldedit.registry.state.BooleanProperty)4 EnumProperty (com.sk89q.worldedit.registry.state.EnumProperty)4 IntegerProperty (com.sk89q.worldedit.registry.state.IntegerProperty)4 Property (com.sk89q.worldedit.registry.state.Property)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 CompoundTag (com.sk89q.jnbt.CompoundTag)3 CompoundTagBuilder (com.sk89q.jnbt.CompoundTagBuilder)3 Location (com.sk89q.worldedit.util.Location)3 List (java.util.List)3 PropertyKey (com.fastasyncworldedit.core.registry.state.PropertyKey)2 ByteTag (com.sk89q.jnbt.ByteTag)2