com.sk89q.worldedit.regions.Polygonal2DRegion Java Examples

The following examples show how to use com.sk89q.worldedit.regions.Polygonal2DRegion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Polygonal2DRegionSchematicCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(Map<String, Tag> tags, Polygonal2DRegion region) {
	List<BlockVector2D> points = region.getPoints();
	int minY = region.getMinimumY();
	int maxY = region.getMaximumY();
	
	List<ListTag> pointList = Lists.newArrayList();
	for (BlockVector2D vector : points) {
		List<IntTag> vectorList = Lists.newArrayList();
		vectorList.add(new IntTag(vector.getBlockX()));
		vectorList.add(new IntTag(vector.getBlockZ()));
		
		ListTag vectorListTag = new ListTag(IntTag.class, vectorList);
		pointList.add(vectorListTag);
	}
	
	ListTag pointListTag = new ListTag(ListTag.class, pointList);
	
	tags.put("points", pointListTag);
	tags.put("minY", new IntTag(minY));
	tags.put("maxY", new IntTag(maxY));
}
 
Example #2
Source File: Polygonal2DRegionXMLCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Polygonal2DRegion asRegion(Element container) {
	Element pointsElement = container.element("points");
	Element minYElement = container.element("minY");
	Element maxYElement = container.element("maxY");
	
	List<Element> pointElementList = pointsElement.elements("point");
	List<BlockVector2D> points = Lists.newArrayList();
	
	for (Element pointElement : pointElementList) {
		int x = Integer.parseInt(pointElement.elementText("x"));
		int z = Integer.parseInt(pointElement.elementText("z"));
		
		BlockVector2D point = new BlockVector2D(x, z);
		points.add(point);
	}
	
	int minY = Integer.parseInt(minYElement.getText());
	int maxY = Integer.parseInt(maxYElement.getText());
	
	return new Polygonal2DRegion((World)null, points, minY, maxY);
}
 
Example #3
Source File: Polygonal2DRegionXMLCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(Element applyTo, Polygonal2DRegion region) {
	List<BlockVector2D> points = region.getPoints();
	int minY = region.getMinimumY();
	int maxY = region.getMaximumY();
	
	Element pointsElement = applyTo.addElement("points");
	for (BlockVector2D point : points) {
		Element pointElement = pointsElement.addElement("point");
		
		pointElement.addElement("x").addText(String.valueOf(point.getBlockX()));
		pointElement.addElement("z").addText(String.valueOf(point.getBlockZ()));
	}
	
	applyTo.addElement("minY").addText(String.valueOf(minY));
	applyTo.addElement("maxY").addText(String.valueOf(maxY));
}
 
Example #4
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean selectPrimary(Vector position, SelectorLimits limits) {
    if (position.equals(pos1)) {
        return false;
    }

    pos1 = position.toBlockVector();
    region = new Polygonal2DRegion(region.getWorld());
    region.addPoint(position);
    region.expandY(position.getBlockY());

    return true;
}
 
Example #5
Source File: CommandInfo.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
private String getRegionTypeName(Region region) {
	String regionType = null;
	if (region instanceof CuboidRegion) {
		regionType = i18n.getString(Messages.Command.CUBOID);
	} else if (region instanceof CylinderRegion) {
		regionType = i18n.getString(Messages.Command.CYLINDRICAL);
	} else if (region instanceof Polygonal2DRegion) {
		regionType = i18n.getString(Messages.Command.POLYGONAL);
	}
	
	return regionType;
}
 
Example #6
Source File: Polygonal2DRegionSchematicCodec.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Polygonal2DRegion asRegion(Map<String, Tag> tags) {
	ListTag pointsListTag = (ListTag) tags.get("points");
	List<Tag> pointList = pointsListTag.getValue();
	List<BlockVector2D> points = Lists.newArrayList();
	
	for (Tag vectorTag : pointList) {
		if (!(vectorTag instanceof ListTag)) {
			continue;
		}
		
		ListTag vectorListTag = (ListTag) vectorTag;
		int x = vectorListTag.getInt(0);
		int z = vectorListTag.getInt(1);
		
		BlockVector2D vector = new BlockVector2D(x, z);
		points.add(vector);
	}
	
	int minY = (int) tags.get("minY").getValue();
	int maxY = (int) tags.get("maxY").getValue();
	
	Polygonal2DRegion region = new Polygonal2DRegion();
	for (BlockVector2D point : points) {
		region.addPoint(point);
	}
	
	region.setMaximumY(maxY);
	region.setMinimumY(minY);
	return region;
}
 
