org.bukkit.Location#getBlockX ( )源码实例Demo

下面列出了org.bukkit.Location#getBlockX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AnnihilationPro   文件: Dragon.java
@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));
    }
 
源代码2 项目: FastAsyncWorldedit   文件: FaweAdapter_1_11.java
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;
}
 
源代码3 项目: Civs   文件: HuntEffect.java
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();
}
 
源代码4 项目: AnnihilationPro   文件: Transporter.java
@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.");
				}
			}
		}
	}
}
 
源代码5 项目: BedWars   文件: GameCreator.java
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");
}
 
源代码6 项目: Kettle   文件: CraftHumanEntity.java
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();
}
 
源代码7 项目: civcraft   文件: Wall.java
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);
	} 
}
 
源代码8 项目: worldedit-adapters   文件: Spigot_v1_14_R4.java
@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();
}
 
源代码9 项目: ShopChest   文件: ShopUtils.java
/**
 * 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);
}
 
源代码10 项目: UhcCore   文件: UhcWorldBorder.java
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;
}
 
源代码11 项目: Crazy-Crates   文件: QuadCrate.java
@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;
            }
        }
    }
}
 
源代码12 项目: Thermos   文件: CraftWorld.java
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();
}
 
@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);
}
 
源代码14 项目: FastAsyncWorldedit   文件: FaweAdapter_1_11.java
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;
}
 
源代码15 项目: AuthMeReloaded   文件: PlayerAuth.java
public void setQuitLocation(Location location) {
    x = location.getBlockX();
    y = location.getBlockY();
    z = location.getBlockZ();
    world = location.getWorld().getName();
}
 
源代码16 项目: Thermos   文件: CraftWorld.java
@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 );
        }
    }
}
 
源代码17 项目: PaperLib   文件: AsyncTeleportPaper.java
@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));
}
 
源代码18 项目: ExoticGarden   文件: Schematic.java
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());
                        }
                    }
                }
            }
        }
    }
}
 
源代码19 项目: Hawk   文件: WrappedBlock7.java
@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);
}
 
源代码20 项目: askyblock   文件: GridManager.java
/**
 * 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);
}