Search in sources :

Example 16 with Pattern

use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.

the class PatternFactory method parseFromInput.

@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    List<Pattern> patterns = new ArrayList<>();
    for (String component : input.split(" ")) {
        if (component.isEmpty()) {
            continue;
        }
        // FAWE start - rich pattern parsing
        Pattern match = richPatternParser.parseFromInput(component, context);
        if (match != null) {
            patterns.add(match);
            continue;
        }
        parseFromParsers(context, patterns, component);
    // FAWE end
    }
    return getPattern(input, patterns);
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) ArrayList(java.util.ArrayList)

Example 17 with Pattern

use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.

the class PatternTraverser method reset.

@SuppressWarnings({ "unchecked" })
private void reset(Object pattern, Extent newExtent) {
    if (pattern == null) {
        return;
    }
    if (pattern instanceof Resettable) {
        ((Resettable) pattern).reset();
    }
    Class<?> current = pattern.getClass();
    while (current.getSuperclass() != null) {
        if (newExtent != null) {
            try {
                Field field = current.getDeclaredField("extent");
                field.setAccessible(true);
                field.set(pattern, newExtent);
            } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
            }
        }
        try {
            Field field = current.getDeclaredField("pattern");
            field.setAccessible(true);
            Object next = field.get(pattern);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
        }
        try {
            Field field = current.getDeclaredField("mask");
            field.setAccessible(true);
            Object next = field.get(pattern);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException ignored) {
        }
        try {
            Field field = current.getDeclaredField("material");
            field.setAccessible(true);
            Pattern next = (Pattern) field.get(pattern);
            reset(next, newExtent);
        } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
        }
        try {
            Field field = current.getDeclaredField("patterns");
            field.setAccessible(true);
            Collection<Pattern> patterns = (Collection<Pattern>) field.get(pattern);
            for (Pattern next : patterns) {
                reset(next, newExtent);
            }
        } catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
        }
        current = current.getSuperclass();
    }
}
Also used : Field(java.lang.reflect.Field) Pattern(com.sk89q.worldedit.function.pattern.Pattern) Collection(java.util.Collection) Resettable(com.fastasyncworldedit.core.Resettable)

Example 18 with Pattern

use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.

the class PatternTransformParser method parseFromInput.

@Override
protected ResettableExtent parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
    if (arguments.length > 2) {
        return null;
    }
    Pattern pattern = worldEdit.getPatternFactory().parseFromInput(arguments[0], context);
    Extent extent = arguments.length == 2 ? worldEdit.getTransformFactory().parseFromInput(arguments[1], context) : context.requireExtent();
    return new PatternTransform(extent, pattern);
}
Also used : Pattern(com.sk89q.worldedit.function.pattern.Pattern) ResettableExtent(com.fastasyncworldedit.core.extent.ResettableExtent) Extent(com.sk89q.worldedit.extent.Extent) PatternTransform(com.fastasyncworldedit.core.extent.transform.PatternTransform)

Example 19 with Pattern

use of com.sk89q.worldedit.function.pattern.Pattern in project PrivateMines by UntouchedOdin0.

the class Mine method expand.

public void expand() {
    final World world = privateMines.getMineWorldManager().getMinesWorld();
    boolean canExpand = canExpand(1);
    if (!canExpand) {
        privateMines.getLogger().info("Failed to expand the mine due to the mine being too large");
    } else {
        final var fillType = BlockTypes.DIAMOND_BLOCK;
        final var wallType = BlockTypes.BEDROCK;
        final var min = getMineData().getMinimumMining();
        final var max = getMineData().getMaximumMining();
        final Region mine = new CuboidRegion(BukkitAdapter.asBlockVector(min), BukkitAdapter.asBlockVector(max));
        final Region fillAir = new CuboidRegion(BukkitAdapter.asBlockVector(min), BukkitAdapter.asBlockVector(max));
        final Region walls = new CuboidRegion(BukkitAdapter.asBlockVector(min), BukkitAdapter.asBlockVector(max));
        if (fillType == null || wallType == null)
            return;
        mine.expand(ExpansionUtils.expansionVectors(1));
        walls.expand(ExpansionUtils.expansionVectors(1));
        walls.expand(BlockVector3.UNIT_X, BlockVector3.UNIT_Y, BlockVector3.UNIT_Z, BlockVector3.UNIT_MINUS_X, BlockVector3.UNIT_MINUS_Y, BlockVector3.UNIT_MINUS_Z);
        fillAir.expand(BlockVector3.UNIT_X, BlockVector3.UNIT_Y, BlockVector3.UNIT_Z, BlockVector3.UNIT_MINUS_X, BlockVector3.UNIT_MINUS_Z);
        Map<Material, Double> materials = mineData.getMineType().getMaterials();
        final RandomPattern randomPattern = new RandomPattern();
        if (materials != null) {
            materials.forEach((material, chance) -> {
                Pattern pattern = BukkitAdapter.adapt(material.createBlockData());
                randomPattern.add(pattern, chance);
            });
        }
        try (EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(BukkitAdapter.adapt(world)).fastMode(true).build()) {
            editSession.setBlocks(walls, BukkitAdapter.adapt(Material.BEDROCK.createBlockData()));
            editSession.setBlocks(fillAir, BukkitAdapter.adapt(Material.AIR.createBlockData()));
        }
        mineData.setMinimumMining(BukkitAdapter.adapt(world, mine.getMinimumPoint()));
        mineData.setMaximumMining(BukkitAdapter.adapt(world, mine.getMaximumPoint()));
        mineData.setMinimumFullRegion(mineData.getMinimumFullRegion().subtract(1, 1, 1));
        mineData.setMaximumFullRegion(mineData.getMaximumFullRegion().add(1, 1, 1));
        setMineData(mineData);
        privateMines.getMineStorage().replaceMine(mineData.getMineOwner(), this);
        reset();
    }
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) EditSession(com.sk89q.worldedit.EditSession)