Example #7
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Polygonal2DRegion getRegion() throws IncompleteRegionException {
    if (!isDefined()) {
        throw new IncompleteRegionException();
    }

    return region;
}
 
Example #8
Source File: WorldEditHelper.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
private void registerShapeProcessors() {
    shapeProcessors.put(CuboidRegion.class, new CuboidProcessor(plugin));
    shapeProcessors.put(Polygonal2DRegion.class, new Polygonal2DProcessor(plugin));
    shapeProcessors.put(EllipsoidRegion.class, new EllipsoidProcessor(plugin));
    shapeProcessors.put(CylinderRegion.class, new CylinderProcessor(plugin));
    shapeProcessors.put(ConvexPolyhedralRegion.class, new ConvexPolyhedralProcessor(plugin));

    if (plugin.getCompatibilityHelper().isUsingFawe()) {
        shapeProcessors.put(FawePolyhedralProcessor.getRegionClass(), new FawePolyhedralProcessor(plugin));
    }
}
 
Example #9
Source File: Worldguard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private static Region adapt(ProtectedRegion region) {
    if (region instanceof ProtectedCuboidRegion) {
        return new CuboidRegion(region.getMinimumPoint(), region.getMaximumPoint());
    }
    if (region instanceof GlobalProtectedRegion) {
        return RegionWrapper.GLOBAL();
    }
    if (region instanceof ProtectedPolygonalRegion) {
        ProtectedPolygonalRegion casted = (ProtectedPolygonalRegion) region;
        BlockVector max = region.getMaximumPoint();
        BlockVector min = region.getMinimumPoint();
        return new Polygonal2DRegion(null, casted.getPoints(), min.getBlockY(), max.getBlockY());
    }
    return new AdaptedRegion(region);
}
 
Example #10
Source File: RegionAdapter6.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
@NotNull
@Override
public List<Vector3d> getPolygonalPoints() {
    if (region instanceof Polygonal2DRegion) {
        Polygonal2DRegion polygonalRegion = (Polygonal2DRegion) region;

        return polygonalRegion.getPoints().stream()
                .map(vec -> new Vector3d(vec.getX(), 0, vec.getZ()))
                .collect(Collectors.toList());
    }
    throw new UnsupportedOperationException();
}
 
Example #11
Source File: RegionAdapter7.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
@NotNull
@Override
public List<Vector3d> getPolygonalPoints() {
    if (region instanceof Polygonal2DRegion) {
        Polygonal2DRegion polygonalRegion = (Polygonal2DRegion) region;

        return polygonalRegion.getPoints().stream()
                .map(vec -> new Vector3d(vec.getX(), 0, vec.getZ()))
                .collect(Collectors.toList());
    }
    throw new UnsupportedOperationException();
}
 
Example #12
Source File: Polygonal2DProcessor.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
@Override
public void processSelection(SelectionPoints selection, Polygonal2DRegion region, RegionAdapter regionAdapter, GlobalSelectionConfig config) {
    double minY = regionAdapter.getMinimumPoint().getY();
    int height = region.getHeight();

    List<Vector3d> bottomCorners = new ArrayList<>();

    for (Vector3d vec2d : regionAdapter.getPolygonalPoints()) {
        bottomCorners.add(vec2d.add(0.5, minY, 0.5));
    }

    createLinesFromBottom(selection, bottomCorners, height, config);
}
 
Example #13
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public Polygonal2DRegionSelector(Polygonal2DRegion region) {
    this.region = region;
}
 
Example #14
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Polygonal2DRegion getIncompleteRegion() {
    return region;
}
 
Example #15
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void clear() {
    pos1 = null;
    region = new Polygonal2DRegion(region.getWorld());
}
 
Example #16
Source File: Polygonal2DProcessor.java    From WorldEditSelectionVisualizer with MIT License 4 votes vote down vote up
public Polygonal2DProcessor(WorldEditSelectionVisualizer plugin) {
    super(Polygonal2DRegion.class, plugin);
}
 
Example #17
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create a new selector.
 *
 * @param world the world
 * @param points a list of points
 * @param minY the minimum Y
 * @param maxY the maximum Y
 */
public Polygonal2DRegionSelector(@Nullable World world, List<BlockVector2D> points, int minY, int maxY) {
    checkNotNull(points);
    
    final BlockVector2D pos2D = points.get(0);
    pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ());
    region = new Polygonal2DRegion(world, points, minY, maxY);
}
 
Example #18
Source File: Polygonal2DRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create a new selector with the given world.
 *
 * @param world the world
 */
public Polygonal2DRegionSelector(@Nullable World world) {
    region = new Polygonal2DRegion(world);
}