com.sk89q.worldedit.regions.CuboidRegion Java Examples

The following examples show how to use com.sk89q.worldedit.regions.CuboidRegion. 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: CuboidProcessor.java    From WorldEditSelectionVisualizer with MIT License 6 votes vote down vote up
@Override
public void processSelection(SelectionPoints selection, CuboidRegion region, RegionAdapter regionAdapter, GlobalSelectionConfig config) {
    Vector3d min = regionAdapter.getMinimumPoint();
    Vector3d max = regionAdapter.getMaximumPoint().add(1, 1, 1);
    int height = region.getHeight();
    int width = region.getWidth();
    int length = region.getLength();

    List<Vector3d> bottomCorners = new ArrayList<>(4);
    bottomCorners.add(min);
    bottomCorners.add(min.withX(max.getX()));
    bottomCorners.add(max.withY(min.getY()));
    bottomCorners.add(min.withZ(max.getZ()));

    createLinesFromBottom(selection, bottomCorners, height, config);

    double lineGap = config.secondary().getLinesGap();
    double distance = config.secondary().getPointsDistance();

    if (lineGap > 0 && getPlugin().getConfig().getBoolean("cuboid-top-bottom")) {
        for (double offset = lineGap; offset < width; offset += lineGap) {
            createLine(selection.secondary(), min.add(offset, 0, 0), min.add(offset, 0, length), distance);
            createLine(selection.secondary(), min.add(offset, height, 0), min.add(offset, height, length), distance);
        }
    }
}
 
Example #2
Source File: CuboidRegionSchematicCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CuboidRegion asRegion(Map<String, Tag> tags) {
	ListTag pos1Tag = (ListTag) tags.get("pos1");
	ListTag pos2Tag = (ListTag) tags.get("pos2");
	
	int pos1X = pos1Tag.getInt(0);
	int pos1Y = pos1Tag.getInt(1);
	int pos1Z = pos1Tag.getInt(2);
	
	int pos2X = pos2Tag.getInt(0);
	int pos2Y = pos2Tag.getInt(1);
	int pos2Z = pos2Tag.getInt(2);
	
	Vector pos1 = new Vector(pos1X, pos1Y, pos1Z);
	Vector pos2 = new Vector(pos2X, pos2Y, pos2Z);
	
	return new CuboidRegion(pos1, pos2);
}
 
Example #3
Source File: CuboidRegionSchematicCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(Map<String, Tag> tags, CuboidRegion region) {
	Vector pos1 = region.getPos1();
	Vector pos2 = region.getPos2();
	
	List<IntTag> pos1List = Lists.newArrayList();
	pos1List.add(new IntTag(pos1.getBlockX()));
	pos1List.add(new IntTag(pos1.getBlockY()));
	pos1List.add(new IntTag(pos1.getBlockZ()));
	
	ListTag pos1Tag = new ListTag(IntTag.class, pos1List);
	
	List<IntTag> pos2List = Lists.newArrayList();
	pos2List.add(new IntTag(pos2.getBlockX()));
	pos2List.add(new IntTag(pos2.getBlockY()));
	pos2List.add(new IntTag(pos2.getBlockZ()));
	
	ListTag pos2Tag = new ListTag(IntTag.class, pos2List);
	
	tags.put("pos1", pos1Tag);
	tags.put("pos2", pos2Tag);
}
 
Example #4
Source File: FaweSchematicHandler.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
    TaskManager.IMP.async(new Runnable() {
        @Override
        public void run() {
            Location[] corners = MainUtil.getCorners(world, regions);
            Location pos1 = corners[0];
            Location pos2 = corners[1];
            final CuboidRegion region = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
            final EditSession editSession = new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();

            final int mx = pos1.getX();
            final int my = pos1.getY();
            final int mz = pos1.getZ();

            ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region);

            Clipboard holder = new BlockArrayClipboard(region, clipboard);
            com.sk89q.jnbt.CompoundTag weTag = SchematicWriter.writeTag(holder);
            CompoundTag tag = new CompoundTag((Map<String, Tag>) (Map<?, ?>) weTag.getValue());
            whenDone.run(tag);
        }
    });
}
 
