Java Code Examples for org.bukkit.Location#setZ()
The following examples show how to use
org.bukkit.Location#setZ() .
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: ClaimChecks.java From WildernessTp with MIT License | 6 votes |
private boolean checkSurroundingWGClaims(Location loc){ if(wild.getConfig().getBoolean("WorldGuard")){ int distance = range / 2; Vector top = new Vector(loc.getX() + distance, loc.getY(), loc.getZ() + distance); Vector bottom = new Vector(loc.getX() - distance, loc.getY(), loc.getZ() - distance); for (int z = bottom.getBlockZ(); z <= top.getBlockZ(); z++) { for (int x = bottom.getBlockX(); x <= top.getBlockX(); x++) { loc.setX(x); loc.setY(Bukkit.getWorld(loc.getWorld().getName()).getHighestBlockYAt(x, z)); loc.setZ(z); if (!WorldGuardWrapper.getInstance().getRegions(loc).isEmpty()) return true; } } } return false; }
Example 2
Source File: VersionUtils_1_14.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@Override public void handleNetherPortalEvent(PlayerPortalEvent event){ Location loc = event.getFrom(); MainConfiguration cfg = GameManager.getGameManager().getConfiguration(); if (event.getFrom().getWorld().getEnvironment() == World.Environment.NETHER){ loc.setWorld(Bukkit.getWorld(cfg.getOverworldUuid())); loc.setX(loc.getX() * 2d); loc.setZ(loc.getZ() * 2d); event.setTo(loc); }else{ loc.setWorld(Bukkit.getWorld(cfg.getNetherUuid())); loc.setX(loc.getX() / 2d); loc.setZ(loc.getZ() / 2d); event.setTo(loc); } }
Example 3
Source File: FireworkShow.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
public static void launchRandom(Player p, int amount) { for (int i = 0; i < amount; i++) { Location l = p.getLocation().clone(); l.setX(l.getX() + CSCoreLib.randomizer().nextInt(amount)); l.setX(l.getX() - CSCoreLib.randomizer().nextInt(amount)); l.setZ(l.getZ() + CSCoreLib.randomizer().nextInt(amount)); l.setZ(l.getZ() - CSCoreLib.randomizer().nextInt(amount)); launchFirework(l, getColors()[CSCoreLib.randomizer().nextInt(getColors().length)]); } }
Example 4
Source File: IslandLocatorLogic.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
/** * <pre> * z * x = -z ^ x = z * \ -x < z | x < z / * \ | / * \ | / * \ | / * \ | / x > z * -x > z \ | / * \ | / * -----------------------+-----------------------------> x * / | \ * -x > -z / | \ * (x < z) / | \ x > -z * / | \ * / | \ * / -x < -z | x < -z \ * x = z | x = -z * | * v * </pre> */ static Location nextIslandLocation(final Location lastIsland) { int d = Settings.island_distance; LocationUtil.alignToDistance(lastIsland, d); int x = lastIsland.getBlockX(); int z = lastIsland.getBlockZ(); if (x < z) { if (-1 * x < z) { x += d; } else { z += d; } } else if (x > z) { if (-1 * x >= z) { x -= d; } else { z -= d; } } else { // x == z if (x <= 0) { z += d; } else { z -= d; } } lastIsland.setX(x); lastIsland.setZ(z); return lastIsland; }
Example 5
Source File: Transporter.java From AnnihilationPro with MIT License | 5 votes |
private Location getMiddle(Location loc) { Location k = loc.clone(); k.setX(k.getBlockX()+0.5); //k.setY(k.getBlockY()+0.5); k.setZ(k.getBlockZ()+0.5); return k; }
Example 6
Source File: MoveEvent.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void frozenSpawnHandler(PlayerMoveEvent e) { /* Optimization for single game world. No longer works since support for multiple worlds was added *if(e.getPlayer().getWorld()!=SettingsManager.getGameWorld()) return;*/ if(GameManager.getInstance().getPlayerGameId(e.getPlayer()) == -1){ playerpos.remove(e.getPlayer()); return; } if(GameManager.getInstance().getGame(GameManager.getInstance().getPlayerGameId(e.getPlayer())).getMode() == Game.GameMode.INGAME) return; GameMode mo3 = GameManager.getInstance().getGameMode(GameManager.getInstance().getPlayerGameId(e.getPlayer())); if(GameManager.getInstance().isPlayerActive(e.getPlayer()) && mo3 != Game.GameMode.INGAME){ if(playerpos.get(e.getPlayer()) == null){ playerpos.put(e.getPlayer(), e.getPlayer().getLocation().toVector()); return; } Location l = e.getPlayer().getLocation(); Vector v = playerpos.get(e.getPlayer()); if(l.getBlockX() != v.getBlockX() || l.getBlockZ() != v.getBlockZ()){ l.setX(v.getBlockX() + .5); l.setZ(v.getBlockZ() + .5); l.setYaw(e.getPlayer().getLocation().getYaw()); l.setPitch(e.getPlayer().getLocation().getPitch()); e.getPlayer().teleport(l); } } }
Example 7
Source File: WaterStructure.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override protected Location repositionCenter(Location center, String dir, double x_size, double z_size) { Location loc = new Location(center.getWorld(), center.getX(), center.getY(), center.getZ(), center.getYaw(), center.getPitch()); // Reposition tile improvements if (this.isTileImprovement()) { // just put the center at 0,0 of this chunk? loc = center.getChunk().getBlock(0, center.getBlockY(), 0).getLocation(); //loc = center.getChunk().getBlock(arg0, arg1, arg2) } else { if (dir.equalsIgnoreCase("east")) { loc.setZ(loc.getZ() - (z_size / 2)); loc.setX(loc.getX() + SHIFT_OUT); } else if (dir.equalsIgnoreCase("west")) { loc.setZ(loc.getZ() - (z_size / 2)); loc.setX(loc.getX() - (SHIFT_OUT+x_size)); } else if (dir.equalsIgnoreCase("north")) { loc.setX(loc.getX() - (x_size / 2)); loc.setZ(loc.getZ() - (SHIFT_OUT+z_size)); } else if (dir.equalsIgnoreCase("south")) { loc.setX(loc.getX() - (x_size / 2)); loc.setZ(loc.getZ() + SHIFT_OUT); } } if (this.getTemplateYShift() != 0) { // Y-Shift based on the config, this allows templates to be built underground. loc.setY(WATER_LEVEL + this.getTemplateYShift()); } return loc; }
Example 8
Source File: FireworkUtils.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
public static void launchRandom(Entity n, int amount) { for (int i = 0; i < amount; i++) { Location l = n.getLocation().clone(); l.setX(l.getX() + ThreadLocalRandom.current().nextInt(amount)); l.setX(l.getX() - ThreadLocalRandom.current().nextInt(amount)); l.setZ(l.getZ() + ThreadLocalRandom.current().nextInt(amount)); l.setZ(l.getZ() - ThreadLocalRandom.current().nextInt(amount)); launchFirework(l, getRandomColor()); } }
Example 9
Source File: CraftBlock.java From Thermos with GNU General Public License v3.0 | 5 votes |
public Location getLocation(Location loc) { if (loc != null) { loc.setWorld(getWorld()); loc.setX(x); loc.setY(y); loc.setZ(z); loc.setYaw(0); loc.setPitch(0); } return loc; }
Example 10
Source File: WorldBorderUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static boolean clampToBorder(Location location) { WorldBorder border = location.getWorld().getWorldBorder(); Location center = border.getCenter(); double radius = border.getSize() / 2d; double xMin = center.getX() - radius; double xMax = center.getX() + radius; double zMin = center.getZ() - radius; double zMax = center.getZ() + radius; boolean moved = false; if(location.getX() < xMin) { location.setX(xMin); moved = true; } if(location.getX() > xMax) { location.setX(xMax); moved = true; } if(location.getZ() < zMin) { location.setZ(zMin); moved = true; } if(location.getZ() > zMax) { location.setZ(zMax); moved = true; } return moved; }
Example 11
Source File: Post.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private Location roundToBlock(Location loc) { Location newLoc = loc.clone(); newLoc.setX(Math.floor(loc.getX()) + 0.5); newLoc.setY(Math.floor(loc.getY())); newLoc.setZ(Math.floor(loc.getZ()) + 0.5); return newLoc; }
Example 12
Source File: CraftBlockState.java From Thermos with GNU General Public License v3.0 | 5 votes |
public Location getLocation(Location loc) { if (loc != null) { loc.setWorld(world); loc.setX(x); loc.setY(y); loc.setZ(z); loc.setYaw(0); loc.setPitch(0); } return loc; }
Example 13
Source File: CraftBlockState.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Location getLocation(Location loc) { if (loc != null) { loc.setWorld(world); loc.setX(x); loc.setY(y); loc.setZ(z); loc.setYaw(0); loc.setPitch(0); } return loc; }
Example 14
Source File: CraftEntity.java From Thermos with GNU General Public License v3.0 | 5 votes |
public Location getLocation(Location loc) { if (loc != null) { loc.setWorld(getWorld()); loc.setX(entity.posX); loc.setY(entity.posY); loc.setZ(entity.posZ); loc.setYaw(entity.rotationYaw); loc.setPitch(entity.rotationPitch); } return loc; }
Example 15
Source File: CraftEntity.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Location getLocation(Location loc) { if (loc != null) { loc.setWorld(getWorld()); loc.setX(entity.posX); loc.setY(entity.posY); loc.setZ(entity.posZ); loc.setYaw(entity.getBukkitYaw()); loc.setPitch(entity.rotationPitch); } return loc; }
Example 16
Source File: Post.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private Location roundToBlock(Location loc) { Location newLoc = loc.clone(); newLoc.setX(Math.floor(loc.getX()) + 0.5); newLoc.setY(Math.floor(loc.getY())); newLoc.setZ(Math.floor(loc.getZ()) + 0.5); return newLoc; }
Example 17
Source File: Explosive.java From ce with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void effect(Event e, ItemStack item, int level) { BlockBreakEvent event = (BlockBreakEvent) e; Player player = event.getPlayer(); if (!isUsable(player.getItemInHand().getType().toString(), event.getBlock().getType().toString())) return; List<Location> locations = new ArrayList<Location>(); int locRad = Radius; if (LargerRadius && Tools.random.nextInt(100) < level * 5) locRad += 2; int r = locRad - 1; int start = r / 2; Location sL = event.getBlock().getLocation(); player.getWorld().createExplosion(sL, 0f); // Create a fake explosion sL.setX(sL.getX() - start); sL.setY(sL.getY() - start); sL.setZ(sL.getZ() - start); for (int x = 0; x < locRad; x++) for (int y = 0; y < locRad; y++) for (int z = 0; z < locRad; z++) if ((!(x == 0 && y == 0 && z == 0)) && (!(x == r && y == 0 && z == 0)) && (!(x == 0 && y == r && z == 0)) && (!(x == 0 && y == 0 && z == r)) && (!(x == r && y == r && z == 0)) && (!(x == 0 && y == r && z == r)) && (!(x == r && y == 0 && z == r)) && (!(x == r && y == r && z == r))) locations.add(new Location(sL.getWorld(), sL.getX() + x, sL.getY() + y, sL.getZ() + z)); for (Location loc : locations) { String iMat = item.getType().toString(); Block b = loc.getBlock(); String bMat = b.getType().toString(); if (isUsable(iMat, bMat)) if (!loc.getBlock().getDrops(item).isEmpty()) if (Tools.checkWorldGuard(loc, player, "BUILD", false)) if (DropItems) loc.getBlock().breakNaturally(item); else for (ItemStack i : loc.getBlock().getDrops(item)) { player.getInventory().addItem(i); loc.getBlock().setType(Material.AIR); } } }
Example 18
Source File: DGameWorld.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
/** * Handles what happens when a player places a block. * * @param player * @param block * @param against * @param hand the event parameters. * @return if the event is cancelled */ public boolean onPlace(Player player, Block block, Block against, ItemStack hand) { Game game = getGame(); if (game == null) { return true; } PlaceableBlock placeableBlock = null; for (PlaceableBlock gamePlaceableBlock : placeableBlocks) { if (gamePlaceableBlock.canPlace(block, caliburn.getExItem(hand))) { placeableBlock = gamePlaceableBlock; break; } } if (!getRules().getState(GameRule.PLACE_BLOCKS) && placeableBlock == null) { // Workaround for a bug that would allow 3-Block-high jumping Location loc = player.getLocation(); if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) { if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) { if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) { loc.setX(block.getX() + 0.5); loc.setY(block.getY()); loc.setZ(block.getZ() + 0.5); player.teleport(loc); } } } return true; } if (placeableBlock != null) { placeableBlock.onPlace(); } Set<ExItem> whitelist = getRules().getState(GameRule.PLACE_WHITELIST); if (whitelist == null || whitelist.contains(VanillaItem.get(block.getType()))) { placedBlocks.add(block); return false; } return true; }
Example 19
Source File: RandomSearcher.java From RandomTeleport with GNU General Public License v3.0 | 4 votes |
private void checkRandom(CompletableFuture<Location> future) { if (checks >= maxTries) { future.completeExceptionally(new NotFoundException("location")); return; } if (future.isCancelled() || future.isDone() || future.isCompletedExceptionally()) { return; } lastCheck = center.getWorld().getTime(); Location randomLoc = center.clone(); randomLoc.setY(0); int minChunk = minRadius >> 4; int maxChunk = maxRadius >> 4; int randChunkX; int randChunkZ; Chunk[] loadedChunks = new Chunk[0]; if (loadedOnly) { loadedChunks = randomLoc.getWorld().getLoadedChunks(); if (loadedChunks.length == 0) { future.completeExceptionally(new NotFoundException("loaded chunk")); return; } } do { checks++; if (checks >= maxTries) { future.completeExceptionally(new NotFoundException("location")); return; } if (loadedOnly) { Chunk chunk = loadedChunks[random.nextInt(loadedChunks.length)]; randChunkX = chunk.getX(); randChunkZ = chunk.getZ(); } else { randChunkX = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1); randChunkZ = (random.nextBoolean() ? 1 : -1) * random.nextInt(maxChunk + 1); } } while (!checked.put(randChunkX, randChunkZ) || !inRadius(Math.abs(randChunkX), Math.abs(randChunkZ), minChunk, maxChunk)); randomLoc.setX(((center.getBlockX() >> 4) + randChunkX) * 16); randomLoc.setZ(((center.getBlockZ() >> 4) + randChunkZ) * 16); PaperLib.getChunkAtAsync(randomLoc, generatedOnly).thenApply(c -> { checks++; if (c == null) { // Chunk not generated, test another one checkRandom(future); return false; } int indexOffset = random.nextInt(RANDOM_LIST.size()); Location foundLoc = null; for (int i = 0; i < RANDOM_LIST.size(); i++) { int index = (i + indexOffset) % RANDOM_LIST.size(); boolean validated = true; Location loc = randomLoc.clone().add(RANDOM_LIST.get(index)[0], 0, RANDOM_LIST.get(index)[1]); if (!inRadius(loc)) { continue; } for (LocationValidator validator : getValidators().getAll()) { if (!validator.validate(this, loc)) { validated = false; break; } } if (validated) { foundLoc = loc; break; } } if (foundLoc != null) { // all checks are for the top block, put we want a location above that so add 1 to y future.complete(foundLoc.add(0, 1, 0)); return true; } long diff = center.getWorld().getTime() - lastCheck; if (diff < checkDelay) { plugin.getServer().getScheduler().runTaskLater(plugin, () -> checkRandom(future), checkDelay - diff); } else { checkRandom(future); } return false; }).exceptionally(future::completeExceptionally); }
Example 20
Source File: DropCrate.java From CratesPlus with GNU General Public License v3.0 | 4 votes |
private void spawnCrate() { startTimer(); // Start timer for the next drop if (Bukkit.getOnlinePlayers().size() < minPlayers) { return; // Not enough players online :( } List<String> worlds = new ArrayList<>(); for (String worldName : this.worlds) { if (Bukkit.getWorld(worldName) == null) continue; if (Bukkit.getWorld(worldName).getPlayers().size() < minPlayers) continue; // No players in world worlds.add(worldName); } if (worlds.isEmpty()) { return; // No world with players found :( } World world = Bukkit.getWorld(worlds.get(randInt(0, worlds.size() - 1))); Player player = world.getPlayers().get(randInt(0, world.getPlayers().size() - 1)); // Get random player to spawn crate near Location location = player.getLocation().clone(); double randomX = randInt((int) location.getX() - radiusClosestToPlayer, (int) location.getX() + radiusClosestToPlayer); double randomZ = randInt((int) location.getZ() - radiusClosestToPlayer, (int) location.getZ() + radiusClosestToPlayer); location.setX(randomX); location.setZ(randomZ); location = world.getHighestBlockAt(location).getLocation().clone().add(0, 0, 0); if (location.getBlock().getType().equals(Material.AIR)) { location.getBlock().setType(getBlock()); // TODO idk how to handle the below, is it even needed with 1.13? So reflection if thats the case... // location.getBlock().setData((byte) getBlockData()); System.out.println("Crate dropped at " + location.toString()); drops.add(location); // TODO Broadcast, populate and what not if (despawnTimer > 0) { // TODO Despawn Location finalLocation = location; Bukkit.getScheduler().runTaskLater(getCratesPlus(), () -> { if (drops.contains(finalLocation)) { drops.remove(finalLocation); finalLocation.getBlock().setType(Material.AIR); } }, despawnTimer * 20); } } }