Java Code Examples for com.sk89q.worldedit.math.BlockVector3#at()

The following examples show how to use com.sk89q.worldedit.math.BlockVector3#at() . 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: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isIslandIntersectingSpawn(Location islandLocation) {
    log.entering(CN, "isIslandIntersectingSpawn", islandLocation);
    try {
        int r = Settings.general_spawnSize;
        if (r == 0) {
            return false;
        }
        ProtectedRegion spawn = new ProtectedCuboidRegion("spawn", BlockVector3.at(-r, 0, -r), BlockVector3.at(r, 255, r));
        ProtectedCuboidRegion islandRegion = getIslandRegion(islandLocation);
        return !islandRegion.getIntersectingRegions(Collections.singletonList(spawn)).isEmpty();
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unable to locate intersecting regions", e);
        return false;
    } finally {
        log.exiting(CN, "isIslandIntersectingSpawn");
    }
}
 
Example 2
Source File: WorldGuardApi.java    From ClaimChunk with MIT License 5 votes vote down vote up
static boolean _isAllowedClaim(ClaimChunk claimChunk, Chunk chunk) {
    try {
        // Generate a region in the given chunk to get all intersecting regions
        int bx = chunk.getX() << 4;
        int bz = chunk.getZ() << 4;
        BlockVector3 pt1 = BlockVector3.at(bx, 0, bz);
        BlockVector3 pt2 = BlockVector3.at(bx + 15, 256, bz + 15);
        ProtectedCuboidRegion region = new ProtectedCuboidRegion("_", pt1, pt2);
        RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(chunk.getWorld()));

        // No regions in this world, claiming should be determined by the config
        if (regionManager == null) {
            return claimChunk.chConfig().getBool("worldguard", "allowClaimingInNonGuardedWorlds");
        }

        // If any regions in the given chunk deny chunk claiming, false is returned
        for (ProtectedRegion regionIn : regionManager.getApplicableRegions(region)) {
            StateFlag.State flag = regionIn.getFlag(FLAG_CHUNK_CLAIM);
            if (flag == StateFlag.State.DENY) return false;
        }

        // No objections
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    // An error occurred, better to be on the safe side so false is returned
    return false;
}
 
Example 3
Source File: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static void loadIslandSchematic(final File file, final Location origin, PlayerPerk playerPerk) {
    log.finer("Trying to load schematic " + file);
    if (file == null || !file.exists() || !file.canRead()) {
        LogUtil.log(Level.WARNING, "Unable to load schematic " + file);
    }
    boolean noAir = false;
    BlockVector3 to = BlockVector3.at(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
    EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(origin.getWorld()), -1);
    editSession.setFastMode(true);
    ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(origin);
    if (region != null) {
        editSession.setMask(new RegionMask(getRegion(origin.getWorld(), region)));
    }
    try {
        ClipboardFormat clipboardFormat = ClipboardFormats.findByFile(file);
        try (InputStream in = new FileInputStream(file)) {
            Clipboard clipboard = clipboardFormat.getReader(in).read();
            Operation operation = new ClipboardHolder(clipboard)
                    .createPaste(editSession)
                    .to(to)
                    .ignoreAirBlocks(noAir)
                    .build();
            Operations.completeBlindly(operation);
        }
        editSession.flushSession();
    } catch (IOException e) {
        log.log(Level.INFO, "Unable to paste schematic " + file, e);
    }
}
 
Example 4
Source File: WorldGuardHandler7_beta_2.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<ProtectedRegion> getApplicableRegionsSet(Location location) {
	Set<ProtectedRegion> result = new HashSet<>();
	BlockVector3 vector = BlockVector3.at(location.getX(), location.getY(), location.getZ());
	for(ProtectedRegion region : getRegionManager(location.getWorld()).getRegions().values()) {
		if(region.contains(vector)) {
			result.add(region);
		}
	}
	return result;
}
 
