Search in sources :

Example 1 with FaweException

use of com.fastasyncworldedit.core.internal.exception.FaweException in project FastAsyncWorldEdit by IntellectualSites.

the class PlatformManager method handlePlayerInput.

// FAWE end
@Subscribe
public void handlePlayerInput(PlayerInputEvent event) {
    // Create a proxy actor with a potentially different world for
    // making changes to the world
    Player player = createProxyActor(event.getPlayer());
    LocalSession session = worldEdit.getSessionManager().get(player);
    try {
        switch(event.getInputType()) {
            case PRIMARY:
                {
                    Tool tool = session.getTool(player);
                    if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) {
                        // FAWE start - run async
                        player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session));
                        // FAWE end
                        event.setCancelled(true);
                        return;
                    }
                    break;
                }
            case SECONDARY:
                {
                    Tool tool = session.getTool(player);
                    if (tool instanceof TraceTool && tool.canUse(player)) {
                        // FAWE start - run async
                        // todo this needs to be fixed so the event is canceled after actPrimary is used and returns true
                        player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session), false, true);
                        // FAWE end
                        event.setCancelled(true);
                        return;
                    }
                    break;
                }
        }
    // FAWE start - add own message
    } catch (Throwable e) {
        FaweException faweException = FaweException.get(e);
        if (faweException != null) {
            player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
        } else {
            player.print(Caption.of("worldedit.command.error.report"));
            player.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
            e.printStackTrace();
        }
    // FAWE end
    } finally {
        Request.reset();
    }
}
Also used : TraceTool(com.sk89q.worldedit.command.tool.TraceTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) Player(com.sk89q.worldedit.entity.Player) LocalSession(com.sk89q.worldedit.LocalSession) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) TraceTool(com.sk89q.worldedit.command.tool.TraceTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Tool(com.sk89q.worldedit.command.tool.Tool) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 2 with FaweException

use of com.fastasyncworldedit.core.internal.exception.FaweException in project FastAsyncWorldEdit by IntellectualSites.

the class LimitExtent method apply.

@Override
public <T extends Filter> T apply(Iterable<BlockVector3> positions, T filter) {
    int size;
    if (positions instanceof Collection) {
        size = ((Collection<BlockVector3>) positions).size();
    } else if (positions instanceof Region) {
        BlockVector3 dim = ((Region) positions).getDimensions();
        size = dim.getX() * dim.getY() * dim.getZ();
    } else if (positions instanceof Extent) {
        BlockVector3 min = ((Extent) positions).getMinimumPoint();
        BlockVector3 max = ((Extent) positions).getMinimumPoint();
        BlockVector3 dim = max.subtract(min).add(BlockVector3.ONE);
        size = dim.getX() * dim.getY() * dim.getZ();
    } else {
        ExtentFilterBlock block = new ExtentFilterBlock(this);
        for (BlockVector3 pos : positions) {
            limit.THROW_MAX_CHECKS();
            try {
                filter.applyBlock(block.init(pos));
            } catch (FaweException e) {
                if (!limit.MAX_FAILS()) {
                    throw e;
                }
            }
        }
        return filter;
    }
    limit.THROW_MAX_CHECKS(size);
    limit.THROW_MAX_CHANGES(size);
    return super.apply(positions, filter);
}
Also used : AbstractDelegateExtent(com.sk89q.worldedit.extent.AbstractDelegateExtent) Extent(com.sk89q.worldedit.extent.Extent) ExtentFilterBlock(com.fastasyncworldedit.core.extent.filter.block.ExtentFilterBlock) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) Collection(java.util.Collection) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 3 with FaweException

use of com.fastasyncworldedit.core.internal.exception.FaweException in project FastAsyncWorldEdit by IntellectualSites.

the class PlatformCommandManager method handleCommandTask.

