Search in sources :

Example 1 with AbstractDelegateExtent

use of com.sk89q.worldedit.extent.AbstractDelegateExtent in project FastAsyncWorldEdit by IntellectualSites.

the class WEManager method cancelEditSafe.

public void cancelEditSafe(AbstractDelegateExtent parent, FaweException reason) throws FaweException {
    LOGGER.warn("CancelEditSafe was hit. Please ignore this message.");
    Extent currentExtent = parent.getExtent();
    if (!(currentExtent instanceof NullExtent)) {
        parent.extent = new NullExtent(parent.extent, reason);
    }
    throw reason;
}
Also used : NullExtent(com.fastasyncworldedit.core.extent.NullExtent) AbstractDelegateExtent(com.sk89q.worldedit.extent.AbstractDelegateExtent) Extent(com.sk89q.worldedit.extent.Extent) NullExtent(com.fastasyncworldedit.core.extent.NullExtent)

Example 2 with AbstractDelegateExtent

use of com.sk89q.worldedit.extent.AbstractDelegateExtent 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 3 with AbstractDelegateExtent

use of com.sk89q.worldedit.extent.AbstractDelegateExtent in project FastAsyncWorldEdit by IntellectualSites.

the class ExtentTraverser method next.

@SuppressWarnings("unchecked")
public ExtentTraverser<T> next() {
    try {
        if (root instanceof AbstractDelegateExtent) {
            AbstractDelegateExtent root = (AbstractDelegateExtent) this.root;
            T value = (T) root.getExtent();
            if (value == null) {
                return null;
            }
            return new ExtentTraverser<>(value, this);
        }
        return null;
    } catch (Throwable e) {
        e.printStackTrace();
        return null;
    }
}
Also used : AbstractDelegateExtent(com.sk89q.worldedit.extent.AbstractDelegateExtent)

Example 4 with AbstractDelegateExtent

use of com.sk89q.worldedit.extent.AbstractDelegateExtent 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

AbstractDelegateExtent (com.sk89q.worldedit.extent.AbstractDelegateExtent)4 WorldEditException (com.sk89q.worldedit.WorldEditException)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)2 Location (org.bukkit.Location)2 NullExtent (com.fastasyncworldedit.core.extent.NullExtent)1 Actor (com.sk89q.worldedit.extension.platform.Actor)1 Extent (com.sk89q.worldedit.extent.Extent)1 BlockStateHolder (com.sk89q.worldedit.world.block.BlockStateHolder)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 Player (org.bukkit.entity.Player)1