Java Code Examples for org.bukkit.Location#getBlockX()
The following examples show how to use
org.bukkit.Location#getBlockX() .
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: Dragon.java From AnnihilationPro with MIT License | 6 votes |
@Override public Packet getTeleportPacket(Location loc) { // Class<?> PacketPlayOutEntityTeleport = Util.getCraftClass("PacketPlayOutEntityTeleport"); // // Object packet = null; // // try { // packet = PacketPlayOutEntityTeleport.getConstructor(new Class<?>[] { int.class, int.class, int.class, int.class, byte.class, byte.class }).newInstance(this.id, loc.getBlockX() * 32, loc.getBlockY() * 32, loc.getBlockZ() * 32, (byte) ((int) loc.getYaw() * 256 / 360), (byte) ((int) loc.getPitch() * 256 / 360)); // } catch (IllegalArgumentException e) { // //e.printStackTrace(); // } catch (SecurityException e) { // //e.printStackTrace(); // } catch (InstantiationException e) { // //e.printStackTrace(); // } catch (IllegalAccessException e) { // //e.printStackTrace(); // } catch (InvocationTargetException e) { // //e.printStackTrace(); // } catch (NoSuchMethodException e) { // //e.printStackTrace(); // } return new PacketPlayOutEntityTeleport(this.id, loc.getBlockX() * 32, loc.getBlockY() * 32, loc.getBlockZ() * 32, (byte) ((int) loc.getYaw() * 256 / 360), (byte) ((int) loc.getPitch() * 256 / 360)); }
Example 2
Source File: FaweAdapter_1_11.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
public BaseBlock getBlock(Location location) { Preconditions.checkNotNull(location); CraftWorld craftWorld = (CraftWorld)location.getWorld(); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); Block bukkitBlock = location.getBlock(); BaseBlock block = new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData()); TileEntity te = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z)); if (te != null) { NBTTagCompound tag = new NBTTagCompound(); readTileEntityIntoTag(te, tag); block.setNbtData((CompoundTag)toNative(tag)); } return block; }
Example 3
Source File: HuntEffect.java From Civs with GNU General Public License v3.0 | 6 votes |
public static Location findNearbyLocationForTeleport(Location location, int radius, Player player) { int times = 0; Block targetBlock; do { times++; int xRadius = (int) (Math.random()*radius); if (Math.random() > .5) { xRadius = xRadius *-1; } int x = location.getBlockX() + xRadius; int zRadius = (int) ((Math.sqrt(radius*radius - xRadius*xRadius))); if (Math.random() > .5) { zRadius = zRadius *-1; } int z = location.getBlockZ() + zRadius; targetBlock = location.getWorld().getHighestBlockAt(x, z); } while (times < 5 && (targetBlock.getType() == Material.LAVA)); if (times == 5) { return null; } return targetBlock.getLocation(); }
Example 4
Source File: Wall.java From civcraft with GNU General Public License v2.0 | 6 votes |
private void getVerticalWallSegment(Player player, Location loc, Map<String, SimpleBlock> simpleBlocks) throws CivException { Location tmp = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ()); for (int i = 0; i < Wall.HEIGHT; i++) { SimpleBlock sb; if (i == 0) { sb = new SimpleBlock(CivData.STONE_BRICK, 0x1); } else { sb = new SimpleBlock(CivData.STONE_BRICK, 0); } sb.worldname = tmp.getWorld().getName(); sb.x = tmp.getBlockX(); sb.y = tmp.getBlockY(); sb.z = tmp.getBlockZ(); validateBlockLocation(player, tmp); simpleBlocks.put(sb.worldname+","+sb.x+","+sb.y+","+sb.z, sb); tmp.add(0, 1.0, 0); } }
Example 5
Source File: Transporter.java From AnnihilationPro with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true) public void MoveListeners(PlayerMoveEvent event) { ///block under your feet Block to = event.getTo().getBlock().getRelative(BlockFace.DOWN); if(to.getType() == Material.QUARTZ_ORE) { Location x = event.getTo(); Location y = event.getFrom(); if(x.getBlockX() != y.getBlockX() || x.getBlockY() != y.getBlockY() || x.getBlockZ() != y.getBlockZ()) { AnniPlayer user = AnniPlayer.getPlayer(event.getPlayer().getUniqueId()); UUID owner = getBlocksOwner(to); if(owner != null && user != null) { Teleporter tele = this.teleporters.get(owner); if(tele != null && tele.isLinked() && tele.getOwner().getTeam() == user.getTeam()) { event.getPlayer().sendMessage(ChatColor.AQUA+"This is a teleporter owned by "+ChatColor.WHITE+tele.getOwner().getName()+ChatColor.AQUA+", Sneak to go through it."); } } } } }
Example 6
Source File: GameCreator.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
private String changeStoreEntityType(Location loc, String type) { type = type.toUpperCase(); String location = loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); if (villagerstores.containsKey(location)) { EntityType t = null; try { t = EntityType.valueOf(type); if (!t.isAlive()) { t = null; } } catch (Exception e) { } if (t == null) { return i18n("admin_command_wrong_living_entity_type"); } villagerstores.get(location).setEntityType(t); return i18n("admin_command_store_living_entity_type_set").replace("%type%", t.toString()); } return i18n("admin_command_store_not_exists"); }
Example 7
Source File: CraftHumanEntity.java From Kettle with GNU General Public License v3.0 | 6 votes |
public InventoryView openEnchanting(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.ENCHANTMENT_TABLE) { return null; } } if (location == null) { location = getLocation(); } // If there isn't an enchant table we can force create one, won't be very useful though. BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); TileEntity container = getHandle().world.getTileEntity(pos); if (container == null && force) { container = new TileEntityEnchantmentTable(); container.setWorld(getHandle().world); container.setPos(pos); } getHandle().displayGui((TileEntityLockable) container); if (force) { getHandle().inventoryContainer.checkReachable = false; } return getHandle().inventoryContainer.getBukkitView(); }
Example 8
Source File: ShopUtils.java From ShopChest with MIT License | 5 votes |
/** * Get the shop at a given location * * @param location Location of the shop * @return Shop at the given location or <b>null</b> if no shop is found there */ public Shop getShop(Location location) { Location newLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); return shopLocation.get(newLocation); }
Example 9
Source File: UhcWorldBorder.java From UhcCore with GNU General Public License v3.0 | 5 votes |
public boolean isWithinBorder(Location loc){ int x = loc.getBlockX(); int z = loc.getBlockZ(); if (x < 0) x = -x; if (z < 0) z = -z; double border = getCurrentSize(); return x < border && z < border; }
Example 10
Source File: QuadCrate.java From Crazy-Crates with MIT License | 5 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent e) { Player player = e.getPlayer(); if (QuadCrateSession.inSession(player)) {//Player tries to walk away from the crate area Location from = e.getFrom(); Location to = e.getTo(); if (from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) { e.setCancelled(true); player.teleport(from); return; } } for (Entity en : player.getNearbyEntities(2, 2, 2)) {//Someone tries to enter the crate area if (en instanceof Player) { Player p = (Player) en; if (QuadCrateSession.inSession(p)) { Vector v = player.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().setY(1); if (player.isInsideVehicle()) { player.getVehicle().setVelocity(v); } else { player.setVelocity(v); } break; } } } }
Example 11
Source File: CraftWorld.java From Thermos with GNU General Public License v3.0 | 5 votes |
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException { Validate.notNull(location, "Location cannot be null"); Validate.notNull(material, "Material cannot be null"); Validate.isTrue(material.isBlock(), "Material must be a block"); double x = location.getBlockX() + 0.5; double y = location.getBlockY() + 0.5; double z = location.getBlockZ() + 0.5; net.minecraft.entity.item.EntityFallingBlock entity = new net.minecraft.entity.item.EntityFallingBlock(world, x, y, z, net.minecraft.block.Block.getBlockById(material.getId()), data); entity.field_145812_b = 1; // ticksLived world.addEntity(entity, SpawnReason.CUSTOM); return (FallingBlock) entity.getBukkitEntity(); }
Example 12
Source File: Spigot_v1_14_R4.java From worldedit-adapters with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BaseBlock getBlock(Location location) { checkNotNull(location); CraftWorld craftWorld = ((CraftWorld) location.getWorld()); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); final WorldServer handle = craftWorld.getHandle(); Chunk chunk = handle.getChunkAt(x >> 4, z >> 4); final BlockPosition blockPos = new BlockPosition(x, y, z); final IBlockData blockData = chunk.getType(blockPos); int internalId = Block.getCombinedId(blockData); BlockState state = BlockStateIdAccess.getBlockStateById(internalId); if (state == null) { org.bukkit.block.Block bukkitBlock = location.getBlock(); state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); } // Read the NBT data TileEntity te = chunk.a(blockPos, Chunk.EnumTileEntityState.CHECK); if (te != null) { NBTTagCompound tag = new NBTTagCompound(); readTileEntityIntoTag(te, tag); // Load data return state.toBaseBlock((CompoundTag) toNative(tag)); } return state.toBaseBlock(); }
Example 13
Source File: PlotSquaredIntegrationV5.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
@Override public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { com.plotsquared.core.location.Location pLocation = new com.plotsquared.core.location.Location( location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); Plot plot = pLocation.getPlot(); if (plot == null) { return !whiteList; } return plot.getFlag(createFlag); }
Example 14
Source File: FaweAdapter_1_11.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public boolean setBlock(Location location, BaseBlock block, boolean notifyAndLight) { Preconditions.checkNotNull(location); Preconditions.checkNotNull(block); CraftWorld craftWorld = (CraftWorld)location.getWorld(); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); boolean changed = location.getBlock().setTypeIdAndData(block.getId(), (byte)block.getData(), notifyAndLight); CompoundTag nativeTag = block.getNbtData(); if (nativeTag != null) { TileEntity tileEntity = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z)); if (tileEntity != null) { NBTTagCompound tag = (NBTTagCompound)fromNative(nativeTag); tag.set("x", new NBTTagInt(x)); tag.set("y", new NBTTagInt(y)); tag.set("z", new NBTTagInt(z)); readTagIntoTileEntity(tag, tileEntity); } } return changed; }
Example 15
Source File: WrappedBlock7.java From Hawk with GNU General Public License v3.0 | 4 votes |
@Override public void sendPacketToPlayer(Player p) { Location loc = getBukkitBlock().getLocation(); PacketPlayOutBlockChange pac = new PacketPlayOutBlockChange(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), ((CraftWorld) loc.getWorld()).getHandle()); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(pac); }
Example 16
Source File: Schematic.java From ExoticGarden with GNU General Public License v3.0 | 4 votes |
public static void pasteSchematic(Location loc, Tree tree) { Schematic schematic; try { schematic = tree.getSchematic(); } catch (IOException e) { ExoticGarden.instance.getLogger().log(Level.WARNING, "Could not paste Schematic for Tree: " + tree.getFruitID() + "_TREE (" + e.getClass().getSimpleName() + ')', e); return; } BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST }; short[] blocks = schematic.getBlocks(); byte[] blockData = schematic.getData(); short length = schematic.getLength(); short width = schematic.getWidth(); short height = schematic.getHeight(); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; int blockX = x + loc.getBlockX() - length / 2; int blockY = y + loc.getBlockY(); int blockZ = z + loc.getBlockZ() - width / 2; Block block = new Location(loc.getWorld(), blockX, blockY, blockZ).getBlock(); if ((!block.getType().isSolid() && !block.getType().isInteractable() && !MaterialCollections.getAllUnbreakableBlocks().contains(block.getType())) || block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR || org.bukkit.Tag.SAPLINGS.isTagged(block.getType())) { Material material = parseId(blocks[index], blockData[index]); if (material != null) { if (blocks[index] != 0) { block.setType(material); } if (org.bukkit.Tag.LEAVES.isTagged(material)) { if (ThreadLocalRandom.current().nextInt(100) < 25) { BlockStorage.store(block, tree.getItem()); } } else if (material == Material.PLAYER_HEAD) { Rotatable s = (Rotatable) block.getBlockData(); s.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]); block.setBlockData(s); SkullBlock.setFromHash(block, tree.getTexture()); BlockStorage.store(block, tree.getFruit()); } } } } } } }
Example 17
Source File: AsyncTeleportPaper.java From PaperLib with MIT License | 4 votes |
@Override public CompletableFuture<Boolean> teleportAsync(Entity entity, Location location, TeleportCause cause) { int x = location.getBlockX() >> 4; int z = location.getBlockZ() >> 4; return PaperLib.getChunkAtAsyncUrgently(entity.getWorld(), x, z, true).thenApply(chunk -> entity.teleport(location, cause)); }
Example 18
Source File: CraftWorld.java From Thermos with GNU General Public License v3.0 | 4 votes |
@Override public void playEffect( Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius ) { Validate.notNull( location, "Location cannot be null" ); Validate.notNull( effect, "Effect cannot be null" ); Validate.notNull( location.getWorld(), "World cannot be null" ); net.minecraft.network.Packet packet; if ( effect.getType() != Effect.Type.PARTICLE ) { int packetData = effect.getId(); packet = new net.minecraft.network.play.server.S28PacketEffect( packetData, location.getBlockX(), location.getBlockY(), location.getBlockZ(), id, false ); } else { StringBuilder particleFullName = new StringBuilder(); particleFullName.append( effect.getName() ); if ( effect.getData() != null && ( effect.getData().equals( net.minecraft.block.material.Material.class ) || effect.getData().equals( org.bukkit.material.MaterialData.class ) ) ) { particleFullName.append( '_' ).append( id ); } if ( effect.getData() != null && effect.getData().equals( org.bukkit.material.MaterialData.class ) ) { particleFullName.append( '_' ).append( data ); } packet = new net.minecraft.network.play.server.S2APacketParticles( particleFullName.toString(), (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, particleCount ); } int distance; radius *= radius; for ( Player player : getPlayers() ) { if ( ( (CraftPlayer) player ).getHandle().playerNetServerHandler == null ) { continue; } if ( !location.getWorld().equals( player.getWorld() ) ) { continue; } distance = (int) player.getLocation().distanceSquared( location ); if ( distance <= radius ) { ( (CraftPlayer) player ).getHandle().playerNetServerHandler.sendPacket( packet ); } } }
Example 19
Source File: PlayerAuth.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
public void setQuitLocation(Location location) { x = location.getBlockX(); y = location.getBlockY(); z = location.getBlockZ(); world = location.getWorld().getName(); }
Example 20
Source File: GridManager.java From askyblock with GNU General Public License v2.0 | 2 votes |
/** * Provides confirmation that the island is on the grid lines * * @param loc - location to check * @return true if on grid, false if not */ public boolean onGrid(Location loc) { int x = loc.getBlockX(); int z = loc.getBlockZ(); return onGrid(x, z); }