public void handleCommandTask(ThrowableSupplier<Throwable> task, InjectedValueAccess context, @Nullable LocalSession session, CommandEvent event) {
    Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("No player"));
    long start = System.currentTimeMillis();
    try {
        // exceptions and rethrow their converted form, if their is one.
        try {
            Object result = task.get();
        } catch (Throwable t) {
            // Use the exception converter to convert the exception if any of its causes
            // can be converted, otherwise throw the original exception
            Throwable next = t;
            do {
                exceptionConverter.convert(next);
                next = next.getCause();
            } while (next != null);
            throw t;
        }
    } catch (ConditionFailedException e) {
        if (e.getCondition() instanceof PermissionCondition) {
            actor.print(Caption.of("fawe.error.no-perm", StringMan.getString(((PermissionCondition) e.getCondition()).getPermissions())));
        } else {
            actor.print(e.getRichMessage());
        }
    } catch (FaweException e) {
        actor.print(Caption.of("fawe.cancel.reason", e.getComponent()));
    } catch (UsageException e) {
        actor.printError(e.getRichMessage());
    } catch (CommandExecutionException e) {
        handleUnknownException(actor, e.getCause());
    } catch (CommandException e) {
        if (e.getCause() instanceof FaweException) {
            actor.print(Caption.of("fawe.cancel.reason", ((FaweException) e.getCause()).getComponent()));
        } else {
            Component msg = e.getRichMessage();
            if (msg == TextComponent.empty()) {
                List<String> argList = parseArgs(event.getArguments()).map(Substring::getSubstring).collect(Collectors.toList());
                printUsage(actor, argList);
            } else {
                actor.printError(msg);
            }
        }
    } catch (Throwable t) {
        handleUnknownException(actor, t);
    } finally {
        if (context instanceof MemoizingValueAccess) {
            context = ((MemoizingValueAccess) context).snapshotMemory();
        }
        Optional<EditSession> editSessionOpt = context.injectedValue(Key.of(EditSession.class));
        // Require null CommandEvent#getSession as it means the editsession is being handled somewhere else.
        if (editSessionOpt.isPresent() && event.getSession() == null) {
            EditSession editSession = editSessionOpt.get();
            editSession.close();
            session.remember(editSession);
            long time = System.currentTimeMillis() - start;
            double timeS = (time / 1000.0);
            int changed = editSession.getBlockChangeCount();
            double throughput = timeS == 0 ? changed : changed / timeS;
            if (time > 1000) {
                actor.print(Caption.of("worldedit.command.time-elapsed", TextComponent.of(timeS), TextComponent.of(changed), TextComponent.of(Math.round(throughput))));
            }
            worldEdit.flushBlockBag(actor, editSession);
        }
        // TODO: Ping @MattBDev to reimplement 2020-02-04
        // CFICommands.CFISettings cfi = actor.getMeta("CFISettings");
        // if (cfi != null) {
        // HeightMapMCAGenerator gen = cfi.getGenerator();
        // if (gen != null && gen.isModified()) {
        // try {
        // gen.update();
        // CFIChangeSet set = new CFIChangeSet(gen, actor.getUniqueId());
        // session.remember(actor, gen, set, actor.getLimit());
        // } catch (IOException e) {
        // e.printStackTrace();
        // }
        // }
        // }
        Request.reset();
    }
    event.setCancelled(true);
}
Also used : Substring(com.sk89q.worldedit.internal.util.Substring) UsageException(org.enginehub.piston.exception.UsageException) MemoizingValueAccess(org.enginehub.piston.inject.MemoizingValueAccess) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) CommandException(org.enginehub.piston.exception.CommandException) ConditionFailedException(org.enginehub.piston.exception.ConditionFailedException) PermissionCondition(com.sk89q.worldedit.command.util.PermissionCondition) SubCommandPermissionCondition(com.sk89q.worldedit.command.util.SubCommandPermissionCondition) CommandExecutionException(org.enginehub.piston.exception.CommandExecutionException) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) EditSession(com.sk89q.worldedit.EditSession) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent)

Example 4 with FaweException

use of com.fastasyncworldedit.core.internal.exception.FaweException in project FastAsyncWorldEdit by IntellectualSites.

the class AbstractDelegateExtent method disableQueue.

@Override
public void disableQueue() {
    try {
        if (!(extent instanceof ForgetfulExtentBuffer)) {
            // placeholder
            extent.disableQueue();
        }
    } catch (FaweException ignored) {
    }
    if (extent instanceof AbstractDelegateExtent) {
        Extent next = ((AbstractDelegateExtent) extent).getExtent();
        new ExtentTraverser(this).setNext(next);
    } else {
        LOGGER.error("Cannot disable queue");
    }
}
Also used : ForgetfulExtentBuffer(com.sk89q.worldedit.extent.buffer.ForgetfulExtentBuffer) ExtentTraverser(com.fastasyncworldedit.core.util.ExtentTraverser) HistoryExtent(com.fastasyncworldedit.core.extent.HistoryExtent) NullExtent(com.fastasyncworldedit.core.extent.NullExtent) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException)

Example 5 with FaweException

use of com.fastasyncworldedit.core.internal.exception.FaweException in project FastAsyncWorldEdit by IntellectualSites.

the class PlatformManager method handleThrowable.

// FAWE start
public void handleThrowable(Throwable e, Actor actor) {
    FaweException faweException = FaweException.get(e);
    if (faweException != null) {
        actor.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
    } else {
        actor.print(Caption.of("worldedit.command.error.report"));
        actor.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
        e.printStackTrace();
    }
}
Also used : FaweException(com.fastasyncworldedit.core.internal.exception.FaweException)

Aggregations

FaweException (com.fastasyncworldedit.core.internal.exception.FaweException)9 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 NullExtent (com.fastasyncworldedit.core.extent.NullExtent)2 Region (com.sk89q.worldedit.regions.Region)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 Fawe (com.fastasyncworldedit.core.Fawe)1 FaweCache (com.fastasyncworldedit.core.FaweCache)1 Settings (com.fastasyncworldedit.core.configuration.Settings)1 HistoryExtent (com.fastasyncworldedit.core.extent.HistoryExtent)1 PassthroughExtent (com.fastasyncworldedit.core.extent.PassthroughExtent)1 WorldCopyClipboard (com.fastasyncworldedit.core.extent.clipboard.WorldCopyClipboard)1 CountFilter (com.fastasyncworldedit.core.extent.filter.CountFilter)1 DistrFilter (com.fastasyncworldedit.core.extent.filter.DistrFilter)1 LinkedFilter (com.fastasyncworldedit.core.extent.filter.LinkedFilter)1 ChunkFilterBlock (com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock)1 ExtentFilterBlock (com.fastasyncworldedit.core.extent.filter.block.ExtentFilterBlock)1 BatchProcessorHolder (com.fastasyncworldedit.core.extent.processor.BatchProcessorHolder)1 MultiBatchProcessor (com.fastasyncworldedit.core.extent.processor.MultiBatchProcessor)1