Search in sources :

Example 1 with Subscribe

use of com.sk89q.worldedit.util.eventbus.Subscribe in project Prism-Bukkit by prism.

the class PrismBlockEditHandler method wrapForLogging.

/**
 * Wrap and edit session so it can be logged.
 *
 * @param event EditSessionEvent
 */
@Subscribe
public void wrapForLogging(EditSessionEvent event) {
    if (event.getStage().equals(EditSession.Stage.BEFORE_CHANGE)) {
        Actor actor = event.getActor();
        org.bukkit.World world = Bukkit.getWorld(event.getWorld().getName());
        if (actor != null && actor.isPlayer() && world != null) {
            event.setExtent(new PrismWorldEditLogger(actor, event.getExtent(), world));
        }
    }
}
Also used : Actor(com.sk89q.worldedit.extension.platform.Actor) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 2 with Subscribe

use of com.sk89q.worldedit.util.eventbus.Subscribe in project CoreProtect by PlayPro.

the class CoreProtectEditSessionEvent method wrapForLogging.

@Subscribe
public void wrapForLogging(EditSessionEvent event) {
    Actor actor = event.getActor();
    World world = event.getWorld();
    if (actor != null && event.getStage() == (isFAWE ? Stage.BEFORE_HISTORY : Stage.BEFORE_CHANGE)) {
        event.setExtent(new CoreProtectLogger(actor, world, event.getExtent()));
    }
}
Also used : Actor(com.sk89q.worldedit.extension.platform.Actor) World(com.sk89q.worldedit.world.World) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 3 with Subscribe

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

the class SessionManager method onSessionIdle.

@Subscribe
public void onSessionIdle(final SessionIdleEvent event) {
    SessionHolder holder = this.sessions.get(getKey(event.getKey()));
    if (holder != null && !holder.sessionIdle) {
        holder.sessionIdle = true;
        LocalSession session = holder.session;
        // Perform any session cleanup for data that should not be persisted.
        session.onIdle();
    }
}
Also used : LocalSession(com.sk89q.worldedit.LocalSession) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 4 with Subscribe

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

the class PlatformCommandManager method handleCommandSuggestion.

@Subscribe
public void handleCommandSuggestion(CommandSuggestionEvent event) {
    try {
        String rawArgs = event.getArguments();
        // FAWE start
        // Increase the resulting positions by 1 if we remove a leading `/`
        final int posOffset = rawArgs.startsWith("/") ? 1 : 0;
        String arguments = rawArgs.startsWith("/") ? rawArgs.substring(1) : rawArgs;
        // FAWE end
        List<Substring> split = parseArgs(arguments).collect(Collectors.toList());
        List<String> argStrings = split.stream().map(Substring::getSubstring).collect(Collectors.toList());
        // FAWE start - event & suggestion
        MemoizingValueAccess access = initializeInjectedValues(() -> arguments, event.getActor(), event, true);
        // FAWE end
        ImmutableSet<Suggestion> suggestions;
        try {
            suggestions = commandManager.getSuggestions(access, argStrings);
        } catch (Throwable t) {
            // catch errors which are *not* command exceptions generated by parsers/suggesters
            if (!(t instanceof InputParseException) && !(t instanceof CommandException)) {
                Throwable cause = t;
                // These exceptions can be very nested, and should not be printed as they are not an actual error.
                boolean printError = true;
                while ((cause = cause.getCause()) != null) {
                    if (cause instanceof InputParseException || cause instanceof CommandException) {
                        printError = false;
                        break;
                    }
                }
                if (printError) {
                    LOGGER.error("Unexpected error occurred while generating suggestions for input: {}", arguments, t);
                    return;
                }
            }
            return;
        }
        event.setSuggestions(suggestions.stream().map(suggestion -> {
            int noSlashLength = arguments.length();
            Substring original = suggestion.getReplacedArgument() == split.size() ? Substring.from(arguments, noSlashLength, noSlashLength) : split.get(suggestion.getReplacedArgument());
            return Substring.wrap(suggestion.getSuggestion(), original.getStart() + posOffset, original.getEnd() + posOffset);
        }).collect(Collectors.toList()));
    } catch (ConditionFailedException e) {
        if (e.getCondition() instanceof PermissionCondition) {
            event.setSuggestions(new ArrayList<>());
        }
    }
}
Also used : Substring(com.sk89q.worldedit.internal.util.Substring) MemoizingValueAccess(org.enginehub.piston.inject.MemoizingValueAccess) ArrayList(java.util.ArrayList) CommandException(org.enginehub.piston.exception.CommandException) Suggestion(org.enginehub.piston.suggestion.Suggestion) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) ConditionFailedException(org.enginehub.piston.exception.ConditionFailedException) PermissionCondition(com.sk89q.worldedit.command.util.PermissionCondition) SubCommandPermissionCondition(com.sk89q.worldedit.command.util.SubCommandPermissionCondition) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 5 with Subscribe

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

Aggregations

Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)14 Actor (com.sk89q.worldedit.extension.platform.Actor)6 Player (org.bukkit.entity.Player)4 LocalSession (com.sk89q.worldedit.LocalSession)3 WorldEditException (com.sk89q.worldedit.WorldEditException)2 BlockTool (com.sk89q.worldedit.command.tool.BlockTool)2 BrushTool (com.sk89q.worldedit.command.tool.BrushTool)2 DoubleActionBlockTool (com.sk89q.worldedit.command.tool.DoubleActionBlockTool)2 DoubleActionTraceTool (com.sk89q.worldedit.command.tool.DoubleActionTraceTool)2 Tool (com.sk89q.worldedit.command.tool.Tool)2 TraceTool (com.sk89q.worldedit.command.tool.TraceTool)2 PermissionCondition (com.sk89q.worldedit.command.util.PermissionCondition)2 SubCommandPermissionCondition (com.sk89q.worldedit.command.util.SubCommandPermissionCondition)2 Player (com.sk89q.worldedit.entity.Player)2 AbstractDelegateExtent (com.sk89q.worldedit.extent.AbstractDelegateExtent)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 World (com.sk89q.worldedit.world.World)2 Location (org.bukkit.Location)2 BuildWorld (com.eintosti.buildsystem.object.world.BuildWorld)1 FaweException (com.fastasyncworldedit.core.internal.exception.FaweException)1