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