cn.nukkit.nbt.tag.StringTag Java Examples

The following examples show how to use cn.nukkit.nbt.tag.StringTag. 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: Item.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
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]);
}
 
Example #2
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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]);
}
 
Example #3
Source File: BinaryStream.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: Item.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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]);
}
 
Example #5
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: Item.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
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 "";
}
 
Example #7
Source File: BlockDispenser.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #8
Source File: BlockShulkerBoxUndyed.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #9
Source File: BlockDropper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: BlockShulkerBox.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #11
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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 "";
}
 
Example #13
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: Item.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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 "";
}
 
Example #15
Source File: EntityHuman.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@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);
    }
}