Example 5
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 6
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 7
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static ProtectedCuboidRegion getIslandRegion(Location islandLocation) {
    int r = Settings.island_radius;
    BlockVector3 islandCenter = BlockVector3.at(islandLocation.getBlockX(), 0, islandLocation.getBlockZ());
    return new ProtectedCuboidRegion(
            String.format("%d,%disland", islandCenter.getBlockX(), islandLocation.getBlockZ()),
            getProtectionVectorLeft(islandLocation),
            getProtectionVectorRight(islandLocation));
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
Source File: WorldGuardHandler7_beta_2.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ProtectedCuboidRegion createCuboidRegion(String name, Vector corner1, Vector corner2) {
	return new ProtectedCuboidRegion(name, BlockVector3.at(corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()), BlockVector3.at(corner2.getBlockX(), corner2.getBlockY(), corner2.getBlockZ()));
}
 
Example 14
Source File: WorldEditHandlerTest.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Tests that single blocks overlapping regions gives out 1-wide borders.
 * <pre>
 *     ^
 *     |           +---+---+---+---+---+---+
 *     |           |   |   |   |   |   |   |
 *     |           |   |   |   |   |   |   |
 *     |           +---+---+---+---+---+---+
 *     |         l |   | D=======C |   |   |
 *     |           |   | I |   | I |   |   |
 *     |         k +---+-I-R---Q-I-+---+---+
 *     |           |   | I |   | I |   |   |
 *     |           |   | I |   | I |   |   |
 *     |         j +---+-I-O---P-I-+---+---+
 *     |           |   | I |   | I |   |   |
 *     |         i |   | A=======B |   |   |
 *     |           +---+---+---+---+---+---+
 *     |                 a b   c d
 *     +----------------------------------------->
 *
 * Points:
 *     A = (a,i)
 *     B = (d,i)
 *     C = (d,l)
 *     D = (a,l)
 *
 *     M(x) = X mod 16, i.e. Mc = C mod 16.
 *
 * Borders:
 *     O = A + 16 - Ma   | A > 0
 *       = A - Ma        | A <= 0
 *
 *     Q = C - Mc - 1    | C > 0 && Mc != 15
 *       = C + Mc - 16   | C < 0 && Mc != -1
 * </pre>
 *
 * <pre>
 *     +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |     |     |     |     |     |     |     |     |
 *     +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |x===========x B  |     |     |     |     |     |
 *     +-----+-----+|----+-----+|----+-----+-----+-----+-----+-----+
 *     |     |     ||    |     ||    |     |     |     |     |     |
 *     |     |     ||    |     ||    |     |     |     |     |     |
 *     |     |     ||    |     ||    |     |     |     |     |     |
 *     +-----+-----+|----+-----||----+-----+-----+-----+-----+-----+
 *     |     |     ||    |     ||    |     |     |     |     |     |
 *     |     |     || A  |     ||    |     |     |     |     |     |
 *     |     |     |x===========x    |     |     |     |     |     |
 *     +-----+-----0-----+-----+-----+-----+-----+-----+-----+-----+
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |     |     |     |     |     |     |     |     |
 *     |     |     |     |     |     |     |     |     |     |     |
 *     +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 *     A =   1,   1
 *     B =  32,  32
 * </pre>
 * @throws Exception
 */
@Test
public void testGetBorderRegionsUnalignedPos() throws Exception {
    Region region = new CuboidRegion(BlockVector3.at(1,0,1), BlockVector3.at(32, 15, 32));
    Set<Region> borderRegions = WorldEditHandler.getBorderRegions(region);
    Set<Region> expectedBorder = new HashSet<>(Arrays.<Region>asList(
            new CuboidRegion(BlockVector3.at(1,0,1), BlockVector3.at(15,15,32)),
            new CuboidRegion(BlockVector3.at(32,0,1), BlockVector3.at(32,15,32)),
            new CuboidRegion(BlockVector3.at(16,0,1), BlockVector3.at(31,15,15)),
            new CuboidRegion(BlockVector3.at(16,0,32), BlockVector3.at(31,15,32))
    ));
    Set<BlockVector2> expectedInner = new HashSet<>(Arrays.asList(
            BlockVector2.at(1, 1)
    ));
    verifySame(borderRegions, expectedBorder);
    Set<BlockVector2> innerChunks = WorldEditHandler.getInnerChunks(region);
    assertThat(innerChunks, is(expectedInner));
}
 
Example 15
Source File: BiomeCommand.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean doExecute(String alias, final Player player, PlayerInfo pi, final IslandInfo island, Map<String, Object> data, final String... args) {
    if (args.length == 0) {
        if (!island.hasPerm(player, "canChangeBiome")) {
            player.sendMessage(tr("\u00a7cYou do not have permission to change the biome of your current island."));
        } else {
            player.openInventory(menu.displayBiomeGUI(player)); // Weird, that we show the UI
        }
    }
    if (args.length >= 1) {
        final String biome = args[0].toLowerCase();
        if (!island.hasPerm(player, "canChangeBiome")) {
            player.sendMessage(tr("\u00a74You do not have permission to change the biome of this island!"));
            return true;
        }
        Location location = player.getLocation();
        ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(location);
        if (!plugin.playerIsOnOwnIsland(player) || region == null) {
            player.sendMessage(tr("\u00a7eYou must be on your island to change the biome!"));
            return true;
        }
        if (!biomeExists(biome)) {
            player.sendMessage(tr("\u00a7cYou have misspelled the biome name. Must be one of {0}", BIOMES.keySet()));
            return true;
        }
        int cooldown = plugin.getCooldownHandler().getCooldown(player, "biome");
        if (cooldown > 0) {
            player.sendMessage(tr("\u00a7eYou can change your biome again in {0,number,#} minutes.", cooldown / 60));
            return true;
        }
        if (!player.hasPermission("usb.biome." + biome.toLowerCase())) {
            player.sendMessage(tr("\u00a7cYou do not have permission to change your biome to that type."));
            return true;
        }
        BlockVector3 minP = region.getMinimumPoint();
        BlockVector3 maxP = region.getMaximumPoint();
        if (args.length == 2 && args[1].matches("[0-9]+")) {
            int radius = Integer.parseInt(args[1], 10);
            Location loc = location.clone().add(-radius, 0, -radius);
            if (region.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
                minP = BlockVector3.at(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
            }
            loc = location.clone().add(radius, 0, radius);
            if (region.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
                maxP = BlockVector3.at(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
            }
            player.sendMessage(tr("\u00a77The pixies are busy changing the biome near you to \u00a79{0}\u00a77, be patient.", biome));
        } else if (args.length == 2 && args[1].equalsIgnoreCase("chunk")) {
            Chunk chunk = location.clone().getChunk();
            minP = BlockVector3.at(chunk.getX() << 4, 0, chunk.getZ() << 4);
            maxP = BlockVector3.at((chunk.getX() << 4) + 15, location.getWorld().getMaxHeight(), (chunk.getZ() << 4) + 15);
            player.sendMessage(tr("\u00a77The pixies are busy changing the biome in your current chunk to \u00a79{0}\u00a77, be patient.", biome));
        } else if (args.length < 2 || args[1].equalsIgnoreCase("all")) {
            player.sendMessage(tr("\u00a77The pixies are busy changing the biome of your island to \u00a79{0}\u00a77, be patient.", biome));
        }
        Biome biomeEnum = BIOMES.get(biome);
        if (biomeEnum == null) {
            player.sendMessage(tr("\u00a7eInvalid biome {0} supplied!", biome));
            return true;
        }
        new SetBiomeTask(plugin, player.getWorld(), minP, maxP, biomeEnum, () -> {
            if (args.length == 1) {
                island.setBiome(biome);
                player.sendMessage(tr("\u00a7aYou have changed your island''s biome to {0}", biome.toUpperCase()));
                island.sendMessageToIslandGroup(true, marktr("{0} changed the island biome to {1}"), player.getName(), biome.toUpperCase());
                plugin.getCooldownHandler().resetCooldown(player, "biome", Settings.general_biomeChange);
            } else {
                player.sendMessage(tr("\u00a7aYou have changed {0} blocks around you to the {1} biome", args[1], biome.toUpperCase()));
                island.sendMessageToIslandGroup(true, marktr("{0} created an area with {1} biome"), player.getName(), biome.toUpperCase());
            }
        }).runTask(plugin);
    }
    return true;
}
 
Example 16
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
public static BlockVector3 asVector(Location location) {
    if (location == null) {
        return BlockVector3.at(0, 0, 0);
    }
    return toVector(location);
}
 
Example 17
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private static BlockVector3 toVector(Location location) {
    return BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
 
Example 18
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
public static BlockVector3 getProtectionVectorRight(final Location island) {
    return BlockVector3.at(island.getX() - Settings.island_radius, 0.0, island.getZ() - Settings.island_radius);
}
 
Example 19
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
public static BlockVector3 getProtectionVectorLeft(final Location island) {
    return BlockVector3.at(island.getX() + Settings.island_radius - 1, 255.0, island.getZ() + Settings.island_radius - 1);
}
 
Example 20
Source File: Vectors7.java    From WorldEditSelectionVisualizer with MIT License 4 votes vote down vote up
@NotNull
public static BlockVector3 toBlockVector3(Vector3d vec) {
    return BlockVector3.at(vec.getX(), vec.getY(), vec.getZ());
}