com.sk89q.worldedit.extent.Extent Java Examples

The following examples show how to use com.sk89q.worldedit.extent.Extent. 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: FawePrimitiveBinding.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@BindingMatch(
        type = {Extent.class},
        behavior = BindingBehavior.PROVIDES
)
public Extent getExtent(ArgumentStack context) throws ParameterException {
    Extent extent = context.getContext().getLocals().get(EditSession.class);
    if (extent != null) return extent;
    extent = Request.request().getExtent();
    if (extent != null) return extent;
    Actor actor = context.getContext().getLocals().get(Actor.class);
    if (actor == null) throw new ParameterException("No player to get a session for");
    if (!(actor instanceof Player)) throw new ParameterException("Caller is not a player");
    LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
    EditSession editSession = session.createEditSession((Player) actor);
    editSession.enableQueue();
    context.getContext().getLocals().put(EditSession.class, editSession);
    session.tellVersion(actor);
    return editSession;
}
 
Example #2
Source File: Schematic.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public void paste(Extent extent, WorldData worldData, Vector to, boolean pasteAir, Transform transform) {
    checkNotNull(transform);
    Region region = clipboard.getRegion();
    Extent source = clipboard;
    if (worldData != null && transform != null) {
        source = new BlockTransformExtent(clipboard, transform, worldData.getBlockRegistry());
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(), extent, to);
    if (transform != null) {
        copy.setTransform(transform);
    }
    copy.setCopyBiomes(!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes());
    if (extent instanceof EditSession) {
        EditSession editSession = (EditSession) extent;
        Mask sourceMask = editSession.getSourceMask();
        if (sourceMask != null) {
            new MaskTraverser(sourceMask).reset(extent);
            copy.setSourceMask(sourceMask);
            editSession.setSourceMask(null);
        }
    }
    if (!pasteAir) {
        copy.setSourceMask(new ExistingBlockMask(clipboard));
    }
    Operations.completeBlindly(copy);
}
 
Example #3
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 #4
Source File: MaskCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#nolight"},
        desc = "Restrict to blocks without light (sky or emitted)"
)
public Mask nolight(Extent extent) {
    return new LightMask(extent, 0, 0);
}
 
Example #5
Source File: ExtentTraverser.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public <U extends Extent> ExtentTraverser<U> find(Object object) {
    try {
        ExtentTraverser<T> value = this;
        while (value != null) {
            if (value.root == object) {
                return (ExtentTraverser<U>) value;
            }
            value = value.next();
        }
        return null;
    } catch (Throwable e) {
        MainUtil.handleError(e);
        return null;
    }
}
 
Example #6
Source File: MaskCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#data"},
        desc = "Restrict to initial data"
)
public Mask data(Extent extent) {
    return new DataMask(extent);
}
 
Example #7
Source File: MutableBlockChange.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void create(UndoContext context) {
    if (queue != null) {
        queue.setBlock(x, y, z, id, data);
    }
    if (!checkedQueue) {
        checkedQueue = true;
        Extent extent = context.getExtent();
        ExtentTraverser found = new ExtentTraverser(extent).find(HasFaweQueue.class);
        if (found != null) {
            (queue = ((HasFaweQueue) found.get()).getQueue()).setBlock(x, y, z, id, data);
        } else {
            Fawe.debug("FAWE does not support: " + extent + " for " + getClass() + " (bug Empire92)");
        }
    }
}
 
Example #8
Source File: DataMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean test(Vector vector) {
    Extent extent = getExtent();
    if (data != -1) {
        return extent.getLazyBlock(vector).getData() == data;
    } else {
        data = extent.getLazyBlock(vector).getData();
        return true;
    }
}
 
Example #9
Source File: RandomOffsetPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
    mutable.mutX((get.getX() + r.nextInt(dx2) - dx));
    mutable.mutY((get.getY() + r.nextInt(dy2) - dy));
    mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz));
    return pattern.apply(extent, set, mutable);
}
 
Example #10
Source File: MaskCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#solid"},
        desc = "If there is a solid block"
)
public Mask solid(Extent extent) {
    return new SolidBlockMask(extent);
}
 
Example #11
Source File: PatternCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#anglecolor"},
        desc = "A darker block based on the existing terrain angle",
        usage = "[randomize=true] [max-complexity=100] [distance=1]",
        min = 0,
        max = 3
)
public Pattern anglecolor(Extent extent, LocalSession session, @Optional("true") boolean randomize, @Optional("100") double maxComplexity, @Optional("1") int distance) {
    return new AngleColorPattern(extent, session, distance);
}
 
Example #12
Source File: BlockReplace.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param extent  an extent
 * @param pattern a pattern
 */
public BlockReplace(Extent extent, Pattern pattern) {
    checkNotNull(extent);
    checkNotNull(pattern);
    this.extent = extent;
    this.pattern = pattern;
}
 
