Search in sources :

Example 1 with TagBase

use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.

the class MyStray method readExtendedInfo.

@SuppressWarnings("unchecked")
@Override
public void readExtendedInfo(TagCompound info) {
    if (info.containsKey("Equipment")) {
        TagList equipment = info.getAs("Equipment", TagList.class);
        List<TagBase> equipmentList = (List<TagBase>) equipment.getData();
        for (TagBase tag : equipmentList) {
            if (tag instanceof TagCompound) {
                TagCompound item = (TagCompound) tag;
                try {
                    ItemStack itemStack = MyPetApi.getPlatformHelper().compundToItemStack(item);
                    setEquipment(EquipmentSlot.getSlotById(item.getAs("Slot", TagInt.class).getIntData()), itemStack);
                } catch (Exception e) {
                    MyPetApi.getLogger().warning("Could not load Equipment item from pet data!");
                }
            }
        }
    }
}
Also used : TagBase(de.keyle.knbt.TagBase) TagInt(de.keyle.knbt.TagInt) TagList(de.keyle.knbt.TagList) ArrayList(java.util.ArrayList) List(java.util.List) TagList(de.keyle.knbt.TagList) ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 2 with TagBase

use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.

the class ItemStackNBTConverter method compoundToVanillaCompound.

public static Tag compoundToVanillaCompound(TagBase tag) {
    switch(TagType.getTypeById(tag.getTagTypeId())) {
        case Int:
            return IntTag.valueOf(((TagInt) tag).getIntData());
        case Short:
            return ShortTag.valueOf(((TagShort) tag).getShortData());
        case String:
            return StringTag.valueOf(((TagString) tag).getStringData());
        case Byte:
            return ByteTag.valueOf(((TagByte) tag).getByteData());
        case Byte_Array:
            return new ByteArrayTag(((TagByteArray) tag).getByteArrayData());
        case Double:
            return DoubleTag.valueOf(((TagDouble) tag).getDoubleData());
        case Float:
            return FloatTag.valueOf(((TagFloat) tag).getFloatData());
        case Int_Array:
            return new IntArrayTag(((TagIntArray) tag).getIntArrayData());
        case Long:
            return LongTag.valueOf(((TagLong) tag).getLongData());
        case List:
            TagList TagList = (TagList) tag;
            ListTag tagList = new ListTag();
            for (TagBase tagInList : TagList.getReadOnlyList()) {
                tagList.add(compoundToVanillaCompound(tagInList));
            }
            return tagList;
        case Compound:
            TagCompound TagCompound = (TagCompound) tag;
            CompoundTag tagCompound = new CompoundTag();
            for (String name : TagCompound.getCompoundData().keySet()) {
                tagCompound.put(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name)));
            }
            return tagCompound;
        case End:
            return null;
    }
    throw new IllegalArgumentException("Not a valid tag type");
}
Also used : IntArrayTag(net.minecraft.nbt.IntArrayTag) TagBase(de.keyle.knbt.TagBase) TagList(de.keyle.knbt.TagList) TagString(de.keyle.knbt.TagString) ListTag(net.minecraft.nbt.ListTag) TagCompound(de.keyle.knbt.TagCompound) CompoundTag(net.minecraft.nbt.CompoundTag) ByteArrayTag(net.minecraft.nbt.ByteArrayTag)

Example 3 with TagBase

use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.

the class ConfigurationNBT method load.

public boolean load() {
    if (!NBTFile.exists()) {
        return false;
    }
    try {
        InputStream is = new FileInputStream(NBTFile);
        TagBase tag = TagStream.readTag(is, true);
        if (tag != null) {
            nbtTagCompound = (TagCompound) tag;
            return true;
        }
        tag = TagStream.readTag(is, false);
        if (tag != null) {
            nbtTagCompound = (TagCompound) tag;
            return true;
        } else {
            MyPetApi.getLogger().warning("Could not parse/load " + NBTFile.getName());
            return false;
        }
    } catch (IOException e) {
        return false;
    }
}
Also used : TagBase(de.keyle.knbt.TagBase)

