Java源码示例:cn.nukkit.nbt.tag.StringTag

示例1
public String[] getLore() {
    Tag tag = this.getNamedTagEntry("display");
    ArrayList<String> lines = new ArrayList<>();

    if (tag instanceof CompoundTag) {
        CompoundTag nbt = (CompoundTag) tag;
        ListTag<StringTag> lore = nbt.getList("Lore", StringTag.class);

        if (lore.size() > 0) {
            for (StringTag stringTag : lore.getAll()) {
                lines.add(stringTag.data);
            }
        }
    }

    return lines.toArray(new String[0]);
}
 
示例2
public String[] getLore() {
    Tag tag = this.getNamedTagEntry("display");
    ArrayList<String> lines = new ArrayList<>();

    if (tag instanceof CompoundTag) {
        CompoundTag nbt = (CompoundTag) tag;
        ListTag<StringTag> lore = nbt.getList("Lore", StringTag.class);

        if (lore.size() > 0) {
            for (StringTag stringTag : lore.getAll()) {
                lines.add(stringTag.data);
            }
        }
    }

    return lines.toArray(new String[0]);
}
 
示例3
private List<String> extractStringList(Item item, String tagName) {
    CompoundTag namedTag = item.getNamedTag();
    if (namedTag == null) {
        return Collections.emptyList();
    }

    ListTag<StringTag> listTag = namedTag.getList(tagName, StringTag.class);
    if (listTag == null) {
        return Collections.emptyList();
    }

    int size = listTag.size();
    List<String> values = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        StringTag stringTag = listTag.get(i);
        if (stringTag != null) {
            values.add(stringTag.data);
        }
    }

    return values;
}
 
示例4
public String[] getLore() {
    Tag tag = this.getNamedTagEntry("display");
    ArrayList<String> lines = new ArrayList<>();

    if (tag instanceof CompoundTag) {
        CompoundTag nbt = (CompoundTag) tag;
        ListTag<StringTag> lore = nbt.getList("Lore", StringTag.class);

        if (lore.size() > 0) {
            for (StringTag stringTag : lore.getAll()) {
                lines.add(stringTag.data);
            }
        }
    }

    return lines.toArray(new String[0]);
}
 
示例5
public boolean hasCustomName() {
    if (!this.hasCompoundTag()) {
        return false;
    }

    CompoundTag tag = this.getNamedTag();
    if (tag.contains("display")) {
        Tag tag1 = tag.get("display");
        if (tag1 instanceof CompoundTag && ((CompoundTag) tag1).contains("Name") && ((CompoundTag) tag1).get("Name") instanceof StringTag) {
            return true;
        }
    }

    return false;
}
 
示例6
public String getCustomName() {
    if (!this.hasCompoundTag()) {
        return "";
    }

    CompoundTag tag = this.getNamedTag();
    if (tag.contains("display")) {
        Tag tag1 = tag.get("display");
        if (tag1 instanceof CompoundTag && ((CompoundTag) tag1).contains("Name") && ((CompoundTag) tag1).get("Name") instanceof StringTag) {
            return ((CompoundTag) tag1).getString("Name");
        }
    }

    return "";
}
 
示例7
@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        BlockEntity t = getLevel().getBlockEntity(this);
        BlockEntityDispenser dispenser;
        if (t instanceof BlockEntityDispenser) {
            dispenser = (BlockEntityDispenser) t;
        } else {
            CompoundTag nbt = new CompoundTag()
                    .putList(new ListTag<>("Items"))
                    .putString("id", BlockEntity.DISPENSER)
                    .putInt("x", (int) this.x)
                    .putInt("y", (int) this.y)
                    .putInt("z", (int) this.z);
            dispenser = new BlockEntityDispenser(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }

        if (dispenser.namedTag.contains("Lock") && dispenser.namedTag.get("Lock") instanceof StringTag) {
            if (!dispenser.namedTag.getString("Lock").equals(item.getCustomName())) {
                return false;
            }
        }

        player.addWindow(dispenser.getInventory());
    }

    return true;
}
 