Example #5
Source File: FaweChunkManager.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void swap(final Location pos1, final Location pos2, final Location pos3, final Location pos4, final Runnable whenDone) {
    TaskManager.IMP.async(new Runnable() {
        @Override
        public void run() {
            synchronized (FaweChunkManager.class) {
                EditSession sessionA = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
                EditSession sessionB = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
                CuboidRegion regionA = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
                CuboidRegion regionB = new CuboidRegion(new Vector(pos3.getX(), pos3.getY(), pos3.getZ()), new Vector(pos4.getX(), pos4.getY(), pos4.getZ()));
                ForwardExtentCopy copyA = new ForwardExtentCopy(sessionA, regionA, sessionB, regionB.getMinimumPoint());
                ForwardExtentCopy copyB = new ForwardExtentCopy(sessionB, regionB, sessionA, regionA.getMinimumPoint());
                try {
                    Operations.completeLegacy(copyA);
                    Operations.completeLegacy(copyB);
                    sessionA.flushQueue();
                    sessionB.flushQueue();
                } catch (MaxChangedBlocksException e) {
                    e.printStackTrace();
                }
                TaskManager.IMP.task(whenDone);
            }
        }
    });
}
 
Example #6
Source File: FaweChunkManager.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location pos3, final Runnable whenDone) {
    TaskManager.IMP.async(new Runnable() {
        @Override
        public void run() {
            synchronized (FaweChunkManager.class) {
                EditSession from = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
                EditSession to = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
                CuboidRegion region = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
                ForwardExtentCopy copy = new ForwardExtentCopy(from, region, to, new Vector(pos3.getX(), pos3.getY(), pos3.getZ()));
                try {
                    Operations.completeLegacy(copy);
                    to.flushQueue();
                } catch (MaxChangedBlocksException e) {
                    e.printStackTrace();
                }
            }
            TaskManager.IMP.task(whenDone);
        }
    });
    return true;
}
 
Example #7
Source File: FaweChunkManager.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean regenerateRegion(final Location pos1, final Location pos2, boolean ignore, final Runnable whenDone) {
    TaskManager.IMP.async(new Runnable() {
        @Override
        public void run() {
            synchronized (FaweChunkManager.class) {
                EditSession editSession = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
                World world = editSession.getWorld();
                CuboidRegion region = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
                world.regenerate(region, editSession);
                editSession.flushQueue();
                TaskManager.IMP.task(whenDone);
            }
        }
    });
    return true;
}
 
Example #8
Source File: CuboidRegionXMLCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CuboidRegion asRegion(Element container) {
	Element pos1Element = container.element("pos1");
	Element pos2Element = container.element("pos2");
	
	int x1 = Integer.parseInt(pos1Element.elementText("x"));
	int y1 = Integer.parseInt(pos1Element.elementText("y"));
	int z1 = Integer.parseInt(pos1Element.elementText("z"));
	
	int x2 = Integer.parseInt(pos2Element.elementText("x"));
	int y2 = Integer.parseInt(pos2Element.elementText("y"));
	int z2 = Integer.parseInt(pos2Element.elementText("z"));
	
	Vector pos1 = new Vector(x1, y1, z1);
	Vector pos2 = new Vector(x2, y2, z2);
	
	return new CuboidRegion(pos1, pos2);
}
 
