com.sk89q.worldedit.extent.AbstractDelegateExtent Java Examples

The following examples show how to use com.sk89q.worldedit.extent.AbstractDelegateExtent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldEditHook.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void wrapForLogging(EditSessionEvent event) {
    event.setExtent(new AbstractDelegateExtent(event.getExtent()) {

        @Override
        public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 pos, T block) throws WorldEditException {
            if (block.getBlockType().getMaterial().isAir()) {
                World world = Bukkit.getWorld(event.getWorld().getName());

                if (world != null) {
                    Location l = new Location(world, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());

                    if (BlockStorage.hasBlockInfo(l)) {
                        BlockStorage.clearBlockInfo(l);
                    }
                }
            }
            
            return getExtent().setBlock(pos, block);
        }

    });
}
 
Example #2
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public boolean cancel() {
    ExtentTraverser traverser = new ExtentTraverser(this.extent);
    NullExtent nullExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
    while (traverser != null) {
        ExtentTraverser next = traverser.next();
        Extent get = traverser.get();
        if (get instanceof AbstractDelegateExtent && !(get instanceof NullExtent)) {
            traverser.setNext(nullExtent);
        }
        traverser = next;
    }
    bypassHistory = nullExtent;
    this.extent = nullExtent;
    bypassAll = nullExtent;
    dequeue();
    queue.clear();
    return true;
}
 
