Java源码示例:com.comphenix.protocol.wrappers.BlockPosition

示例1
private void sendNbt(Vector pos, NbtCompound compound) {
    Player player = this.<Player>getPlayer().parent;
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();

    PacketContainer blockNbt = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
    blockNbt.getBlockPositionModifier().write(0, new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()));
    blockNbt.getIntegers().write(0, 7);
    blockNbt.getNbtModifier().write(0, compound);


    try {
        manager.sendServerPacket(player, blockNbt);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
示例2
private void sendBlockChange(Player plr, Vector pt, BaseBlock block) {
    PacketContainer container = new PacketContainer(PacketType.Play.Server.BLOCK_CHANGE);
    // Block position
    // block combined id
    container.getBlockPositionModifier().write(0, new BlockPosition(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()));
    WrappedBlockData bd = WrappedBlockData.createData(Material.getMaterial(block.getId()), block.getData());
    container.getBlockData().write(0, bd);
    try {
        protocolmanager.sendWirePacket(plr, WirePacket.fromPacket(container));
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
示例3
private Vector getRelPos(PacketEvent event, VirtualWorld generator) {
    PacketContainer packet = event.getPacket();
    StructureModifier<BlockPosition> position = packet.getBlockPositionModifier();
    BlockPosition loc = position.readSafely(0);
    if (loc == null) return null;
    Vector origin = generator.getOrigin();
    Vector pt = new Vector(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ());
    return pt;
}
 
示例4
@Override
public void openPrompt(@Nonnull Player player, @Nonnull List<String> lines, @Nonnull ResponseHandler responseHandler) {
    Location location = player.getLocation().clone();
    location.setY(255);
    Players.sendBlockChange(player, location, Material.WALL_SIGN);

    BlockPosition position = new BlockPosition(location.toVector());
    PacketContainer writeToSign = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
    writeToSign.getBlockPositionModifier().write(0, position);
    writeToSign.getIntegers().write(0, 9);
    NbtCompound compound = NbtFactory.ofCompound("");

    for (int i = 0; i < 4; i++) {
        compound.put("Text" + (i + 1), "{\"text\":\"" + (lines.size() > i ? lines.get(i) : "") + "\"}");
    }

    compound.put("id", "minecraft:sign");
    compound.put("x", position.getX());
    compound.put("y", position.getY());
    compound.put("z", position.getZ());

    writeToSign.getNbtModifier().write(0, compound);
    Protocol.sendPacket(player, writeToSign);

    PacketContainer openSign = new PacketContainer(PacketType.Play.Server.OPEN_SIGN_EDITOR);
    openSign.getBlockPositionModifier().write(0, position);
    Protocol.sendPacket(player, openSign);

    // we need to ensure that the callback is only called once.
    final AtomicBoolean active = new AtomicBoolean(true);

    Protocol.subscribe(PacketType.Play.Client.UPDATE_SIGN)
            .filter(e -> e.getPlayer().getUniqueId().equals(player.getUniqueId()))
            .biHandler((sub, event) -> {
                if (!active.getAndSet(false)) {
                    return;
                }

                PacketContainer container = event.getPacket();

                List<String> input = new ArrayList<>(Arrays.asList(container.getStringArrays().read(0)));
                Response response = responseHandler.handleResponse(input);

                if (response == Response.TRY_AGAIN) {
                    // didn't pass, re-send the sign and request another input
                    Schedulers.sync().runLater(() -> {
                        if (player.isOnline()) {
                            openPrompt(player, lines, responseHandler);
                        }
                    }, 1L);
                }

                // cleanup this instance
                sub.close();
                Players.sendBlockChange(player, location, Material.AIR);
            });
}
 
示例5
public BlockPosition getLocation() {
    return this.handle.getBlockPositionModifier().read(0);
}
 
示例6
public void setLocation(BlockPosition value) {
    this.handle.getBlockPositionModifier().write(0, value);
}