Example #9
Source File: CuboidRegionXMLCodec.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(Element applyTo, CuboidRegion region) {
	Vector pos1 = region.getPos1();
	Vector pos2 = region.getPos2();
	
	Element pos1Element = applyTo.addElement("pos1");
	Element x1Element = pos1Element.addElement("x");
	Element y1Element = pos1Element.addElement("y");
	Element zElement = pos1Element.addElement("z");
	
	Element pos2Element = applyTo.addElement("pos2");
	Element x2Element = pos2Element.addElement("x");
	Element y2Element = pos2Element.addElement("y");
	Element z2Element = pos2Element.addElement("z");
	
	x1Element.addText(String.valueOf(pos1.getBlockX()));
	y1Element.addText(String.valueOf(pos1.getBlockY()));
	zElement.addText(String.valueOf(pos1.getBlockZ()));
	
	x2Element.addText(String.valueOf(pos2.getBlockX()));
	y2Element.addText(String.valueOf(pos2.getBlockY()));
	z2Element.addText(String.valueOf(pos2.getBlockZ()));
}
 
Example #10
Source File: CuboidSpawnpointGenerator.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void generateSpawnpoints(CuboidRegion region, World world, List<Location> spawnpoints, int n) {
	Vector min = region.getMinimumPoint();
	Vector max = region.getMaximumPoint();
	
	int dx = max.getBlockX() - min.getBlockX();
	int dz = max.getBlockZ() - min.getBlockZ();
	int py = max.getBlockY() + 1;
	
	for (int i = 0; i < n; i++) {
		int rx = (int) (Math.random() * dx);
		int rz = (int) (Math.random() * dz);
		
		int px = min.getBlockX() + rx;
		int pz = min.getBlockZ() + rz;
		
		Location location = new Location(world, px + 0.5, py, pz + 0.5);
		spawnpoints.add(location);
	}
}
 
Example #11
Source File: AnvilCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"copy"},
        desc = "Lazily copy chunks to your anvil clipboard"
)
@CommandPermissions("worldedit.anvil.copychunks")
public void copy(Player player, LocalSession session, EditSession editSession, @Selection Region selection) throws WorldEditException {
    if (!(selection instanceof CuboidRegion)) {
        BBC.NO_REGION.send(player);
        return;
    }
    CuboidRegion cuboid = (CuboidRegion) selection;
    String worldName = Fawe.imp().getWorldName(editSession.getWorld());
    FaweQueue tmp = SetQueue.IMP.getNewQueue(worldName, true, false);
    MCAQueue queue = new MCAQueue(tmp);
    Vector origin = session.getPlacementPosition(player);
    MCAClipboard clipboard = new MCAClipboard(queue, cuboid, origin);
    FawePlayer fp = FawePlayer.wrap(player);
    fp.setMeta(FawePlayer.METADATA_KEYS.ANVIL_CLIPBOARD, clipboard);
    BBC.COMMAND_COPY.send(player, selection.getArea());
}
 
Example #12
Source File: AnvilCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Run safely on an existing world within a selection
 *
 * @param player
 * @param editSession
 * @param selection
 * @param filter
 * @param <G>
 * @param <T>
 * @return
 */
@Deprecated
public static <G, T extends MCAFilter<G>> T runWithSelection(Player player, EditSession editSession, Region selection, T filter) {
    if (!(selection instanceof CuboidRegion)) {
        BBC.NO_REGION.send(player);
        return null;
    }
    CuboidRegion cuboid = (CuboidRegion) selection;
    RegionWrapper wrappedRegion = new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
    String worldName = Fawe.imp().getWorldName(editSession.getWorld());
    FaweQueue tmp = SetQueue.IMP.getNewQueue(worldName, true, false);
    MCAQueue queue = new MCAQueue(tmp);
    FawePlayer<Object> fp = FawePlayer.wrap(player);
    fp.checkAllowedRegion(selection);
    recordHistory(fp, editSession.getWorld(), iAnvilHistory -> {
        queue.filterCopy(filter, wrappedRegion, iAnvilHistory);
    });
    return filter;
}
 
