Search in sources :

Example 11 with Subscribe

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

the class PlatformCommandManager method handleCommand.

@Subscribe
public void handleCommand(CommandEvent event) {
    Request.reset();
    Actor actor = event.getActor();
    String args = event.getArguments();
    TaskManager.taskManager().taskNow(() -> {
        if (!Fawe.isMainThread()) {
            Thread.currentThread().setName("FAWE Thread for player: " + actor.getName());
        }
        int space0 = args.indexOf(' ');
        String arg0 = space0 == -1 ? args : args.substring(0, space0);
        Optional<Command> optional = commandManager.getCommand(arg0);
        if (!optional.isPresent()) {
            return;
        }
        Command cmd = optional.get();
        PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null);
        if (queued != null && !queued.isQueued()) {
            handleCommandOnCurrentThread(event);
            return;
        } else {
            actor.decline();
        }
        actor.runAction(() -> {
            SessionKey key = actor.getSessionKey();
            if (key.isActive()) {
                PlatformCommandManager.this.handleCommandOnCurrentThread(event);
            }
        }, false, true);
    }, Fawe.isMainThread());
}
Also used : Command(org.enginehub.piston.Command) PermissionCondition(com.sk89q.worldedit.command.util.PermissionCondition) SubCommandPermissionCondition(com.sk89q.worldedit.command.util.SubCommandPermissionCondition) SessionKey(com.sk89q.worldedit.session.SessionKey) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 12 with Subscribe

use of com.sk89q.worldedit.util.eventbus.Subscribe in project RN-Parkour by xxBennny.

the class SelectionListener method onPaste.

@Subscribe(priority = EventHandler.Priority.VERY_EARLY)
public void onPaste(PasteEvent event) {
    com.sk89q.worldedit.entity.Player wePlayer = event.getPlayer();
    Player player = Bukkit.getPlayer(wePlayer.getName());
    if (player != null && player.getWorld().getName().equalsIgnoreCase(Parkour.getSettingsManager().player_submitted_world)) {
        // if opped and bypassing plots, return
        if (player.isOp() && Parkour.getStatsManager().get(player).isBypassingPlots())
            return;
        try {
            // get session and clipboard holder of session
            LocalSession session = WorldEdit.getInstance().getSessionManager().findByName(player.getName());
            ClipboardHolder holder = session.getClipboard();
            /*
                    this is a complicated part because the location of
                    the min/max of the new paste is not stored, so we have to do hacky math

                    how it is done
                    1) first we get the offset of the clipboard by subtracting the minimum point of the current clipboard
                       by the origin
                    2) we then apply that offset to the holder's transform (rotation, position etc) and add that
                       to the position (gives us the new max)
                    3) finally, we apply the max clipboard point subtracted by the min and then apply that to the transform,
                       and add that to the max point, giving us the min
                 */
            Vector clipboardOffset = event.getClipboard().getMinimumPoint().subtract(event.getClipboard().getOrigin());
            Vector max = event.getPosition().add(holder.getTransform().apply(clipboardOffset));
            Vector min = max.add(holder.getTransform().apply(event.getClipboard().getMaximumPoint().subtract(event.getClipboard().getMinimumPoint())));
            if (checkSelection(min, max, player)) {
                event.setCancelled(true);
                // send bypass info if opped
                String messageToSend = "&cYour paste selection is out of where you can build";
                if (player.isOp())
                    messageToSend += " &7You can bypass this with &c/plot bypass";
                player.sendMessage(Utils.translate(messageToSend));
            }
        } catch (EmptyClipboardException e) {
        // dont print stack track so we dont spam console with simple error
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 13 with Subscribe

use of com.sk89q.worldedit.util.eventbus.Subscribe in project RN-Parkour by xxBennny.

the class SelectionListener method onSelection.

// listen very early to be ahead of normal fawe
@Subscribe(priority = EventHandler.Priority.VERY_EARLY)
public void onSelection(EditSessionEvent event) {
    Actor actor = event.getActor();
    /*
           there are 3 stages, so only listen to before anything happens (avoid 3 event fires),
           make sure the player is the person executing and the world is the plot world
         */
    if (event.getStage().toString().equalsIgnoreCase("BEFORE_CHANGE") && actor != null && actor.isPlayer() && event.getWorld().getName().equalsIgnoreCase(Parkour.getSettingsManager().player_submitted_world)) {
        // get bukkit player from name
        Player player = Bukkit.getPlayer(actor.getName());
        // only continue if not opped
        if (player != null) {
            // if opped and bypassing plots, return
            if (player.isOp() && Parkour.getStatsManager().get(player).isBypassingPlots())
                return;
            // try catch for incomplete regions
            try {
                // get their session, the region from that selection, and the min/max points
                LocalSession session = WorldEdit.getInstance().getSessionManager().findByName(player.getName());
                Region region = session.getSelection(event.getWorld());
                if (checkSelection(region.getMinimumPoint(), region.getMaximumPoint(), player)) {
                    // use FAWE api to cancel and send message
                    event.setCancelled(true);
                    // send bypass info if opped
                    String messageToSend = "&cThis WorldEdit selection is out of where you can build";
                    if (player.isOp())
                        messageToSend += " &7You can bypass this with &c/plot bypass";
                    player.sendMessage(Utils.translate(messageToSend));
                }
            } catch (IncompleteRegionException e) {
            // dont print stack track so we dont spam console with simple error
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Actor(com.sk89q.worldedit.extension.platform.Actor) Region(com.sk89q.worldedit.regions.Region) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 14 with Subscribe

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

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