Example 4 with TagBase

use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.

the class ItemStackNBTConverter method compoundToVanillaCompound.

public static Tag compoundToVanillaCompound(TagBase tag) {
    switch(TagType.getTypeById(tag.getTagTypeId())) {
        case Int:
            return IntTag.valueOf(((TagInt) tag).getIntData());
        case Short:
            return ShortTag.valueOf(((TagShort) tag).getShortData());
        case String:
            return StringTag.valueOf(((TagString) tag).getStringData());
        case Byte:
            return ByteTag.valueOf(((TagByte) tag).getByteData());
        case Byte_Array:
            return new ByteArrayTag(((TagByteArray) tag).getByteArrayData());
        case Double:
            return DoubleTag.valueOf(((TagDouble) tag).getDoubleData());
        case Float:
            return FloatTag.valueOf(((TagFloat) tag).getFloatData());
        case Int_Array:
            return new IntArrayTag(((TagIntArray) tag).getIntArrayData());
        case Long:
            return LongTag.valueOf(((TagLong) tag).getLongData());
        case List:
            TagList TagList = (TagList) tag;
            ListTag tagList = new ListTag();
            for (TagBase tagInList : TagList.getReadOnlyList()) {
                tagList.add(compoundToVanillaCompound(tagInList));
            }
            return tagList;
        case Compound:
            TagCompound TagCompound = (TagCompound) tag;
            CompoundTag tagCompound = new CompoundTag();
            for (String name : TagCompound.getCompoundData().keySet()) {
                tagCompound.put(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name)));
            }
            return tagCompound;
        case End:
            return null;
    }
    throw new IllegalArgumentException("Not a valid tag type");
}
Also used : IntArrayTag(net.minecraft.nbt.IntArrayTag) TagBase(de.keyle.knbt.TagBase) TagList(de.keyle.knbt.TagList) TagString(de.keyle.knbt.TagString) ListTag(net.minecraft.nbt.ListTag) TagCompound(de.keyle.knbt.TagCompound) CompoundTag(net.minecraft.nbt.CompoundTag) ByteArrayTag(net.minecraft.nbt.ByteArrayTag)

Example 5 with TagBase

use of de.keyle.knbt.TagBase in project MyPet by xXKeyleXx.

the class MyGiant method readExtendedInfo.

@SuppressWarnings("unchecked")
@Override
public void readExtendedInfo(TagCompound info) {
    if (info.containsKey("Equipment")) {
        TagList equipment = info.get("Equipment");
        List<TagBase> equipmentList = (List<TagBase>) equipment.getData();
        for (TagBase tag : equipmentList) {
            if (tag instanceof TagCompound) {
                TagCompound item = (TagCompound) tag;
                try {
                    ItemStack itemStack = MyPetApi.getPlatformHelper().compundToItemStack(item);
                    setEquipment(EquipmentSlot.getSlotById(item.getAs("Slot", TagInt.class).getIntData()), itemStack);
                } catch (Exception e) {
                    MyPetApi.getLogger().warning("Could not load Equipment item from pet data!");
                }
            }
        }
    }
}
Also used : TagBase(de.keyle.knbt.TagBase) TagInt(de.keyle.knbt.TagInt) TagList(de.keyle.knbt.TagList) ArrayList(java.util.ArrayList) List(java.util.List) TagList(de.keyle.knbt.TagList) ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound)

Aggregations

TagBase (de.keyle.knbt.TagBase)6 TagCompound (de.keyle.knbt.TagCompound)5 TagList (de.keyle.knbt.TagList)5 TagInt (de.keyle.knbt.TagInt)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ItemStack (org.bukkit.inventory.ItemStack)3 TagString (de.keyle.knbt.TagString)2 ByteArrayTag (net.minecraft.nbt.ByteArrayTag)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 IntArrayTag (net.minecraft.nbt.IntArrayTag)2 ListTag (net.minecraft.nbt.ListTag)2