Example #13
Source File: SchematicStreamer.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public Clipboard getClipboard() throws IOException {
    try {
        addDimensionReaders();
        addBlockReaders();
        readFully();
        Vector min = new Vector(originX, originY, originZ);
        Vector offset = new Vector(offsetX, offsetY, offsetZ);
        Vector origin = min.subtract(offset);
        Vector dimensions = new Vector(width, height, length);
        fc.setDimensions(dimensions);
        CuboidRegion region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE));
        clipboard.init(region, fc);
        clipboard.setOrigin(origin);
        return clipboard;
    } catch (Throwable e) {
        if (fc != null) {
            fc.close();
        }
        throw e;
    }
}
 
Example #14
Source File: SetBiomeTask.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public SetBiomeTask(uSkyBlock plugin, World world, BlockVector3 minP, BlockVector3 maxP, Biome biome, Runnable onCompletion) {
    super(plugin, onCompletion);
    this.biome = biome;
    this.minP = minP;
    this.maxP = maxP;
    this.world = world;
    chunks = WorldEditHandler.getChunks(new CuboidRegion(minP, maxP));
}
 
Example #15
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetBorderRegionsAligned4Quadrants() throws Exception {
    Region region = new CuboidRegion(BlockVector3.at(-64,0,-64), BlockVector3.at(63, 15, 63));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expectedBorder = new HashSet<>(Arrays.<Region>asList());
    Set<BlockVector2> expectedInner = new HashSet<>();
    for (int x = -4; x <= 3; x++) {
        for (int z = -4; z <= 3; z++) {
            expectedInner.add(BlockVector2.at(x, z));
        }
    }
    verifySame(borderRegions, expectedBorder);
    assertThat(WorldEditHandler.getInnerChunks(region), is(expectedInner));
    assertThat(WorldEditHandler.getOuterChunks(region), is(expectedInner));
}
 
Example #16
Source File: SetBiomeTask.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public SetBiomeTask(uSkyBlock plugin, Location loc, Biome biome, Runnable onCompletion) {
    super(plugin, onCompletion);
    this.biome = biome;
    ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(loc);
    if (region != null) {
        minP = region.getMinimumPoint();
        maxP = region.getMaximumPoint();
    } else {
        minP = null;
        maxP = null;
    }
    world = loc.getWorld();
    chunks = WorldEditHandler.getChunks(new CuboidRegion(minP, maxP));
}
 
Example #17
Source File: ChunkSnapShotTask.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public ChunkSnapShotTask(uSkyBlock plugin, Location location, ProtectedRegion region, final Callback<List<ChunkSnapshot>> callback) {
    super(plugin, callback);
    this.location = location;
    if (region != null) {
        chunks = new ArrayList<>(WorldEditHandler.getChunks(new CuboidRegion(region.getMinimumPoint(), region.getMaximumPoint())));
    } else {
        chunks = new ArrayList<>();
    }
    callback.setState(snapshots);
}
 
Example #18
Source File: IslandLogic.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public boolean clearFlatland(final CommandSender sender, final Location loc, final int delay) {
    if (loc == null) {
        return false;
    }
    if (delay > 0 && !flatlandFix) {
        return false; // Skip
    }
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            final World w = loc.getWorld();
            final int px = loc.getBlockX();
            final int pz = loc.getBlockZ();
            final int py = 0;
            final int range = Math.max(Settings.island_protectionRange, Settings.island_distance) + 1;
            final int radius = range/2;
            // 5 sampling points...
            if (w.getBlockAt(px, py, pz).getType() == BEDROCK
                    || w.getBlockAt(px+radius, py, pz+radius).getType() == BEDROCK
                    || w.getBlockAt(px+radius, py, pz-radius).getType() == BEDROCK
                    || w.getBlockAt(px-radius, py, pz+radius).getType() == BEDROCK
                    || w.getBlockAt(px-radius, py, pz-radius).getType() == BEDROCK)
            {
                sender.sendMessage(String.format("\u00a7c-----------------------------------\n\u00a7cFlatland detected under your island!\n\u00a7e Clearing it in %s, stay clear.\n\u00a7c-----------------------------------\n", TimeUtil.ticksAsString(delay)));
                new WorldEditClearFlatlandTask(plugin, sender, new CuboidRegion(BlockVector3.at(px-radius, 0, pz-radius),
                        BlockVector3.at(px+radius, 4, pz+radius)),
                        "\u00a7eFlatland was cleared under your island (%s). Take care.").runTaskLater(plugin, delay);
            }
        }
    };
    if (Bukkit.isPrimaryThread()) {
        runnable.run();
    } else {
        plugin.sync(runnable);
    }
    return false;
}
 
