Fix source masks using EditSession instead of clipboard. (#515)

Dieser Commit ist enthalten in:
wizjany 2019-08-10 11:54:22 -04:00 committet von GitHub
Ursprung f83de2a703
Commit 61bc012f6f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
12 geänderte Dateien mit 91 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -48,6 +48,7 @@ import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.ClipboardMask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.factory.RegionFactory;
import com.sk89q.worldedit.session.ClipboardHolder;
@ -156,9 +157,13 @@ public class BrushCommands {
@Switch(name = 'b', desc = "Paste biomes if available")
boolean pasteBiomes,
@ArgFlag(name = 'm', desc = "Skip blocks matching this mask in the clipboard", def = "")
@ClipboardMask
Mask sourceMask) throws WorldEditException {
ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
ClipboardHolder newHolder = new ClipboardHolder(clipboard);
newHolder.setTransform(holder.getTransform());
BlockVector3 size = clipboard.getDimensions();
@ -167,7 +172,7 @@ public class BrushCommands {
worldEdit.checkMaxBrushRadius(size.getBlockZ() / 2D - 1);
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
tool.setBrush(new ClipboardBrush(holder, ignoreAir, usingOrigin, pasteEntities, pasteBiomes, sourceMask), "worldedit.brush.clipboard");
tool.setBrush(new ClipboardBrush(newHolder, ignoreAir, usingOrigin, pasteEntities, pasteBiomes, sourceMask), "worldedit.brush.clipboard");
player.print("Clipboard brush shape equipped.");
}

Datei anzeigen

@ -35,6 +35,7 @@ import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.ClipboardMask;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.math.BlockVector3;
@ -143,6 +144,7 @@ public class ClipboardCommands {
@Switch(name = 'b', desc = "Paste biomes if available")
boolean pasteBiomes,
@ArgFlag(name = 'm', desc = "Only paste blocks matching this mask", def = "")
@ClipboardMask
Mask sourceMask) throws WorldEditException {
ClipboardHolder holder = session.getClipboard();

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.command.argument;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
@ -27,9 +28,14 @@ import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.ClipboardMask;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.request.RequestExtent;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
@ -41,30 +47,53 @@ import org.enginehub.piston.converter.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;
import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
public class FactoryConverter<T> implements ArgumentConverter<T> {
public static void register(WorldEdit worldEdit, CommandManager commandManager) {
commandManager.registerConverter(Key.of(Pattern.class),
new FactoryConverter<>(worldEdit, WorldEdit::getPatternFactory, "pattern"));
new FactoryConverter<>(worldEdit, WorldEdit::getPatternFactory, "pattern", null));
commandManager.registerConverter(Key.of(Mask.class),
new FactoryConverter<>(worldEdit, WorldEdit::getMaskFactory, "mask"));
new FactoryConverter<>(worldEdit, WorldEdit::getMaskFactory, "mask", null));
commandManager.registerConverter(Key.of(BaseItem.class),
new FactoryConverter<>(worldEdit, WorldEdit::getItemFactory, "item"));
new FactoryConverter<>(worldEdit, WorldEdit::getItemFactory, "item", null));
commandManager.registerConverter(Key.of(Mask.class, ClipboardMask.class),
new FactoryConverter<>(worldEdit, WorldEdit::getMaskFactory, "mask",
context -> {
try {
ClipboardHolder holder = context.getSession().getClipboard();
Transform transform = holder.getTransform();
Extent target;
if (transform.isIdentity()) {
target = holder.getClipboard();
} else {
target = new BlockTransformExtent(holder.getClipboard(), transform);
}
context.setExtent(target);
} catch (EmptyClipboardException e) {
throw new IllegalStateException(e);
}
}));
}
private final WorldEdit worldEdit;
private final Function<WorldEdit, AbstractFactory<T>> factoryExtractor;
private final String description;
@Nullable private final Consumer<ParserContext> contextTweaker;
private FactoryConverter(WorldEdit worldEdit,
Function<WorldEdit, AbstractFactory<T>> factoryExtractor,
String description) {
String description,
@Nullable Consumer<ParserContext> contextTweaker) {
this.worldEdit = worldEdit;
this.factoryExtractor = factoryExtractor;
this.description = description;
this.contextTweaker = contextTweaker;
}
@Override
@ -80,10 +109,15 @@ public class FactoryConverter<T> implements ArgumentConverter<T> {
if (extent instanceof World) {
parserContext.setWorld((World) extent);
}
parserContext.setExtent(new RequestExtent());
}
parserContext.setSession(session);
parserContext.setRestricted(true);
if (contextTweaker != null) {
contextTweaker.accept(parserContext);
}
try {
return SuccessfulConversion.fromSingle(
factoryExtractor.apply(worldEdit).parseFromInput(argument, parserContext)

Datei anzeigen

@ -28,7 +28,6 @@ import com.sk89q.worldedit.function.mask.BiomeMask2D;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.session.request.RequestExtent;
import com.sk89q.worldedit.world.biome.BiomeType;
import java.util.Arrays;
@ -78,6 +77,6 @@ public class BiomeMaskParser extends InputParser<Mask> {
biomes.add(biome);
}
return Masks.asMask(new BiomeMask2D(new RequestExtent(), biomes));
return Masks.asMask(new BiomeMask2D(context.getExtent(), biomes));
}
}

Datei anzeigen

@ -26,7 +26,6 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.BlockCategoryMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.session.request.RequestExtent;
import com.sk89q.worldedit.world.block.BlockCategory;
import java.util.Locale;
@ -54,7 +53,7 @@ public class BlockCategoryMaskParser extends InputParser<Mask> {
if (category == null) {
throw new InputParseException("Unrecognised tag '" + input.substring(2) + '\'');
} else {
return new BlockCategoryMask(new RequestExtent(), category);
return new BlockCategoryMask(context.getExtent(), category);
}
}
}

