feat: add option to prevent parsing legacy blocks to the FaweLimit (#2783)

- Closes #951
This commit is contained in:
Jordan 2024-06-28 21:46:51 +02:00 committed by GitHub
parent 4853a65e7c
commit ff04c93b48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 43 additions and 4 deletions

View File

@ -51,6 +51,7 @@ public abstract class Scroll implements ScrollTool {
parserContext.setActor(player);
parserContext.setWorld(player.getWorld());
parserContext.setSession(session);
parserContext.setTryLegacy(player.getLimit().ALLOW_LEGACY);
switch (mode) {
case CLIPBOARD:
if (arguments.size() != 2) {

View File

@ -191,6 +191,7 @@ public class Settings extends Config {
}
}
limit.UNIVERSAL_DISALLOWED_BLOCKS &= newLimit.UNIVERSAL_DISALLOWED_BLOCKS;
limit.ALLOW_LEGACY &= newLimit.ALLOW_LEGACY;
if (limit.DISALLOWED_BLOCKS == null) {
limit.DISALLOWED_BLOCKS = newLimit.DISALLOWED_BLOCKS.isEmpty() ? Collections.emptySet() : new HashSet<>(
@ -439,6 +440,10 @@ public class Settings extends Config {
" - If fast-placement is disabled, this may cause edits to be slower."
})
public boolean UNIVERSAL_DISALLOWED_BLOCKS = true;
@Comment({
"If legacy, mumerical, blocks IDs should be able to be used (i.e. 12:2),"
})
public boolean ALLOW_LEGACY = true;
@Comment({
"List of blocks to deny use of. Can be either an entire block type or a block with a specific property value.",
"Where block properties are specified, any blockstate with the property will be disallowed (e.g. all directions",

View File

@ -143,7 +143,7 @@ public class RichMaskParser extends FaweParser<Mask> {
int end = command.lastIndexOf(']');
mask = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
} else {
BlockMaskBuilder builder = new BlockMaskBuilder();
BlockMaskBuilder builder = new BlockMaskBuilder(context);
try {
builder.addRegex(full);
} catch (InputParseException ignored) {

View File

@ -200,6 +200,7 @@ public class ConsumeBindings extends Bindings {
public BaseBlock baseBlock(Actor actor, String argument) {
ParserContext parserContext = new ParserContext();
parserContext.setActor(actor);
parserContext.setTryLegacy(actor.getLimit().ALLOW_LEGACY);
if (actor instanceof Entity) {
Extent extent = ((Entity) actor).getExtent();
if (extent instanceof World) {

View File

@ -9,6 +9,7 @@ import com.fastasyncworldedit.core.util.MutableCharSequence;
import com.fastasyncworldedit.core.util.StringMan;
import com.fastasyncworldedit.core.world.block.BlanketBaseBlock;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.registry.state.AbstractProperty;
@ -53,6 +54,7 @@ public class BlockMaskBuilder {
private static final long[] ALL = new long[0];
private final long[][] bitSets;
private final ParserContext context;
private boolean[] ordinals;
private boolean optimizedStates = true;
@ -60,8 +62,28 @@ public class BlockMaskBuilder {
this(new long[BlockTypes.size()][]);
}
/**
* Create a new instance with a given {@link ParserContext} to use if parsing regex
*
* @since TODO
*/
public BlockMaskBuilder(ParserContext context) {
this(new long[BlockTypes.size()][], context);
}
protected BlockMaskBuilder(long[][] bitSets) {
this.bitSets = bitSets;
this.context = new ParserContext();
}
/**
* Create a new instance with a given {@link ParserContext} to use if parsing regex
*
* @since TODO
*/
protected BlockMaskBuilder(long[][] bitSets, ParserContext context) {
this.bitSets = bitSets;
this.context = context;
}
private boolean handleRegex(BlockType blockType, PropertyKey key, String regex, FuzzyStateAllowingBuilder builder) {
@ -173,7 +195,7 @@ public class BlockMaskBuilder {
List<BlockType> blockTypeList;
List<FuzzyStateAllowingBuilder> builders;
if (StringMan.isAlphanumericUnd(charSequence)) {
BlockType type = BlockTypes.parse(charSequence.toString());
BlockType type = BlockTypes.parse(charSequence.toString(), context);
blockTypeList = Collections.singletonList(type);
builders = Collections.singletonList(new FuzzyStateAllowingBuilder(type));
add(type);
@ -280,7 +302,7 @@ public class BlockMaskBuilder {
}
} else {
if (StringMan.isAlphanumericUnd(input)) {
add(BlockTypes.parse(input));
add(BlockTypes.parse(input, context));
} else {
boolean success = false;
for (BlockType myType : BlockTypesCache.values) {

View File

@ -28,6 +28,7 @@ public class FaweLimit {
public boolean FAST_PLACEMENT = false;
public boolean CONFIRM_LARGE = true;
public boolean RESTRICT_HISTORY_TO_REGIONS = true;
public boolean ALLOW_LEGACY = true;
public Set<String> STRIP_NBT = null;
public boolean UNIVERSAL_DISALLOWED_BLOCKS = true;
public Set<String> DISALLOWED_BLOCKS = null;
@ -127,6 +128,7 @@ public class FaweLimit {
MAX.RESTRICT_HISTORY_TO_REGIONS = false;
MAX.STRIP_NBT = Collections.emptySet();
MAX.UNIVERSAL_DISALLOWED_BLOCKS = false;
MAX.ALLOW_LEGACY = true;
MAX.DISALLOWED_BLOCKS = Collections.emptySet();
MAX.REMAP_PROPERTIES = Collections.emptySet();
MAX.MAX_RADIUS = Integer.MAX_VALUE;
@ -259,13 +261,13 @@ public class FaweLimit {
&& !RESTRICT_HISTORY_TO_REGIONS
&& (STRIP_NBT == null || STRIP_NBT.isEmpty())
// && !UNIVERSAL_DISALLOWED_BLOCKS --> do not include this, it effectively has no relevance
&& ALLOW_LEGACY
&& (DISALLOWED_BLOCKS == null || DISALLOWED_BLOCKS.isEmpty())
&& (REMAP_PROPERTIES == null || REMAP_PROPERTIES.isEmpty())
&& MAX_RADIUS == Integer.MAX_VALUE
&& MAX_SUPER_PICKAXE_SIZE == Integer.MAX_VALUE
&& MAX_BRUSH_RADIUS == Integer.MAX_VALUE
&& MAX_BUTCHER_RADIUS == Integer.MAX_VALUE;
}
public void set(FaweLimit limit) {
@ -286,6 +288,7 @@ public class FaweLimit {
RESTRICT_HISTORY_TO_REGIONS = limit.RESTRICT_HISTORY_TO_REGIONS;
STRIP_NBT = limit.STRIP_NBT;
UNIVERSAL_DISALLOWED_BLOCKS = limit.UNIVERSAL_DISALLOWED_BLOCKS;
ALLOW_LEGACY = limit.ALLOW_LEGACY;
DISALLOWED_BLOCKS = limit.DISALLOWED_BLOCKS;
REMAP_PROPERTIES = limit.REMAP_PROPERTIES;
MAX_RADIUS = limit.MAX_RADIUS;
@ -313,6 +316,7 @@ public class FaweLimit {
limit.RESTRICT_HISTORY_TO_REGIONS = RESTRICT_HISTORY_TO_REGIONS;
limit.STRIP_NBT = STRIP_NBT;
limit.UNIVERSAL_DISALLOWED_BLOCKS = UNIVERSAL_DISALLOWED_BLOCKS;
limit.ALLOW_LEGACY = ALLOW_LEGACY;
limit.DISALLOWED_BLOCKS = DISALLOWED_BLOCKS;
limit.REMAP_PROPERTIES = REMAP_PROPERTIES;
limit.MAX_RADIUS = MAX_RADIUS;

View File

@ -510,6 +510,7 @@ public class GeneralCommands {
parserContext.setWorld(worldArg);
parserContext.setSession(session);
parserContext.setExtent(editSession);
parserContext.setTryLegacy(actor.getLimit().ALLOW_LEGACY);
Mask mask = worldEdit.getMaskFactory().parseFromInput(arg, parserContext);
util = TextureUtil.fromMask(mask);
}

View File

@ -133,6 +133,7 @@ public class FactoryConverter<T> implements ArgumentConverter<T> {
parserContext.setSession(session);
parserContext.setRestricted(true);
parserContext.setInjected(context);
parserContext.setTryLegacy(actor.getLimit().ALLOW_LEGACY);
if (contextTweaker != null) {
contextTweaker.accept(parserContext);

View File

@ -49,6 +49,7 @@ public class BlocksMaskParser extends InputParser<Mask> {
ParserContext tempContext = new ParserContext(context);
tempContext.setRestricted(false);
tempContext.setPreferringWildcard(true);
tempContext.setTryLegacy(context.isTryingLegacy());
try {
Set<BaseBlock> holders = worldEdit.getBlockFactory().parseFromListInput(component, tempContext);
if (holders.isEmpty()) {

View File

@ -183,6 +183,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
context.setSession(session);
context.setRestricted(!allAllowed);
context.setPreferringWildcard(false);
context.setTryLegacy(player.getLimit().ALLOW_LEGACY);
return controller.getBlockFactory().parseFromListInput(input, context).stream().findFirst().orElse(null);
}
@ -212,6 +213,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
context.setActor(player);
context.setWorld(player.getWorld());
context.setSession(session);
context.setTryLegacy(player.getLimit().ALLOW_LEGACY);
return controller.getPatternFactory().parseFromInput(list, context);
}
@ -230,6 +232,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
context.setWorld(player.getWorld());
context.setSession(session);
context.setRestricted(!allBlocksAllowed);
context.setTryLegacy(player.getLimit().ALLOW_LEGACY);
return controller.getBlockFactory().parseFromListInput(list, context);
}