Java Code Examples for com.github.steveice10.opennbt.tag.builtin.StringTag#getValue()

The following examples show how to use com.github.steveice10.opennbt.tag.builtin.StringTag#getValue() . 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: ItemRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
public static void rewriteBookToServer(Item item) {
    int id = item.getIdentifier();
    if (id != 387) {
        return;
    }
    CompoundTag tag = item.getTag();
    ListTag pages = tag.get("pages");
    if (pages == null) { // is this even possible?
        return;
    }
    for (int i = 0; i < pages.size(); i++) {
        Tag pageTag = pages.get(i);
        if (!(pageTag instanceof StringTag)) {
            continue;
        }
        StringTag stag = (StringTag) pageTag;
        String value = stag.getValue();
        if (value.replaceAll(" ", "").isEmpty()) {
            value = "\"" + fixBookSpaceChars(value) + "\"";
        } else {
            value = fixBookSpaceChars(value);
        }
        stag.setValue(value);
    }
}
 
Example 2
Source File: BasicItemTranslator.java    From Geyser with MIT License 5 votes vote down vote up
private String toJavaMessage(StringTag tag) {
    String message = tag.getValue();
    if (message == null) return null;
    if (message.startsWith("§r")) {
        message = message.replaceFirst("§r", "");
    }
    Component component = TextComponent.of(message);
    return GsonComponentSerializer.INSTANCE.serialize(component);
}
 
Example 3
Source File: BasicItemTranslator.java    From Geyser with MIT License 5 votes vote down vote up
private String toBedrockMessage(StringTag tag) {
    String message = tag.getValue();
    if (message == null) return null;
    TextComponent component = (TextComponent) MessageUtils.phraseJavaMessage(message);
    String legacy = LegacyComponentSerializer.legacy().serialize(component);
    if (hasFormatting(LegacyComponentSerializer.legacy().deserialize(legacy))) {
        return "§r" + legacy;
    }
    return legacy;
}
 
Example 4
Source File: WorldPackets.java    From ViaVersion with MIT License 5 votes vote down vote up
private static void handleBlockEntity(CompoundTag compoundTag) {
    StringTag idTag = compoundTag.get("id");
    if (idTag == null) return;

    String id = idTag.getValue();
    if (id.equals("minecraft:conduit")) {
        Tag targetUuidTag = compoundTag.remove("target_uuid");
        if (!(targetUuidTag instanceof StringTag)) return;

        // target_uuid -> Target
        UUID targetUuid = UUID.fromString((String) targetUuidTag.getValue());
        compoundTag.put(new IntArrayTag("Target", UUIDIntArrayType.uuidToIntArray(targetUuid)));
    } else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) {
        CompoundTag ownerTag = compoundTag.remove("Owner");
        StringTag ownerUuidTag = ownerTag.remove("Id");
        if (ownerUuidTag != null) {
            UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
            ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid)));
        }

        // Owner -> SkullOwner
        CompoundTag skullOwnerTag = new CompoundTag("SkullOwner");
        for (Tag tag : ownerTag) {
            skullOwnerTag.put(tag);
        }
        compoundTag.put(skullOwnerTag);
    }
}