Example #19
Source File: CuboidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CuboidRegion getRegion() throws IncompleteRegionException {
    if (position1 == null || position2 == null) {
        throw new IncompleteRegionException();
    }

    return region;
}
 
Example #20
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBorderXPosMax() {
    Region region = new CuboidRegion(BlockVector3.at(0,0,0), BlockVector3.at(16, 15, 15));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expected = new HashSet<>(Arrays.<Region>asList(
            new CuboidRegion(BlockVector3.at(16,0,0), BlockVector3.at(16,15,15))
    ));
    verifySame(borderRegions, expected);
}
 
Example #21
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBorderXPosMin() {
    Region region = new CuboidRegion(BlockVector3.at(15,0,0), BlockVector3.at(31, 15, 15));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expected = new HashSet<>(Arrays.<Region>asList(
            new CuboidRegion(BlockVector3.at(15,0,0), BlockVector3.at(15,15,15))
    ));
    verifySame(borderRegions, expected);
}
 
Example #22
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBorderXNegMax() {
    Region region = new CuboidRegion(BlockVector3.at(-16,0,-16), BlockVector3.at(0, 15, -1));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expected = new HashSet<>(Arrays.<Region>asList(
            new CuboidRegion(BlockVector3.at(0,0,-16), BlockVector3.at(0,15,-1))
    ));
    verifySame(borderRegions, expected);
}
 
Example #23
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBorderXNegMin() {
    Region region = new CuboidRegion(BlockVector3.at(-17,0,-16), BlockVector3.at(-1, 15, -1));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expected = new HashSet<>(Arrays.<Region>asList(
            new CuboidRegion(BlockVector3.at(-17,0,-16), BlockVector3.at(-17,15,-1))
    ));
    verifySame(borderRegions, expected);
}
 
Example #24
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBorderZPos() {
    Region region = new CuboidRegion(BlockVector3.at(0,0,0), BlockVector3.at(15, 15, 16));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expected = new HashSet<>(Arrays.<Region>asList(
            new CuboidRegion(BlockVector3.at(0,0,16), BlockVector3.at(15,15,16))
    ));
    verifySame(borderRegions, expected);
}
 
Example #25
Source File: BackwardsExtentBlockCopy.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Operation resume(RunContext run) throws WorldEditException {
    CuboidRegion destRegion = transform(this.transform, this.region);
    Transform inverse = this.transform.inverse();
    for (Vector pt : destRegion) {
        Vector copyFrom = transform(inverse, pt);
        if (region.contains(copyFrom)) {
            function.apply(pt);
        }
    }
    return null;
}
 
Example #26
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <pre>
 *     +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |x=======================x B  |     |     |     |
 *     +-----+-----+|----+-----+-----+-----+|----+-----+-----+-----+
 *     |     |     ||    |     |     |     ||    |     |     |     |
 *     |     |     ||    |     |     |     ||    |     |     |     |
 *     +-----+-----+|----+-----+-----+-----+|----+-----+-----+-----+
 *     |     |     ||    |     |     |     ||    |     |     |     |
 *     |     |     ||    |     | 0,0 |     ||    |     |     |     |
 *     +-----+-----+|----+-----0-----+-----+|----+-----+-----+-----+
 *     |     |     ||    |     |     |     ||    |     |     |     |
 *     |     |     ||    |     |     |     ||    |     |     |     |
 *     +-----+-----+|----+-----+-----+-----+|----+-----+-----+-----+
 *     |     |     || A  |     |     |     ||    |     |     |     |
 *     |     |     |x=======================x    |     |     |     |
 *     +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 *     A = -31, -31
 *     B =  32,  32
 * </pre>
 * @throws Exception
 */
