com.sk89q.worldedit.regions.Region Java Examples

The following examples show how to use com.sk89q.worldedit.regions.Region. 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: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns all the chunks that are fully contained within the region.
 */
public static Set<BlockVector2> getInnerChunks(Region region) {
    Set<BlockVector2> chunks = new HashSet<>();
    int minX = region.getMinimumPoint().getBlockX();
    int minZ = region.getMinimumPoint().getBlockZ();
    int maxX = region.getMaximumPoint().getBlockX();
    int maxZ = region.getMaximumPoint().getBlockZ();
    int cx = minX & 0xF;
    int cz = minZ & 0xF;
    minX = cx != 0 ? minX - cx + 16 : minX;
    minZ = cz != 0 ? minZ - cz + 16 : minZ;
    cx = maxX & 0xF;
    cz = maxZ & 0xF;
    maxX = cx != 15 ? maxX - cx : maxX;
    maxZ = cz != 15 ? maxZ - cz : maxZ;
    for (int x = minX; x < maxX; x += 16) {
        for (int z = minZ; z < maxZ; z += 16) {
            chunks.add(BlockVector2.at(x >> 4, z >> 4));
        }
    }
    return chunks;
}
 
Example #2
Source File: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public static Set<BlockVector2> getOuterChunks(Region region) {
    Set<BlockVector2> chunks = new HashSet<>();
    int minX = region.getMinimumPoint().getBlockX();
    int minZ = region.getMinimumPoint().getBlockZ();
    int maxX = region.getMaximumPoint().getBlockX();
    int maxZ = region.getMaximumPoint().getBlockZ();
    int cx = minX & 0xF;
    int cz = minZ & 0xF;
    minX = minX - cx;
    minZ = minZ - cz;
    cx = maxX & 0xF;
    cz = maxZ & 0xF;
    maxX = cx != 15 ? maxX - cx + 16 : maxX;
    maxZ = cz != 15 ? maxZ - cz + 16 : maxZ;
    for (int x = minX; x < maxX; x += 16) {
        for (int z = minZ; z < maxZ; z += 16) {
            chunks.add(BlockVector2.at(x >> 4, z >> 4));
        }
    }
    return chunks;
}
 
Example #3
Source File: Schematic.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public void paste(Extent extent, WorldData worldData, Vector to, boolean pasteAir, Transform transform) {
    checkNotNull(transform);
    Region region = clipboard.getRegion();
    Extent source = clipboard;
    if (worldData != null && transform != null) {
        source = new BlockTransformExtent(clipboard, transform, worldData.getBlockRegistry());
    }
    ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(), extent, to);
    if (transform != null) {
        copy.setTransform(transform);
    }
    copy.setCopyBiomes(!(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes());
    if (extent instanceof EditSession) {
        EditSession editSession = (EditSession) extent;
        Mask sourceMask = editSession.getSourceMask();
        if (sourceMask != null) {
            new MaskTraverser(sourceMask).reset(extent);
            copy.setSourceMask(sourceMask);
            editSession.setSourceMask(null);
        }
    }
    if (!pasteAir) {
        copy.setSourceMask(new ExistingBlockMask(clipboard));
    }
    Operations.completeBlindly(copy);
}
 
Example #4
Source File: CuboidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a copy of another selector.
 *
 * @param oldSelector another selector
 */
public CuboidRegionSelector(RegionSelector oldSelector) {
    this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());

    if (oldSelector instanceof CuboidRegionSelector) {
        final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;

        position1 = cuboidRegionSelector.position1;
        position2 = cuboidRegionSelector.position2;
    } else {
        final Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            return;
        }

        position1 = oldRegion.getMinimumPoint().toBlockVector();
        position2 = oldRegion.getMaximumPoint().toBlockVector();
    }
    region.setPos1(position1);
    region.setPos2(position2);
}
 
Example #5
Source File: LoseCheckerTask.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
private boolean isInsideDeathzone(Location location, Game game, boolean useLiquidDeathzone) {
	boolean result = false;
	if (useLiquidDeathzone && FLOWING_MATERIALS.contains(location.getBlock().getType())) {
		result = true;
	} else {
		Vector vec = BukkitUtil.toVector(location);
		
		for (Region deathzone : game.getDeathzones().values()) {
			if (deathzone.contains(vec)) {
				//Location is in deathzone
				result = true;
				break;
			}
		}
	}
	
	return result;
}
 