Example #13
Source File: IdMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean test(Vector vector) {
    Extent extent = getExtent();
    if (id != -1) {
        return extent.getLazyBlock(vector).getId() == id;
    } else {
        id = extent.getLazyBlock(vector).getId();
        return true;
    }
}
 
Example #14
Source File: LinearTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResettableExtent setExtent(Extent extent) {
    for (ResettableExtent cur : extentsArray) {
        cur.setExtent(extent);
    }
    return this;
}
 
Example #15
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 #16
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 #17
Source File: Linear3DBlockPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
    int index = (get.getBlockX() + get.getBlockY() + get.getBlockZ()) % patternsArray.length;
    if (index < 0) {
        index += patternsArray.length;
    }
    return patternsArray[index].apply(extent, set, get);
}
 
Example #18
Source File: OffsetPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
    mutable.mutX((get.getX() + dx));
    mutable.mutY((get.getY() + dy));
    mutable.mutZ((get.getZ() + dz));
    return pattern.apply(extent, set, mutable);
}
 
Example #19
Source File: PatternCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#darken"},
        desc = "Darken the existing block",
        min = 0,
        max = 2
)
public Pattern darken(Extent extent, TextureUtil util) {
    return new ShadePattern(extent, true, util);
}
 
Example #20
Source File: PatternCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#!z", "#nz", "#noz"},
        desc = "The pattern will not be provided the z axis info",
        usage = "<pattern>",
        min = 1,
        max = 1
)
public Pattern noz(Actor actor, LocalSession session, Extent extent, Pattern pattern) {
    return new NoZPattern(pattern);
}
 
Example #21
Source File: RandomOffsetTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public RandomOffsetTransform(Extent parent, int dx, int dy, int dz) {
    super(parent);
    this.dx = dx + 1;
    this.dy = dy + 1;
    this.dz = dz + 1;
    this.random = new SplittableRandom();
}
 
Example #22
Source File: HistoryExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param extent    the extent
 * @param changeSet the change set
 */
public HistoryExtent(final EditSession session, final Extent extent, final FaweChangeSet changeSet, FaweQueue queue) {
    super(extent);
    checkNotNull(changeSet);
    this.queue = queue;
    this.changeSet = changeSet;
    this.session = session;
}
 
Example #23
Source File: MaskCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#haslight"},
        desc = "Restricts to blocks with light (sky or emitted)"
)
public Mask haslight(Extent extent) {
    return new LightMask(extent, 1, Integer.MAX_VALUE);
}
 
Example #24
Source File: AngleColorPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    int slope = getSlope(block, getPosition);
    if (slope == -1) return false;
    int color = util.getTextureUtil().getColor(block);
    if (color == 0) return false;
    int newColor = getColor(color, slope);
    BaseBlock newBlock = util.getTextureUtil().getNearestBlock(newColor);
    if (newBlock == null) return false;
    return extent.setBlock(setPosition, newBlock);
}
 
Example #25
Source File: PatternCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"#biome", "$"},
        desc = "Set the biome",
        usage = "<biome>",
        min = 1,
        max = 1
)
public Pattern data(Actor actor, LocalSession session, Extent extent, BaseBiome biome) {
    return new BiomePattern(extent, biome);
}
 
Example #26
Source File: RandomFullClipboardPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public RandomFullClipboardPattern(Extent extent, WorldData worldData, List<ClipboardHolder> clipboards, boolean randomRotate, boolean randomFlip) {
    checkNotNull(clipboards);
    this.clipboards = clipboards;
    this.extent = extent;
    this.randomRotate = randomRotate;
    this.worldData = worldData;
}
 
Example #27
Source File: MaskCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"="},
        desc = "expression mask",
        usage = "<expression>",
        min = 1,
        max = 1
)
public Mask expression(Extent extent, String input) throws ExpressionException {
    Expression exp = Expression.compile(input, "x", "y", "z");
    WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(extent, Vector.ONE, Vector.ZERO);
    exp.setEnvironment(env);
    return new ExpressionMask(exp);
}
 
Example #28
Source File: Request.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public
@Nullable
Extent getExtent() {
    if (extent != null) return extent;
    if (editSession != null) return editSession;
    if (world != null) return world;
    return null;
}
 
Example #29
Source File: PasteEvent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public PasteEvent(Player player, Clipboard clipboard, URI uri, Extent extent, Vector to) {
    this.player = player;
    this.clipboard = clipboard;
    this.uri = uri;
    this.extent = extent;
    this.to = to;
}
 
Example #30
Source File: SurfaceRegionFunction.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public SurfaceRegionFunction(Extent extent, RegionFunction function, int minY, int maxY) {
    this.extent = extent;
    this.minY = minY;
    this.maxY = maxY;
    this.lastY = maxY;
    this.function = function;
}