示例8
@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        Block top = up();
        if (!top.isTransparent()) {
            return true;
        }

        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityShulkerBox shulkerBox;
        if (t instanceof BlockEntityShulkerBox) {
            shulkerBox = (BlockEntityShulkerBox) t;
        } else {
            CompoundTag nbt = new CompoundTag("")
                    .putString("id", BlockEntity.SHULKER_BOX)
                    .putInt("x", (int) this.x)
                    .putInt("y", (int) this.y)
                    .putInt("z", (int) this.z);
            shulkerBox = new BlockEntityShulkerBox(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }

        if (shulkerBox.namedTag.contains("Lock") && shulkerBox.namedTag.get("Lock") instanceof StringTag) {
            if (!shulkerBox.namedTag.getString("Lock").equals(item.getCustomName())) {
                return true;
            }
        }

        player.addWindow(shulkerBox.getInventory());
    }

    return true;
}
 
示例9
@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        BlockEntity t = getLevel().getBlockEntity(this);
        BlockEntityDropper dropper;
        if (t instanceof BlockEntityDropper) {
            dropper = (BlockEntityDropper) t;
        } else {
            CompoundTag nbt = new CompoundTag()
                    .putList(new ListTag<>("Items"))
                    .putString("id", BlockEntity.DROPPER)
                    .putInt("x", (int) this.x)
                    .putInt("y", (int) this.y)
                    .putInt("z", (int) this.z);
            dropper = new BlockEntityDropper(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }

        if (dropper.namedTag.contains("Lock") && dropper.namedTag.get("Lock") instanceof StringTag) {
            if (!dropper.namedTag.getString("Lock").equals(item.getCustomName())) {
                return false;
            }
        }

        player.addWindow(dropper.getInventory());
    }

    return true;
}
 