Example 20 with Pattern

use of com.sk89q.worldedit.function.pattern.Pattern in project bteConoSurCore by BTEConoSur.

the class Polywall method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (command.getName().equals("/polywalls")) {
        if (sender instanceof Player) {
            Player p = (Player) sender;
            // 
            // GET REGION
            Region region = null;
            try {
                region = getSelection(p);
            } catch (IncompleteRegionException e) {
                p.sendMessage(wePrefix + "Selecciona un área primero.");
                return true;
            }
            if (args.length > 0) {
                // PARSE PATTERN
                com.sk89q.worldedit.entity.Player actor = new BukkitPlayer((WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"), ((WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit")).getServerInterface(), p);
                LocalSession localSession = WorldEdit.getInstance().getSessionManager().get(actor);
                Mask mask = localSession.getMask();
                ParserContext parserContext = new ParserContext();
                parserContext.setActor(actor);
                Extent extent = ((Entity) actor).getExtent();
                if (extent instanceof World) {
                    parserContext.setWorld((World) extent);
                }
                parserContext.setSession(WorldEdit.getInstance().getSessionManager().get(actor));
                Pattern pattern;
                try {
                    pattern = WorldEdit.getInstance().getPatternFactory().parseFromInput(args[0], parserContext);
                } catch (InputParseException e) {
                    p.sendMessage(wePrefix + "Patrón inválido.");
                    return true;
                }
                // GET POINTS
                List<BlockVector2D> points = new ArrayList<>();
                int maxY;
                int minY;
                if (region instanceof CuboidRegion) {
                    CuboidRegion cuboidRegion = (CuboidRegion) region;
                    Vector first = cuboidRegion.getPos1();
                    Vector second = cuboidRegion.getPos2();
                    maxY = cuboidRegion.getMaximumY();
                    minY = cuboidRegion.getMinimumY();
                    points.add(new BlockVector2D(first.getX(), first.getZ()));
                    points.add(new BlockVector2D(second.getX(), first.getZ()));
                    points.add(new BlockVector2D(second.getX(), second.getZ()));
                    points.add(new BlockVector2D(first.getX(), second.getZ()));
                } else if (region instanceof Polygonal2DRegion) {
                    maxY = ((Polygonal2DRegion) region).getMaximumY();
                    minY = ((Polygonal2DRegion) region).getMinimumY();
                    points = ((Polygonal2DRegion) region).getPoints();
                } else {
                    p.sendMessage(wePrefix + "Debes seleccionar una region cúbica o poligonal.");
                    return true;
                }
                if (points.size() < 3) {
                    p.sendMessage(wePrefix + "Selecciona un área primero.");
                    return true;
                }
                List<BlockVector2D> pointsFinal = new ArrayList<>(points);
                pointsFinal.add(points.get(0));
                EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession((World) new BukkitWorld(mainWorld), WorldEdit.getInstance().getSessionManager().get(actor).getBlockChangeLimit());
                for (int i = minY; i <= maxY; i++) {
                    for (int j = 0; j < pointsFinal.size() - 1; j++) {
                        BlockVector2D v1 = pointsFinal.get(j);
                        BlockVector2D v2 = pointsFinal.get(j + 1);
                        setBlocksInLine(p, actor, editSession, pattern, mask, v1.toVector(i), v2.toVector(i));
                    }
                }
                p.sendMessage(wePrefix + "Paredes de la selección creadas.");
            } else {
                p.sendMessage(wePrefix + "Introduce un patrón de bloques.");
            }
        }
    }
    return true;
}
Also used : Entity(com.sk89q.worldedit.entity.Entity) Pattern(com.sk89q.worldedit.function.pattern.Pattern) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer) Player(org.bukkit.entity.Player) Extent(com.sk89q.worldedit.extent.Extent) Mask(com.sk89q.worldedit.function.mask.Mask) ArrayList(java.util.ArrayList) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BteConoSur.mainWorld(pizzaaxx.bteconosur.BteConoSur.mainWorld) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BukkitPlayer(com.sk89q.worldedit.bukkit.BukkitPlayer) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) ParserContext(com.sk89q.worldedit.extension.input.ParserContext)

Aggregations

Pattern (com.sk89q.worldedit.function.pattern.Pattern)23 RandomPattern (com.sk89q.worldedit.function.pattern.RandomPattern)11 EditSession (com.sk89q.worldedit.EditSession)7 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)7 Region (com.sk89q.worldedit.regions.Region)7 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 ParserContext (com.sk89q.worldedit.extension.input.ParserContext)4 World (com.sk89q.worldedit.world.World)4 IOException (java.io.IOException)4 MineData (me.untouchedodin0.privatemines.mine.data.MineData)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Caption (com.fastasyncworldedit.core.configuration.Caption)2 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)2 WorldEdit (com.sk89q.worldedit.WorldEdit)2 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)2 NoMatchException (com.sk89q.worldedit.extension.input.NoMatchException)2 Extent (com.sk89q.worldedit.extent.Extent)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2