Example #6
Source File: FlagShowBarriers.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
private void calculateSpawnLocations() {
	spawningBarriers.clear();
	
	for (Floor floor : game.getFloors()) {
		Region region = floor.getRegion();
		RegionIterator iterator = new RegionIterator(region);
		
		while (iterator.hasNext()) {
			BlockVector vector = iterator.next();
			Location location = BukkitUtil.toLocation(game.getWorld(), vector);
			Block block = location.getBlock();
			if (block.getType() != Material.BARRIER) {
				continue;
			}
			
			spawningBarriers.add(vector.add(0.5, 0.5, 0.5));
		}
	}
	
	Collections.shuffle(spawningBarriers);
}
 
Example #7
Source File: MaskedFaweQueue.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public void setMask(Region[] mask) {
    switch (mask.length) {
        case 0:
            region = new HeightBoundExtent(this, FaweLimit.MAX.copy(), 0, 255);
            break;
        case 1:
            region = new SingleRegionExtent(this, FaweLimit.MAX.copy(), mask[0]);
            break;
        default:
            region = new MultiRegionExtent(this, FaweLimit.MAX.copy(), mask);
            break;
    }
    if (mask.length == 1) {
        region = new SingleRegionExtent(this, FaweLimit.MAX.copy(), mask[0]);
    } else {
        region = new MultiRegionExtent(this, FaweLimit.MAX.copy(), mask);
    }
}
 
Example #8
Source File: DefaultFloorRegenerator.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
	Clipboard clipboard = floor.getClipboard();
	
	Region region = clipboard.getRegion();
	World world = region.getWorld();
	WorldData data = world.getWorldData();
	
	ClipboardHolder holder = new ClipboardHolder(clipboard, data);
	
	Operation pasteOperation = holder.createPaste(session, data)
			.to(region.getMinimumPoint())
			.ignoreAirBlocks(true)
			.build();
	
	try {
		Operations.complete(pasteOperation);
	} catch (WorldEditException e) {
		throw new RuntimeException(e);
	}
}
 
Example #9
Source File: SelectionCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"/inset"},
        usage = "<amount>",
        desc = "Inset the selection area",
        help =
                "Contracts the selection by the given amount in all directions.\n" +
                        "Flags:\n" +
                        "  -h only contract horizontally\n" +
                        "  -v only contract vertically\n",
        flags = "hv",
        min = 1,
        max = 1
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.inset")
public void inset(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    Region region = session.getSelection(player.getWorld());
    region.contract(getChangesForEachDir(args));
    session.getRegionSelector(player.getWorld()).learnChanges();
    session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
    BBC.SELECTION_INSET.send(player);
}
 
Example #10
Source File: EllipsoidRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new selector from the given selector.
 *
 * @param oldSelector the old selector
 */
public EllipsoidRegionSelector(RegionSelector oldSelector) {
    this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
    if (oldSelector instanceof EllipsoidRegionSelector) {
        final EllipsoidRegionSelector ellipsoidRegionSelector = (EllipsoidRegionSelector) oldSelector;

        region = new EllipsoidRegion(ellipsoidRegionSelector.getIncompleteRegion());
    } else {
        Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            return;
        }

        BlockVector pos1 = oldRegion.getMinimumPoint().toBlockVector();
        BlockVector pos2 = oldRegion.getMaximumPoint().toBlockVector();

        Vector center = pos1.add(pos2).divide(2).floor();
        region.setCenter(center);
        region.setRadius(pos2.subtract(center));
    }
}
 
Example #11
Source File: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static void clearIsland(@NotNull final World islandWorld, @NotNull final ProtectedRegion region,
                               @Nullable final Runnable afterDeletion) {
    Validate.notNull(islandWorld, "IslandWorld cannot be null");
    Validate.notNull(region, "Region cannot be null");

    log.finer("Clearing island " + region);
    uSkyBlock plugin = uSkyBlock.getInstance();
    final long t = System.currentTimeMillis();
    final Region cube = getRegion(islandWorld, region);
    Runnable onCompletion = () -> {
        long diff = System.currentTimeMillis() - t;
        LogUtil.log(Level.INFO, String.format("Cleared island on %s in %d.%03d seconds",
                islandWorld.getName(), (diff / 1000), (diff % 1000)));
        if (afterDeletion != null) {
            afterDeletion.run();
        }
    };
    Set<BlockVector2> innerChunks;
    Set<Region> borderRegions = new HashSet<>();
    if (isOuterPossible()) {
        if (Settings.island_protectionRange == Settings.island_distance) {
            innerChunks = getInnerChunks(cube);
        } else {
            innerChunks = getOuterChunks(cube);
        }
    } else {
        innerChunks = getInnerChunks(cube);
        borderRegions = getBorderRegions(cube);
    }
    List<Chunk> chunkList = new ArrayList<>();
    for (BlockVector2 vector : innerChunks) {
        chunkList.add(islandWorld.getChunkAt(vector.getBlockX(), vector.getBlockZ()));
    }
    WorldEditClear weClear = new WorldEditClear(plugin, islandWorld, borderRegions, onCompletion);
    plugin.getWorldManager().getChunkRegenerator(islandWorld).regenerateChunks(chunkList, weClear);
}
 
