Search in sources :

Example 6 with Subscribe

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

the class PlatformManager method handleBlockInteract.

@Subscribe
public void handleBlockInteract(BlockInteractEvent event) {
    // Create a proxy actor with a potentially different world for
    // making changes to the world
    Actor actor = createProxyActor(event.getCause());
    Location location = event.getLocation();
    // At this time, only handle interaction from players
    if (!(actor instanceof Player)) {
        return;
    }
    Player player = (Player) actor;
    LocalSession session = worldEdit.getSessionManager().get(actor);
    Request.reset();
    Request.request().setSession(session);
    Request.request().setWorld(player.getWorld());
    try {
        if (event.getType() == Interaction.HIT) {
            // in addition, it is implicitly bound to all pickaxe items, not just a single tool item
            if (session.hasSuperPickAxe() && player.isHoldingPickAxe()) {
                final BlockTool superPickaxe = session.getSuperPickaxe();
                if (superPickaxe != null && superPickaxe.canUse(player)) {
                    // FAWE start - run async
                    player.runAction(() -> reset(superPickaxe).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
                    // FAWE end
                    event.setCancelled(true);
                    return;
                }
            }
            Tool tool = session.getTool(player);
            if (tool instanceof DoubleActionBlockTool && tool.canUse(player)) {
                // FAWE start - run async
                player.runAction(() -> reset((DoubleActionBlockTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
                // FAWE end
                event.setCancelled(true);
            }
        } else if (event.getType() == Interaction.OPEN) {
            // FAWE start - get general tool over item in main hand & run async
            Tool tool = session.getTool(player);
            if (tool instanceof BlockTool && tool.canUse(player)) {
                if (player.checkAction()) {
                    // FAWE run async
                    player.runAction(() -> {
                        BlockTool blockTool = (BlockTool) tool;
                        if (!(tool instanceof BrushTool)) {
                            blockTool = reset(blockTool);
                        }
                        blockTool.actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace());
                    }, false, true);
                    // FAWE end
                    event.setCancelled(true);
                }
            }
        }
    } catch (Throwable e) {
        handleThrowable(e, actor);
    } finally {
        Request.reset();
    }
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Player(com.sk89q.worldedit.entity.Player) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) LocalSession(com.sk89q.worldedit.LocalSession) Location(com.sk89q.worldedit.util.Location) 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 7 with Subscribe

use of com.sk89q.worldedit.util.eventbus.Subscribe in project BuildSystem by einTosti.

the class EditSessionListener method onEditSession.

@Subscribe
public void onEditSession(EditSessionEvent event) {
    Actor actor = event.getActor();
    if (actor == null || !actor.isPlayer()) {
        return;
    }
    Player player = Bukkit.getPlayer(actor.getName());
    if (player == null) {
        return;
    }
    BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
    if (buildWorld == null) {
        return;
    }
    if (event.getStage() == EditSession.Stage.BEFORE_CHANGE) {
        disableArchivedWorlds(buildWorld, player, event);
        checkBuilders(buildWorld, player, event);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) Actor(com.sk89q.worldedit.extension.platform.Actor) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 8 with Subscribe

use of com.sk89q.worldedit.util.eventbus.Subscribe in project ChuoCity by jaoafa.

the class Event_WGNonProtection method onWEEdit.

@Subscribe
public void onWEEdit(EditSessionEvent event) {
    if (Main.getWorldGuard() == null) {
        return;
    }
    if (event.getStage() == EditSession.Stage.BEFORE_REORDER) {
        return;
    }
    Actor actor = event.getActor();
    if (actor == null || !actor.isPlayer()) {
        return;
    }
    Player player = Bukkit.getPlayer(actor.getUniqueId());
    if (player == null) {
        return;
    }
    if (player.hasPermission("worldguard.region.bypass")) {
        return;
    }
    event.setExtent(new AbstractDelegateExtent(event.getExtent()) {

        private boolean canBuild(int x, int y, int z) {
            LocalPlayer localPlayer = Main.getWorldGuard().wrapPlayer(player);
            if (Main.isChuoCity(new Location(player.getWorld(), x, y, z))) {
                return true;
            }
            if (!player.getWorld().getName().equalsIgnoreCase("Jao_Afa")) {
                // Jao_Afa以外では適用しない
                return true;
            }
            ProtectedRegion region = Main.getTopRegion(new Location(player.getWorld(), x, y, z));
            if (region == null) {
                // 誰も保護していない
                return false;
            }
            if (region.isOwner(localPlayer)) {
                // オーナー
                return true;
            }
            // メンバー
            return region.isMember(localPlayer);
        }

        @Override
        public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
            return canBuild(location.getBlockX(), location.getBlockY(), location.getBlockZ()) && super.setBlock(location, block);
        }
    });
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) AbstractDelegateExtent(com.sk89q.worldedit.extent.AbstractDelegateExtent) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Actor(com.sk89q.worldedit.extension.platform.Actor) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) WorldEditException(com.sk89q.worldedit.WorldEditException) Location(org.bukkit.Location) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 9 with Subscribe

use of com.sk89q.worldedit.util.eventbus.Subscribe in project QuickShop-Hikari by Ghost-chu.

the class WorldEditAdapter method proxyEditSession.

@Subscribe(priority = EventHandler.Priority.NORMAL)
public void proxyEditSession(EditSessionEvent event) {
    Actor actor = event.getActor();
    World world = event.getWorld();
    if (actor != null && event.getStage() == EditSession.Stage.BEFORE_CHANGE) {
        event.setExtent(new WorldEditBlockListener(actor, world, event.getExtent(), QuickShop.getInstance()));
    }
}
Also used : Actor(com.sk89q.worldedit.extension.platform.Actor) World(com.sk89q.worldedit.world.World) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 10 with Subscribe

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

the class SessionManager method onConfigurationLoad.

@Subscribe
public void onConfigurationLoad(ConfigurationLoadEvent event) {
    LocalConfiguration config = event.getConfiguration();
    File dir = new File(config.getWorkingDirectoryPath().toFile(), "sessions");
    store = new JsonFileSessionStore(dir);
}
Also used : JsonFileSessionStore(com.sk89q.worldedit.session.storage.JsonFileSessionStore) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) File(java.io.File) 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