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);
}
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.");
}
}
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;
}
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());
}
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;
}
Aggregations