Example #12
Source File: GenerationCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"/caves"},
        usage = "[size=8] [freq=40] [rarity=7] [minY=8] [maxY=127] [sysFreq=1] [sysRarity=25] [pocketRarity=0] [pocketMin=0] [pocketMax=3]",
        desc = "Generates caves",
        help = "Generates a cave network"
)
@CommandPermissions("worldedit.generation.caves")
@Logging(PLACEMENT)
public void caves(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region, @Optional("8") int size, @Optional("40") int frequency, @Optional("7") int rarity, @Optional("8") int minY, @Optional("127") int maxY, @Optional("1") int systemFrequency, @Optional("25") int individualRarity, @Optional("0") int pocketChance, @Optional("0") int pocketMin, @Optional("3") int pocketMax, CommandContext context) throws WorldEditException, ParameterException {
    fp.checkConfirmationRegion(() -> {
        CavesGen gen = new CavesGen(size, frequency, rarity, minY, maxY, systemFrequency, individualRarity, pocketChance, pocketMin, pocketMax);
        editSession.generate(region, gen);
        BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount());
    }, getArguments(context), region, context);
}
 
Example #13
Source File: FAWEAdaptor.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void regenerate(final Region region, final Runnable onCompletion) {
    // NOTE: Running this asynchronous MIGHT be a bit dangereous! Since pasting could interfere
    plugin.async(() -> {
        try {
            EditSession editSession = createEditSession(region.getWorld(), -1);
            editSession.regenerate(region);
            editSession.flushQueue();
        } finally {
            onCompletion.run();
        }
    });
}
 
Example #14
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 #15
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 #16
Source File: FaweAdapter7.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
public static List<Vector3d[]> getConvexTriangles(Region region) {
    if (region instanceof PolyhedralRegion) {
        return ((PolyhedralRegion) region).getTriangles().stream()
                .map(FaweAdapter7::triangleToVectors)
                .collect(Collectors.toList());
    }
    throw new UnsupportedOperationException();
}
 
Example #17
Source File: SelectionCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"/shift"},
        usage = "<amount> [direction]",
        desc = "Shift the selection area",
        min = 1,
        max = 2
)
@Logging(REGION)
@CommandPermissions("worldedit.selection.shift")
public void shift(Player player, LocalSession session, CommandContext args) throws WorldEditException {
    List<Vector> dirs = new ArrayList<Vector>();
    int change = args.getInteger(0);
    if (args.argsLength() == 2) {
        if (args.getString(1).contains(",")) {
            for (String s : args.getString(1).split(",")) {
                dirs.add(we.getDirection(player, s.toLowerCase()));
            }
        } else {
            dirs.add(we.getDirection(player, args.getString(1).toLowerCase()));
        }
    } else {
        dirs.add(we.getDirection(player, "me"));
    }

    try {
        Region region = session.getSelection(player.getWorld());

        for (Vector dir : dirs) {
            region.shift(dir.multiply(change));
        }

        session.getRegionSelector(player.getWorld()).learnChanges();

        session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
        BBC.SELECTION_SHIFT.send(player);
    } catch (RegionOperationException e) {
        player.printError(e.getMessage());
    }
}
 
Example #18
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 #19
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 #20
Source File: FaweRegionExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean isGlobal() {
    for (Region region : getRegions()) {
        if (region.isGlobal()) {
            return true;
        }
    }
    return false;
}
 
Example #21
Source File: BlockArrayClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<? extends Entity> getEntities(Region region) {
    List<Entity> filtered = new ArrayList<Entity>();
    for (Entity entity : getEntities()) {
        if (region.contains(entity.getLocation().toVector())) {
            filtered.add(entity);
        }
    }
    return Collections.unmodifiableList(filtered);
}
 
