Search in sources :

Example 1 with Polygonal2DRegion

use of com.sk89q.worldedit.regions.Polygonal2DRegion in project FastAsyncWorldEdit by IntellectualSites.

the class AbstractPlayerActor method setSelection.

@Override
public void setSelection(Region region) {
    RegionSelector selector;
    if (region instanceof ConvexPolyhedralRegion) {
        selector = new ConvexPolyhedralRegionSelector((ConvexPolyhedralRegion) region);
    } else if (region instanceof CylinderRegion) {
        selector = new CylinderRegionSelector((CylinderRegion) region);
    } else if (region instanceof Polygonal2DRegion) {
        selector = new Polygonal2DRegionSelector((Polygonal2DRegion) region);
    } else {
        selector = new CuboidRegionSelector(null, region.getMinimumPoint(), region.getMaximumPoint());
    }
    selector.setWorld(region.getWorld());
    getSession().setRegionSelector(getWorld(), selector);
}
Also used : CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) RegionSelector(com.sk89q.worldedit.regions.RegionSelector) ConvexPolyhedralRegionSelector(com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector) Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) ConvexPolyhedralRegion(com.sk89q.worldedit.regions.ConvexPolyhedralRegion) CylinderRegion(com.sk89q.worldedit.regions.CylinderRegion) CylinderRegionSelector(com.sk89q.worldedit.regions.selector.CylinderRegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector)

Example 2 with Polygonal2DRegion

use of com.sk89q.worldedit.regions.Polygonal2DRegion in project WorldGuard by EngineHub.

the class RegionCommandsBase method checkRegionFromSelection.

/**
 * Create a {@link ProtectedRegion} from the actor's selection.
 *
 * @param actor the actor
 * @param id the ID of the new region
 * @return a new region
 * @throws CommandException thrown on an error
 */
protected static ProtectedRegion checkRegionFromSelection(Actor actor, String id) throws CommandException {
    Region selection = checkSelection(actor);
    // Detect the type of region from WorldEdit
    if (selection instanceof Polygonal2DRegion) {
        Polygonal2DRegion polySel = (Polygonal2DRegion) selection;
        int minY = polySel.getMinimumPoint().getBlockY();
        int maxY = polySel.getMaximumPoint().getBlockY();
        return new ProtectedPolygonalRegion(id, polySel.getPoints(), minY, maxY);
    } else if (selection instanceof CuboidRegion) {
        BlockVector3 min = selection.getMinimumPoint();
        BlockVector3 max = selection.getMaximumPoint();
        return new ProtectedCuboidRegion(id, min, max);
    } else {
        throw new CommandException("Sorry, you can only use cuboids and polygons for WorldGuard regions.");
    }
}
Also used : Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) CommandException(com.sk89q.minecraft.util.commands.CommandException) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 3 with Polygonal2DRegion

use of com.sk89q.worldedit.regions.Polygonal2DRegion in project FastAsyncWorldEdit by IntellectualSites.

the class Polygonal2DRegionSelector method selectPrimary.

@Override
public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) {
    if (position.equals(pos1)) {
        return false;
    }
    pos1 = position;
    region = new Polygonal2DRegion(region.getWorld());
    region.addPoint(position);
    region.expandY(position.getBlockY());
    return true;
}
Also used : Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion)

Example 4 with Polygonal2DRegion

use of com.sk89q.worldedit.regions.Polygonal2DRegion in project FastAsyncWorldEdit by IntellectualSites.

the class Polygonal2DRegionSelector method clear.

@Override
public void clear() {
    pos1 = null;
    region = new Polygonal2DRegion(region.getWorld());
}
Also used : Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion)

Example 5 with Polygonal2DRegion

use of com.sk89q.worldedit.regions.Polygonal2DRegion 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

Polygonal2DRegion (com.sk89q.worldedit.regions.Polygonal2DRegion)5 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 Region (com.sk89q.worldedit.regions.Region)2 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)1 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)1 Entity (com.sk89q.worldedit.entity.Entity)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 ParserContext (com.sk89q.worldedit.extension.input.ParserContext)1 Extent (com.sk89q.worldedit.extent.Extent)1 Mask (com.sk89q.worldedit.function.mask.Mask)1 Pattern (com.sk89q.worldedit.function.pattern.Pattern)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 ConvexPolyhedralRegion (com.sk89q.worldedit.regions.ConvexPolyhedralRegion)1 CylinderRegion (com.sk89q.worldedit.regions.CylinderRegion)1 RegionSelector (com.sk89q.worldedit.regions.RegionSelector)1 ConvexPolyhedralRegionSelector (com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector)1 CuboidRegionSelector (com.sk89q.worldedit.regions.selector.CuboidRegionSelector)1 CylinderRegionSelector (com.sk89q.worldedit.regions.selector.CylinderRegionSelector)1 Polygonal2DRegionSelector (com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector)1