mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 12:36:40 +00:00
Reorganize and further unify the new commands.
This commit is contained in:
@ -17,13 +17,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
package com.sk89q.worldedit.function;
|
||||
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
public interface Contextual<T> {
|
||||
|
||||
public interface OperationFactory {
|
||||
|
||||
Operation createOperation(EditContext context);
|
||||
T createFromContext(EditContext context);
|
||||
|
||||
}
|
@ -19,43 +19,44 @@
|
||||
|
||||
package com.sk89q.worldedit.function;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class EditContext {
|
||||
|
||||
private Extent destination = new NullExtent();
|
||||
private Region region = new CuboidRegion(Vector.ZERO, Vector.ZERO);
|
||||
private Pattern fill = new BlockPattern(new BaseBlock(BlockID.AIR));
|
||||
private Extent destination;
|
||||
@Nullable private Region region;
|
||||
@Nullable private Pattern fill;
|
||||
|
||||
public Extent getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(Extent destination) {
|
||||
checkNotNull(destination, "destination");
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Region getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(Region region) {
|
||||
public void setRegion(@Nullable Region region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Pattern getFill() {
|
||||
return fill;
|
||||
}
|
||||
|
||||
public void setFill(Pattern fill) {
|
||||
public void setFill(@Nullable Pattern fill) {
|
||||
this.fill = fill;
|
||||
}
|
||||
|
||||
|
@ -19,31 +19,41 @@
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
||||
import com.sk89q.worldedit.regions.NullRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class RegionApply implements OperationFactory {
|
||||
public class Apply implements Contextual<Operation> {
|
||||
|
||||
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
|
||||
private final Region region;
|
||||
private final Contextual<? extends RegionFunction> function;
|
||||
|
||||
public RegionApply(Function<EditContext, ? extends RegionFunction> regionFunctionFactory) {
|
||||
checkNotNull(regionFunctionFactory, "regionFunctionFactory");
|
||||
this.regionFunctionFactory = regionFunctionFactory;
|
||||
public Apply(Contextual<? extends RegionFunction> function) {
|
||||
this(new NullRegion(), function);
|
||||
}
|
||||
|
||||
public Apply(Region region, Contextual<? extends RegionFunction> function) {
|
||||
checkNotNull(region, "region");
|
||||
checkNotNull(function, "function");
|
||||
this.region = region;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation createOperation(EditContext context) {
|
||||
return new RegionVisitor(context.getRegion(), regionFunctionFactory.apply(context));
|
||||
public Operation createFromContext(EditContext context) {
|
||||
return new RegionVisitor(MoreObjects.firstNonNull(context.getRegion(), region), function.createFromContext(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "set " + regionFunctionFactory;
|
||||
return "set " + function;
|
||||
}
|
||||
|
||||
}
|
@ -19,37 +19,73 @@
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.regions.NullRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class Deform implements OperationFactory {
|
||||
public class Deform implements Contextual<Operation> {
|
||||
|
||||
private Extent destination;
|
||||
private Region region;
|
||||
private String expression;
|
||||
private Mode mode = Mode.UNIT_CUBE;
|
||||
private Vector offset = new Vector();
|
||||
|
||||
public Deform(String expression) {
|
||||
checkNotNull(expression, "expression");
|
||||
this.expression = expression;
|
||||
this(new NullExtent(), new NullRegion(), expression);
|
||||
}
|
||||
|
||||
public Deform(String expression, Mode mode) {
|
||||
this(new NullExtent(), new NullRegion(), expression, mode);
|
||||
}
|
||||
|
||||
public Deform(Extent destination, Region region, String expression) {
|
||||
this(destination, region, expression, Mode.UNIT_CUBE);
|
||||
}
|
||||
|
||||
public Deform(Extent destination, Region region, String expression, Mode mode) {
|
||||
checkNotNull(destination, "destination");
|
||||
checkNotNull(region, "region");
|
||||
checkNotNull(expression, "expression");
|
||||
checkNotNull(mode, "mode");
|
||||
this.destination = destination;
|
||||
this.region = region;
|
||||
this.expression = expression;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public Extent getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(Extent destination) {
|
||||
checkNotNull(destination, "destination");
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public Region getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(Region region) {
|
||||
checkNotNull(region, "region");
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
@ -83,14 +119,16 @@ public class Deform implements OperationFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation createOperation(final EditContext context) {
|
||||
public Operation createFromContext(final EditContext context) {
|
||||
final Vector zero;
|
||||
Vector unit;
|
||||
|
||||
Region region = MoreObjects.firstNonNull(context.getRegion(), this.region);
|
||||
|
||||
switch (mode) {
|
||||
case UNIT_CUBE:
|
||||
final Vector min = context.getRegion().getMinimumPoint();
|
||||
final Vector max = context.getRegion().getMaximumPoint();
|
||||
final Vector min = region.getMinimumPoint();
|
||||
final Vector max = region.getMaximumPoint();
|
||||
|
||||
zero = max.add(min).multiply(0.5);
|
||||
unit = max.subtract(zero);
|
||||
@ -109,7 +147,7 @@ public class Deform implements OperationFactory {
|
||||
unit = Vector.ONE;
|
||||
}
|
||||
|
||||
return new DeformOperation(context.getDestination(), context.getRegion(), zero, unit, expression);
|
||||
return new DeformOperation(context.getDestination(), region, zero, unit, expression);
|
||||
}
|
||||
|
||||
private static final class DeformOperation implements Operation {
|
||||
@ -141,6 +179,12 @@ public class Deform implements OperationFactory {
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
messages.add("deformed using " + expression);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
|
@ -19,7 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.GroundFunction;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
@ -28,25 +31,41 @@ import com.sk89q.worldedit.function.mask.NoiseFilter2D;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.visitor.LayerVisitor;
|
||||
import com.sk89q.worldedit.math.noise.RandomNoise;
|
||||
import com.sk89q.worldedit.regions.NullRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.regions.Regions.*;
|
||||
|
||||
public class Scatter implements OperationFactory {
|
||||
public class Paint implements Contextual<Operation> {
|
||||
|
||||
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
|
||||
private final Extent destination;
|
||||
private final Region region;
|
||||
private final Contextual<? extends RegionFunction> function;
|
||||
private final double density;
|
||||
|
||||
public Scatter(Function<EditContext, ? extends RegionFunction> regionFunctionFactory, double density) {
|
||||
this.regionFunctionFactory = regionFunctionFactory;
|
||||
public Paint(Contextual<? extends RegionFunction> function, double density) {
|
||||
this(new NullExtent(), new NullRegion(), function, density);
|
||||
}
|
||||
|
||||
public Paint(Extent destination, Region region, Contextual<? extends RegionFunction> function,
|
||||
double density) {
|
||||
checkNotNull(destination, "destination");
|
||||
checkNotNull(region, "region");
|
||||
checkNotNull(function, "function");
|
||||
checkNotNull(density, "density");
|
||||
this.destination = destination;
|
||||
this.region = region;
|
||||
this.function = function;
|
||||
this.density = density;
|
||||
new NoiseFilter2D(new RandomNoise(), density); // Check validity density argument
|
||||
new NoiseFilter2D(new RandomNoise(), density); // Check validity of the density argument
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation createOperation(EditContext context) {
|
||||
Region region = context.getRegion();
|
||||
GroundFunction ground = new GroundFunction(new ExistingBlockMask(context.getDestination()), regionFunctionFactory.apply(context));
|
||||
public Operation createFromContext(EditContext context) {
|
||||
Extent destination = MoreObjects.firstNonNull(context.getDestination(), this.destination);
|
||||
Region region = MoreObjects.firstNonNull(context.getRegion(), this.region);
|
||||
GroundFunction ground = new GroundFunction(new ExistingBlockMask(destination), function.createFromContext(context));
|
||||
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
|
||||
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
|
||||
return visitor;
|
||||
@ -54,7 +73,7 @@ public class Scatter implements OperationFactory {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "scatter " + regionFunctionFactory;
|
||||
return "scatter " + function;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.block.BlockReplace;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
||||
|
||||
public class RegionReplace implements OperationFactory {
|
||||
|
||||
@Override
|
||||
public Operation createOperation(EditContext context) {
|
||||
BlockReplace replace = new BlockReplace(context.getDestination(), context.getFill());
|
||||
return new RegionVisitor(context.getRegion(), replace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "set blocks";
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -64,4 +65,9 @@ public class BlockMapEntryPlacer implements Operation {
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.history.changeset.ChangeSet;
|
||||
import com.sk89q.worldedit.history.UndoContext;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -79,6 +80,10 @@ public class ChangeSetExecutor implements Operation {
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new undo operation.
|
||||
*
|
||||
|
@ -21,6 +21,8 @@ package com.sk89q.worldedit.function.operation;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
@ -57,4 +59,10 @@ public class DelegateOperation implements Operation {
|
||||
original.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
original.addStatusMessages(messages);
|
||||
delegate.addStatusMessages(messages);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -246,4 +246,8 @@ public class ForwardExtentCopy implements Operation {
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ package com.sk89q.worldedit.function.operation;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An task that may be split into multiple steps to be run sequentially
|
||||
* immediately or at a varying or fixed interval. Operations should attempt
|
||||
@ -49,4 +51,12 @@ public interface Operation {
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Add messages to the provided list that describe the current status
|
||||
* of the operation.
|
||||
*
|
||||
* @param messages The list to add messages to
|
||||
*/
|
||||
void addStatusMessages(List<String> messages);
|
||||
|
||||
}
|
||||
|
@ -19,11 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.function.operation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -32,6 +34,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class OperationQueue implements Operation {
|
||||
|
||||
private final List<Operation> operations = Lists.newArrayList();
|
||||
private final Deque<Operation> queue = new ArrayDeque<Operation>();
|
||||
private Operation current;
|
||||
|
||||
@ -51,6 +54,7 @@ public class OperationQueue implements Operation {
|
||||
for (Operation operation : operations) {
|
||||
offer(operation);
|
||||
}
|
||||
this.operations.addAll(operations);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,4 +104,11 @@ public class OperationQueue implements Operation {
|
||||
queue.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
for (Operation operation : operations) {
|
||||
operation.addStatusMessages(messages);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -176,4 +176,9 @@ public abstract class BreadthFirstSearch implements Operation {
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
messages.add(getAffected() + " blocks affected");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -75,4 +76,9 @@ public class EntityVisitor implements Operation {
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
messages.add(getAffected() + " entities affected");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
@ -75,5 +77,10 @@ public class FlatRegionVisitor implements Operation {
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
messages.add(getAffected() + " columns affected");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.regions.FlatRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -125,4 +127,9 @@ public class LayerVisitor implements Operation {
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.operation.RunContext;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility class to apply region functions to {@link com.sk89q.worldedit.regions.Region}.
|
||||
*/
|
||||
@ -64,5 +66,10 @@ public class RegionVisitor implements Operation {
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
messages.add(getAffected() + " blocks affected");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user