Example #22
Source File: WEManager.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean intersects(final Region region1, final Region region2) {
    Vector rg1P1 = region1.getMinimumPoint();
    Vector rg1P2 = region1.getMaximumPoint();
    Vector rg2P1 = region2.getMinimumPoint();
    Vector rg2P2 = region2.getMaximumPoint();

    return (rg1P1.getBlockX() <= rg2P2.getBlockX()) && (rg1P2.getBlockX() >= rg2P1.getBlockX()) && (rg1P1.getBlockZ() <= rg2P2.getBlockZ()) && (rg1P2.getBlockZ() >= rg2P1.getBlockZ());
}
 
Example #23
Source File: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static void loadRegion(Location location) {
    ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(location);
    World world = location.getWorld();
    Region cube = getRegion(world, region);
    for (BlockVector2 chunk : cube.getChunks()) {
        world.unloadChunk(chunk.getBlockX(), chunk.getBlockZ(), true);
        world.loadChunk(chunk.getBlockX(), chunk.getBlockZ(), false);
    }
}
 
Example #24
Source File: GenerationCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"/ores"},
        desc = "Generates ores",
        help = "Generates ores",
        min = 1,
        max = 1
)
@CommandPermissions("worldedit.generation.ore")
@Logging(PLACEMENT)
public void ores(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, CommandContext context) throws WorldEditException, ParameterException {
    player.checkConfirmationRegion(() -> {
        editSession.addOres(region, mask);
        BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount());
    }, getArguments(context), region, context);
}
 
Example #25
Source File: PolyhedralRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Region getRegion() throws IncompleteRegionException {
    if (!region.isDefined()) {
        throw new IncompleteRegionException();
    }

    return region;
}
 
Example #26
Source File: WorldWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<? extends Entity> getEntities(final Region region) {
    return TaskManager.IMP.sync(new RunnableVal<List<? extends Entity>>() {
        @Override
        public void run(List<? extends Entity> value) {
            this.value = parent.getEntities(region);
        }
    });
}
 
Example #27
Source File: FAWEFloorRegenerator.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
    Clipboard clipboard = floor.getClipboard();
    Schematic faweSchematic = new Schematic(clipboard);

    Region region = clipboard.getRegion();
    World world = region.getWorld();
    if (world == null) {
        throw new IllegalStateException("World of floor " + floor.getName() + " is null!");
    }

    faweSchematic.paste(world, region.getMinimumPoint(), false, false, (Transform) null);
}
 
Example #28
Source File: CylinderRegionSelector.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new selector from the given one.
 *
 * @param oldSelector the old selector
 */
public CylinderRegionSelector(RegionSelector oldSelector) {
    this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());

    if (oldSelector instanceof CylinderRegionSelector) {
        final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;

        region = new CylinderRegion(cylSelector.region);
    } else {
        final Region oldRegion;
        try {
            oldRegion = oldSelector.getRegion();
        } catch (IncompleteRegionException e) {
            return;
        }

        Vector pos1 = oldRegion.getMinimumPoint();
        Vector pos2 = oldRegion.getMaximumPoint();

        Vector center = pos1.add(pos2).divide(2).floor();
        region.setCenter(center.toVector2D());
        region.setRadius(pos2.toVector2D().subtract(center.toVector2D()));

        region.setMaximumY(Math.max(pos1.getBlockY(), pos2.getBlockY()));
        region.setMinimumY(Math.min(pos1.getBlockY(), pos2.getBlockY()));
    }
}
 
Example #29
Source File: ClipboardRemapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void apply(Clipboard clipboard) throws WorldEditException {
    if (clipboard instanceof BlockArrayClipboard) {
        BlockArrayClipboard bac = (BlockArrayClipboard) clipboard;
        bac.IMP = new RemappedClipboard(bac.IMP, this);
    } else {
        Region region = clipboard.getRegion();
        for (BlockVector pos : region) {
            BaseBlock block = clipboard.getBlock(pos);
            BaseBlock newBlock = remap(block);
            if (block != newBlock) {
                clipboard.setBlock(pos, newBlock);
            }
        }
    }
}
 
Example #30
Source File: BlockArrayClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void init(Region region, FaweClipboard fc) {
    checkNotNull(region);
    checkNotNull(fc);
    this.region = region.clone();
    this.size = getDimensions();
    this.IMP = fc;
    this.origin = region.getMinimumPoint();
    this.mx = origin.getBlockX();
    this.my = origin.getBlockY();
    this.mz = origin.getBlockZ();
}