3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-19 09:20:08 +01:00

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

- Closes #951
Dieser Commit ist enthalten in:
Jordan 2024-06-28 21:46:51 +02:00 committet von GitHub
Ursprung 4853a65e7c
Commit ff04c93b48
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
10 geänderte Dateien mit 43 neuen und 4 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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