Example #3
Source File: ExtentTraverser.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public ExtentTraverser<T> next() {
    try {
        if (root instanceof AbstractDelegateExtent) {
            Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
            field.setAccessible(true);
            T value = (T) field.get(root);
            if (value == null) {
                return null;
            }
            return new ExtentTraverser<>(value, this);
        }
        return null;
    } catch (Throwable e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #4
Source File: LinearTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AbstractDelegateExtent getExtent(int x, int y, int z) {
    if (index == extentsArray.length) {
        index = 0;
    }
    return extentsArray[index];
}
 
Example #5
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public @Nullable ResettableExtent getTransform() {
    ExtentTraverser<AbstractDelegateExtent> traverser = new ExtentTraverser(this.extent).find(ResettableExtent.class);
    if (traverser != null) {
        return (ResettableExtent) traverser.get();
    }
    return null;
}
 
Example #6
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void addTransform(ResettableExtent transform) {
    wrapped = true;
    if (transform == null) {
        ExtentTraverser<AbstractDelegateExtent> traverser = new ExtentTraverser(this.extent).find(ResettableExtent.class);
        AbstractDelegateExtent next = extent;
        while (traverser != null && traverser.get() instanceof ResettableExtent) {
            traverser = traverser.next();
            next = traverser.get();
        }
        this.extent = next;
        return;
    } else {
        this.extent = transform.setExtent(extent);
    }
}
 
Example #7
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
private AbstractDelegateExtent wrapExtent(final AbstractDelegateExtent extent, final EventBus eventBus, EditSessionEvent event, final Stage stage) {
    event = event.clone(stage);
    event.setExtent(extent);
    eventBus.post(event);
    if (event.isCancelled()) {
        return new NullExtent(extent, BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
    }
    final Extent toReturn = event.getExtent();
    if (!(toReturn instanceof AbstractDelegateExtent)) {
        Fawe.debug("Extent " + toReturn + " must be AbstractDelegateExtent");
        return extent;
    }
    if (toReturn != extent) {
        String className = toReturn.getClass().getName().toLowerCase();
        for (String allowed : Settings.IMP.EXTENT.ALLOWED_PLUGINS) {
            if (className.contains(allowed.toLowerCase())) {
                this.wrapped = true;
                return (AbstractDelegateExtent) toReturn;
            }
        }
        if (Settings.IMP.EXTENT.DEBUG) {
            Fawe.debug("&cPotentially unsafe extent blocked: " + toReturn.getClass().getName());
            Fawe.debug("&8 - &7For area restrictions, it is recommended to use the FaweAPI");
            Fawe.debug("&8 - &7For block logging, it is recommended to use use BlocksHub");
            Fawe.debug("&8 - &7To allow this plugin add it to the FAWE `allowed-plugins` list");
            Fawe.debug("&8 - &7To hide this message set `debug` to false in the FAWE config.yml");
            if (toReturn.getClass().getName().contains("CoreProtect")) {
                Fawe.debug("Note on CoreProtect: ");
                Fawe.debug(" - If you disable CP's WE logger (CP config) and this still shows, please update CP");
                Fawe.debug(" - Use BlocksHub and set `debug` false in the FAWE config");
            }
        }
    }
    return extent;
}
 
Example #8
Source File: ExtentTraverser.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean insert(T extent) {
    try {
        Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
        field.setAccessible(true);
        field.set(extent, field.get(root));
        field.set(root, extent);
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}
 
Example #9
Source File: ExtentTraverser.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setNext(T next) {
    try {
        Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
        ReflectionUtils.setFailsafeFieldValue(field, root, next);
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}
 
Example #10
Source File: WEManager.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void cancelEditSafe(Extent parent, BBC reason) throws FaweException {
    try {
        final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
        field.setAccessible(true);
        Object currentExtent = field.get(parent);
        if (!(currentExtent instanceof NullExtent)) {
            field.set(parent, new NullExtent((Extent) field.get(parent), reason));
        }
    } catch (final Exception e) {
        MainUtil.handleError(e);
    }
    throw new FaweException(reason);
}
 
Example #11
Source File: Linear3DTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AbstractDelegateExtent getExtent(int x, int y, int z) {
    int index = (x + y + z) % extentsArray.length;
    if (index < 0) {
        index += extentsArray.length;
    }
    return extentsArray[index];
}
 
Example #12
Source File: RandomTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResettableExtent setExtent(Extent extent) {
    if (collection == null) {
        collection = RandomCollection.of(weights, random);
        extents = new LinkedHashSet<>(weights.keySet());
    }
    for (AbstractDelegateExtent current : extents) {
        if (current instanceof ResettableExtent) {
            ((ResettableExtent) current).setExtent(extent);
        }
    }
    return this;
}
 
Example #13
Source File: MultiTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    Entity created = null;
    for (AbstractDelegateExtent extent : extents) created = extent.createEntity(location, entity);
    return created;
}
 
Example #14
Source File: ResettableExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public ResettableExtent setExtent(Extent extent) {
    checkNotNull(extent);
    Extent next = getExtent();
    if (!(next instanceof NullExtent) && !(next instanceof World) && next instanceof ResettableExtent) {
        ((ResettableExtent) next).setExtent(extent);
    } else {
        new ExtentTraverser(this).setNext(new AbstractDelegateExtent(extent));
    }
    return this;
}
 
Example #15
Source File: ResettableExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (stream.readBoolean()) {
        try {
            Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
            ReflectionUtils.setFailsafeFieldValue(field, this, stream.readObject());
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
 
Example #16
Source File: WorldGuardSevenCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
@Override
public AbstractDelegateExtent getWorldEditFlag(World world, Extent extent, com.sk89q.worldedit.entity.Player player)
{
	return new WorldEditFlagHandler(world, extent, player);
}
 
Example #17
Source File: WorldGuardSixCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
@Override
public AbstractDelegateExtent getWorldEditFlag(World world, Extent extent, com.sk89q.worldedit.entity.Player player)
{
	return new WorldEditFlagHandler(world, extent, player);
}
 
Example #18
Source File: MultiTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) throws WorldEditException {
    boolean result = false;
    for (AbstractDelegateExtent extent : extents) result |= extent.setBlock(x, y, z, block);
    return result;
}
 
Example #19
Source File: MultiTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
    boolean result = false;
    for (AbstractDelegateExtent extent : extents) result |= extent.setBlock(location, block);
    return result;
}
 
Example #20
Source File: MultiTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
    boolean result = false;
    for (AbstractDelegateExtent extent : extents) result |= extent.setBiome(position, biome);
    return result;
}
 
Example #21
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void setExtent(AbstractDelegateExtent extent) {
    this.extent = extent;
    new ExtentTraverser(this).setNext(extent);
}
 
Example #22
Source File: RandomTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AbstractDelegateExtent getExtent(int x, int y, int z) {
    return collection.next(x, y, z);
}
 
Example #23
Source File: ProcessedWEExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public ProcessedWEExtent(final Extent parent, FaweLimit limit) {
    super(parent);
    this.limit = limit;
    this.extent = (AbstractDelegateExtent) parent;
}
 
Example #24
Source File: LinearTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AbstractDelegateExtent getExtent(int x, int z) {
    return getExtent(x, 0, z);
}
 
Example #25
Source File: Linear3DTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AbstractDelegateExtent getExtent(int x, int z) {
    return getExtent(x, 0, z);
}
 
Example #26
Source File: RandomTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AbstractDelegateExtent getExtent(int x, int z) {
    return collection.next(x, 0, z);
}
 
Example #27
Source File: SelectTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 votes vote down vote up
public abstract AbstractDelegateExtent getExtent(int x, int z); 
Example #28
Source File: SelectTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 votes vote down vote up
public abstract AbstractDelegateExtent getExtent(int x, int y, int z); 
Example #29
Source File: WorldGuardCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License votes vote down vote up
public AbstractDelegateExtent getWorldEditFlag(World world, Extent extent, com.sk89q.worldedit.entity.Player player);