Datei anzeigen

@ -26,7 +26,6 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.BlockStateMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.session.request.RequestExtent;
import java.util.stream.Stream;
@ -53,7 +52,7 @@ public class BlockStateMaskParser extends InputParser<Mask> {
boolean strict = input.charAt(1) == '=';
String states = input.substring(2 + (strict ? 1 : 0), input.length() - 1);
try {
return new BlockStateMask(new RequestExtent(),
return new BlockStateMask(context.getExtent(),
Splitter.on(',').omitEmptyStrings().trimResults().withKeyValueSeparator('=').split(states),
strict);
} catch (Exception e) {

Datei anzeigen

@ -26,7 +26,6 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.session.request.RequestExtent;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.Set;
@ -56,7 +55,7 @@ public class BlocksMaskParser extends InputParser<Mask> {
if (holders.isEmpty()) {
return null;
}
return new BlockMask(new RequestExtent(), holders);
return new BlockMask(context.getExtent(), holders);
} catch (NoMatchException e) {
return null;
}

Datei anzeigen

@ -25,7 +25,6 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.session.request.RequestExtent;
import java.util.List;
@ -44,6 +43,6 @@ public class ExistingMaskParser extends SimpleInputParser<Mask> {
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) {
return new ExistingBlockMask(new RequestExtent());
return new ExistingBlockMask(context.getExtent());
}
}

Datei anzeigen

@ -30,7 +30,6 @@ import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
import com.sk89q.worldedit.session.SessionOwner;
import com.sk89q.worldedit.session.request.RequestExtent;
import java.util.function.IntSupplier;
import java.util.stream.Stream;
@ -58,7 +57,7 @@ public class ExpressionMaskParser extends InputParser<Mask> {
try {
Expression exp = Expression.compile(input.substring(1), "x", "y", "z");
WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment(
new RequestExtent(), Vector3.ONE, Vector3.ZERO);
context.getExtent(), Vector3.ONE, Vector3.ZERO);
exp.setEnvironment(env);
if (context.getActor() != null) {
SessionOwner owner = context.getActor();

Datei anzeigen

@ -29,7 +29,6 @@ import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.mask.OffsetMask;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.request.RequestExtent;
import java.util.stream.Stream;
@ -62,7 +61,7 @@ public class OffsetMaskParser extends InputParser<Mask> {
if (input.length() > 1) {
submask = worldEdit.getMaskFactory().parseFromInput(input.substring(1), context);
} else {
submask = new ExistingBlockMask(new RequestExtent());
submask = new ExistingBlockMask(context.getExtent());
}
OffsetMask offsetMask = new OffsetMask(submask, BlockVector3.at(0, firstChar == '>' ? -1 : 1, 0));
return new MaskIntersection(offsetMask, Masks.negate(submask));

Datei anzeigen

@ -25,7 +25,6 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
import com.sk89q.worldedit.session.request.RequestExtent;
import java.util.List;
@ -44,6 +43,6 @@ public class SolidMaskParser extends SimpleInputParser<Mask> {
@Override
public Mask parseFromSimpleInput(String input, ParserContext context) {
return new SolidBlockMask(new RequestExtent());
return new SolidBlockMask(context.getExtent());
}
}

Datei anzeigen

@ -0,0 +1,37 @@
/*
* 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.internal.annotation;
import com.sk89q.worldedit.function.mask.Mask;
import org.enginehub.piston.inject.InjectAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotates a {@link Mask} parameter to use the clipboard as the extent instead of target World/EditSession.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@InjectAnnotation
public @interface ClipboardMask {
}