@Test
public void testGetBorderRegionsUnaligned4Quadrants() throws Exception {
    Region region = new CuboidRegion(BlockVector3.at(-31,0,-31), BlockVector3.at(32, 15, 32));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expectedBorder = new HashSet<>(Arrays.<Region>asList(
            new CuboidRegion(BlockVector3.at(-16,0,32), BlockVector3.at(31,15,32)),
            new CuboidRegion(BlockVector3.at(-16,0,-31), BlockVector3.at(31,15,-17)),
            new CuboidRegion(BlockVector3.at(-31,0,-31), BlockVector3.at(-17,15,32)),
            new CuboidRegion(BlockVector3.at(32,0,-31), BlockVector3.at(32,15,32))
            ));
    Set<BlockVector2> expectedInner = new HashSet<>();
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            expectedInner.add(BlockVector2.at(x, z));
        }
    }
    Set<BlockVector2> expectedOuter = new HashSet<>();
    for (int x = -2; x <= 2; x++) {
        for (int z = -2; z <= 2; z++) {
            expectedOuter.add(BlockVector2.at(x, z));
        }
    }

    verifySame(borderRegions, expectedBorder);
    assertThat(WorldEditHandler.getInnerChunks(region), is(expectedInner));
    assertThat(WorldEditHandler.getOuterChunks(region), is(expectedOuter));
}
 
Example #27
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 #28
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 #29
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 #30
Source File: AnvilCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"paste"},
        desc = "Paste chunks from your anvil clipboard",
        help =
                "Paste the chunks from your anvil clipboard.\n" +
                        "The -c flag will align the paste to the chunks.",
        flags = "c"

)
@CommandPermissions("worldedit.anvil.pastechunks")
public void paste(Player player, LocalSession session, EditSession editSession, @Switch('c') boolean alignChunk) throws WorldEditException, IOException {
    FawePlayer fp = FawePlayer.wrap(player);
    MCAClipboard clipboard = fp.getMeta(FawePlayer.METADATA_KEYS.ANVIL_CLIPBOARD);
    if (clipboard == null) {
        fp.sendMessage(BBC.getPrefix() + "You must first use `//anvil copy`");
        return;
    }
    CuboidRegion cuboid = clipboard.getRegion();
    RegionWrapper copyRegion = new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
    final Vector offset = player.getPosition().subtract(clipboard.getOrigin());
    if (alignChunk) {
        offset.setComponents((offset.getBlockX() >> 4) << 4, offset.getBlockY(), (offset.getBlockZ() >> 4) << 4);
    }
    int oX = offset.getBlockX();
    int oZ = offset.getBlockZ();
    RegionWrapper pasteRegion = new RegionWrapper(copyRegion.minX + oX, copyRegion.maxX + oX, copyRegion.minZ + oZ, copyRegion.maxZ + oZ);
    String pasteWorldName = Fawe.imp().getWorldName(editSession.getWorld());
    FaweQueue tmpTo = SetQueue.IMP.getNewQueue(pasteWorldName, true, false);
    MCAQueue copyQueue = clipboard.getQueue();
    MCAQueue pasteQueue = new MCAQueue(tmpTo);

    fp.checkAllowedRegion(pasteRegion);
    recordHistory(fp, editSession.getWorld(), iAnvilHistory -> {
        try {
            pasteQueue.pasteRegion(copyQueue, copyRegion, offset, iAnvilHistory);
        } catch (IOException e) { throw new RuntimeException(e); }
    });
    BBC.COMMAND_PASTE.send(player, player.getPosition().toBlockVector());
}