Permalink
Browse files

Merge pull request #438 from sk89q/feature/modular-patterns-masks

Modularise Patterns & Masks
  • Loading branch information...
me4502 committed Dec 26, 2018
2 parents 976a92d + b75d514 commit 4cc8e9a1c0bc21ff179697cd59b4545c517127e7
Showing with 849 additions and 258 deletions.
  1. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/BlockFactory.java
  2. +0 −185 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java
  3. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/ItemFactory.java
  4. +58 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java
  5. +6 −3 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/PatternFactory.java
  6. +3 −3 ...edit-core/src/main/java/com/sk89q/worldedit/extension/factory/{ → parser}/DefaultBlockParser.java
  7. +7 −5 ...dedit-core/src/main/java/com/sk89q/worldedit/extension/factory/{ → parser}/DefaultItemParser.java
  8. +64 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BiomeMaskParser.java
  9. +55 −0 ...core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java
  10. +61 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java
  11. +51 −0 ...edit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ExistingMaskParser.java
  12. +56 −0 ...it-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ExpressionMaskParser.java
  13. +48 −0 ...it-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/LazyRegionMaskParser.java
  14. +47 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/NegateMaskParser.java
  15. +45 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/NoiseMaskParser.java
  16. +59 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/OffsetMaskParser.java
  17. +52 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RegionMaskParser.java
  18. +51 −0 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/SolidMaskParser.java
  19. +21 −21 ...ldedit/extension/factory/{HashTagPatternParser.java → parser/pattern/ClipboardPatternParser.java}
  20. +4 −3 .../src/main/java/com/sk89q/worldedit/extension/factory/{ → parser/pattern}/RandomPatternParser.java
  21. +3 −3 ...main/java/com/sk89q/worldedit/extension/factory/{ → parser/pattern}/SingleBlockPatternParser.java
  22. +24 −1 worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java
  23. +12 −1 worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/InputParser.java
  24. +71 −0 worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/SimpleInputParser.java
  25. +3 −3 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java
  26. +5 −4 worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java
  27. +9 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java
  28. +7 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java
  29. +3 −5 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java
  30. +5 −5 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java
  31. +9 −0 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java
  32. +6 −13 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java
@@ -21,6 +21,7 @@

import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.DefaultBlockParser;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
@@ -47,7 +48,7 @@
public BlockFactory(WorldEdit worldEdit) {
super(worldEdit);

parsers.add(new DefaultBlockParser(worldEdit));
register(new DefaultBlockParser(worldEdit));
}

/**

This file was deleted.

Oops, something went wrong.
@@ -21,6 +21,7 @@

import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.factory.parser.DefaultItemParser;
import com.sk89q.worldedit.internal.registry.AbstractFactory;

public class ItemFactory extends AbstractFactory<BaseItem> {
@@ -33,7 +34,7 @@
public ItemFactory(WorldEdit worldEdit) {
super(worldEdit);

parsers.add(new DefaultItemParser(worldEdit));
register(new DefaultItemParser(worldEdit));
}

}
@@ -20,8 +20,27 @@
package com.sk89q.worldedit.extension.factory;

import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser;
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
import com.sk89q.worldedit.internal.registry.InputParser;

import java.util.ArrayList;
import java.util.List;

/**
* A registry of known {@link Mask}s. Provides methods to instantiate
@@ -40,7 +59,45 @@
public MaskFactory(WorldEdit worldEdit) {
super(worldEdit);

parsers.add(new DefaultMaskParser(worldEdit));
register(new ExistingMaskParser(worldEdit));
register(new SolidMaskParser(worldEdit));
register(new LazyRegionMaskParser(worldEdit));
register(new RegionMaskParser(worldEdit));
register(new BlockCategoryMaskParser(worldEdit));
register(new OffsetMaskParser(worldEdit));
register(new BiomeMaskParser(worldEdit));
register(new NoiseMaskParser(worldEdit));
register(new NegateMaskParser(worldEdit));
register(new ExpressionMaskParser(worldEdit));
register(new BlocksMaskParser(worldEdit));
}

@Override
public Mask parseFromInput(String input, ParserContext context) throws InputParseException {
List<Mask> masks = new ArrayList<>();

for (String component : input.split(" ")) {
if (component.isEmpty()) {
continue;
}

for (InputParser<Mask> parser : getParsers()) {
Mask match = parser.parseFromInput(component, context);

if (match != null) {
masks.add(match);
}
}
}

switch (masks.size()) {
case 0:
throw new NoMatchException("No match for '" + input + "'");
case 1:
return masks.get(0);
default:
return new MaskIntersection(masks);
}
}

}
@@ -20,6 +20,9 @@
package com.sk89q.worldedit.extension.factory;

import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser;
import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser;
import com.sk89q.worldedit.extension.factory.parser.pattern.SingleBlockPatternParser;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.registry.AbstractFactory;

@@ -40,9 +43,9 @@
public PatternFactory(WorldEdit worldEdit) {
super(worldEdit);

parsers.add(new HashTagPatternParser(worldEdit));
parsers.add(new SingleBlockPatternParser(worldEdit));
parsers.add(new RandomPatternParser(worldEdit));
register(new ClipboardPatternParser(worldEdit));
register(new SingleBlockPatternParser(worldEdit));
register(new RandomPatternParser(worldEdit));
}

}
@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.extension.factory;
package com.sk89q.worldedit.extension.factory.parser;

import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.NotABlockException;
@@ -52,9 +52,9 @@
/**
* Parses block input strings.
*/
class DefaultBlockParser extends InputParser<BlockStateHolder> {
public class DefaultBlockParser extends InputParser<BlockStateHolder> {

protected DefaultBlockParser(WorldEdit worldEdit) {
public DefaultBlockParser(WorldEdit worldEdit) {
super(worldEdit);
}

@@ -17,20 +17,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.extension.factory;
package com.sk89q.worldedit.extension.factory.parser;

import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;

public class DefaultItemParser extends InputParser<BaseItem> {

protected DefaultItemParser(WorldEdit worldEdit) {
public DefaultItemParser(WorldEdit worldEdit) {
super(worldEdit);
}

@@ -53,8 +53,10 @@ public BaseItem parseFromInput(String input, ParserContext context) throws Input
}

if (item == null) {
item = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().createFromId(input.toLowerCase());
ItemType type = ItemTypes.get(input.toLowerCase());
if (type != null) {
item = new BaseItem(type);
}
}

if (item == null) {
Oops, something went wrong.

0 comments on commit 4cc8e9a

Please sign in to comment.