Java源码示例:com.comphenix.protocol.wrappers.nbt.NbtFactory

示例1
/**
 * Sets a player profile onto the given tag
 *
 * @param nbt           the tag to set the profile to
 * @param playerProfile the profile to set
 */
public static void setPlayerProfile(NbtCompound nbt, PlayerProfile playerProfile) {
    nbt.put("Id", (playerProfile.getId() == null ? UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerProfile.getName()).getBytes()) : playerProfile.getId()).toString());
    nbt.put("Name", playerProfile.getName());
    if (!nbt.containsKey("Properties")) return;
    NbtCompound properties = nbt.getCompound("Properties");
    NbtList list = properties.getList("textures");
    Map<String, NbtBase> texture = (Map<String, NbtBase>) list.getValue(0);
    for (ProfileProperty property : playerProfile.getProperties()) {
        texture.put("name", NbtFactory.of("name", property.getValue()));
        texture.put("Signature", NbtFactory.of("Signature", property.getSignature()));
        texture.put("Value", NbtFactory.of("Value", property.getValue()));
    }
}
 
示例2
private NbtCompound constructStructureNbt(int x, int y, int z, int posX, int posY, int posZ, int sizeX, int sizeY, int sizeZ) {
    HashMap<String, Object> tag = new HashMap<>();
    tag.put("name", UUID.randomUUID().toString());
    tag.put("author", "Empire92"); // :D
    tag.put("metadata", "");
    tag.put("x", x);
    tag.put("y", y);
    tag.put("z", z);
    tag.put("posX", posX);
    tag.put("posY", posY);
    tag.put("posZ", posZ);
    tag.put("sizeX", sizeX);
    tag.put("sizeY", sizeY);
    tag.put("sizeZ", sizeZ);
    tag.put("rotation", "NONE");
    tag.put("mirror", "NONE");
    tag.put("mode", "SAVE");
    tag.put("ignoreEntities", true);
    tag.put("powered", false);
    tag.put("showair", false);
    tag.put("showboundingbox", true);
    tag.put("integrity", 1.0f);
    tag.put("seed", 0);
    tag.put("id", "minecraft:structure_block");
    Object nmsTag = BukkitQueue_0.fromNative(FaweCache.asTag(tag));
    return NbtFactory.fromNMSCompound(nmsTag);
}
 
示例3
@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);
            });
}