示例10
@Override
public boolean onActivate(Item item, Player player) {
    if (player != null) {
        Block top = up();
        if (!top.isTransparent()) {
            return true;
        }

        BlockEntity t = this.getLevel().getBlockEntity(this);
        BlockEntityShulkerBox shulkerBox;
        if (t instanceof BlockEntityShulkerBox) {
            shulkerBox = (BlockEntityShulkerBox) t;
        } else {
            CompoundTag nbt = new CompoundTag("")
                    .putString("id", BlockEntity.SHULKER_BOX)
                    .putInt("x", (int) this.x)
                    .putInt("y", (int) this.y)
                    .putInt("z", (int) this.z);
            shulkerBox = new BlockEntityShulkerBox(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
        }

        if (shulkerBox.namedTag.contains("Lock") && shulkerBox.namedTag.get("Lock") instanceof StringTag) {
            if (!shulkerBox.namedTag.getString("Lock").equals(item.getCustomName())) {
                return true;
            }
        }

        player.addWindow(shulkerBox.getInventory());
    }

    return true;
}
 
示例11
public boolean hasCustomName() {
    if (!this.hasCompoundTag()) {
        return false;
    }

    CompoundTag tag = this.getNamedTag();
    if (tag.contains("display")) {
        Tag tag1 = tag.get("display");
        return tag1 instanceof CompoundTag && ((CompoundTag) tag1).contains("Name") && ((CompoundTag) tag1).get("Name") instanceof StringTag;
    }

    return false;
}
 
示例12
public String getCustomName() {
    if (!this.hasCompoundTag()) {
        return "";
    }

    CompoundTag tag = this.getNamedTag();
    if (tag.contains("display")) {
        Tag tag1 = tag.get("display");
        if (tag1 instanceof CompoundTag && ((CompoundTag) tag1).contains("Name") && ((CompoundTag) tag1).get("Name") instanceof StringTag) {
            return ((CompoundTag) tag1).getString("Name");
        }
    }

    return "";
}
 
示例13
public boolean hasCustomName() {
    if (!this.hasCompoundTag()) {
        return false;
    }

    CompoundTag tag = this.getNamedTag();
    if (tag.contains("display")) {
        Tag tag1 = tag.get("display");
        if (tag1 instanceof CompoundTag && ((CompoundTag) tag1).contains("Name") && ((CompoundTag) tag1).get("Name") instanceof StringTag) {
            return true;
        }
    }

    return false;
}
 
示例14
public String getCustomName() {
    if (!this.hasCompoundTag()) {
        return "";
    }

    CompoundTag tag = this.getNamedTag();
    if (tag.contains("display")) {
        Tag tag1 = tag.get("display");
        if (tag1 instanceof CompoundTag && ((CompoundTag) tag1).contains("Name") && ((CompoundTag) tag1).get("Name") instanceof StringTag) {
            return ((CompoundTag) tag1).getString("Name");
        }
    }

    return "";
}
 
示例15
@Override
public void saveNBT() {
    super.saveNBT();

    if (skin != null) {
        CompoundTag skinTag = new CompoundTag()
                .putByteArray("Data", this.getSkin().getSkinData().data)
                .putInt("SkinImageWidth", this.getSkin().getSkinData().width)
                .putInt("SkinImageHeight", this.getSkin().getSkinData().height)
                .putString("ModelId", this.getSkin().getSkinId())
                .putString("CapeId", this.getSkin().getCapeId())
                .putByteArray("CapeData", this.getSkin().getCapeData().data)
                .putInt("CapeImageWidth", this.getSkin().getCapeData().width)
                .putInt("CapeImageHeight", this.getSkin().getCapeData().height)
                .putByteArray("SkinResourcePatch", this.getSkin().getSkinResourcePatch().getBytes(StandardCharsets.UTF_8))
                .putByteArray("GeometryData", this.getSkin().getGeometryData().getBytes(StandardCharsets.UTF_8))
                .putByteArray("AnimationData", this.getSkin().getAnimationData().getBytes(StandardCharsets.UTF_8))
                .putBoolean("PremiumSkin", this.getSkin().isPremium())
                .putBoolean("PersonaSkin", this.getSkin().isPersona())
                .putBoolean("CapeOnClassicSkin", this.getSkin().isCapeOnClassic())
                .putString("ArmSize", this.getSkin().getArmSize())
                .putString("SkinColor", this.getSkin().getSkinColor())
                .putBoolean("IsTrustedSkin", this.getSkin().isTrusted());
        List<SkinAnimation> animations = this.getSkin().getAnimations();
        if (!animations.isEmpty()) {
            ListTag<CompoundTag> animationsTag = new ListTag<>("AnimationImageData");
            for (SkinAnimation animation : animations) {
                animationsTag.add(new CompoundTag()
                        .putFloat("Frames", animation.frames)
                        .putInt("Type", animation.type)
                        .putInt("ImageWidth", animation.image.width)
                        .putInt("ImageHeight", animation.image.height)
                        .putByteArray("Image", animation.image.data));
            }
            skinTag.putList(animationsTag);
        }
        List<PersonaPiece> personaPieces = this.getSkin().getPersonaPieces();
        if (!personaPieces.isEmpty()) {
            ListTag<CompoundTag> piecesTag = new ListTag<>("PersonaPieces");
            for (PersonaPiece piece : personaPieces) {
                piecesTag.add(new CompoundTag().putString("PieceId", piece.id)
                        .putString("PieceType", piece.type)
                        .putString("PackId", piece.packId)
                        .putBoolean("IsDefault", piece.isDefault)
                        .putString("ProductId", piece.productId));
            }
        }
        List<PersonaPieceTint> tints = this.getSkin().getTintColors();
        if (!tints.isEmpty()) {
            ListTag<CompoundTag> tintsTag = new ListTag<>("PieceTintColors");
            for (PersonaPieceTint tint : tints) {
                ListTag<StringTag> colors = new ListTag<>("Colors");
                colors.setAll(tint.colors.stream().map(s -> new StringTag("", s)).collect(Collectors.toList()));
                tintsTag.add(new CompoundTag()
                        .putString("PieceType", tint.pieceType)
                        .putList(colors));
            }
        }
        this.namedTag.putCompound("Skin", skinTag);
    }
}