Search in sources :

Example 56 with TagCompound

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

the class MyStrider method readExtendedInfo.

@Override
public void readExtendedInfo(TagCompound info) {
    if (info.containsKeyAs("Saddle", TagByte.class)) {
        boolean saddle = info.getAs("Saddle", TagByte.class).getBooleanData();
        if (saddle) {
            ItemStack item = new ItemStack(Material.SADDLE);
            setSaddle(item);
        }
    } else if (info.containsKeyAs("Saddle", TagCompound.class)) {
        TagCompound itemTag = info.get("Saddle");
        try {
            ItemStack item = MyPetApi.getPlatformHelper().compundToItemStack(itemTag);
            setSaddle(item);
        } catch (Exception e) {
            MyPetApi.getLogger().warning("Could not load Saddle item from pet data!");
        }
    }
    if (info.containsKey("Baby")) {
        setBaby(info.getAs("Baby", TagByte.class).getBooleanData());
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Example 57 with TagCompound

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

the class MyTropicalFish method writeExtendedInfo.

@Override
public TagCompound writeExtendedInfo() {
    TagCompound info = super.writeExtendedInfo();
    info.getCompoundData().put("Variant", new TagInt(getVariant()));
    return info;
}
Also used : TagInt(de.keyle.knbt.TagInt) TagCompound(de.keyle.knbt.TagCompound)

Example 58 with TagCompound

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

the class MyHorse method writeExtendedInfo.

@Override
public TagCompound writeExtendedInfo() {
    TagCompound info = super.writeExtendedInfo();
    info.getCompoundData().put("Type", new TagByte(getHorseType()));
    info.getCompoundData().put("Variant", new TagInt(getVariant()));
    if (hasArmor()) {
        info.getCompoundData().put("Armor", MyPetApi.getPlatformHelper().itemStackToCompund(getArmor()));
    }
    info.getCompoundData().put("Age", new TagInt(getAge()));
    if (hasChest()) {
        info.getCompoundData().put("Chest", MyPetApi.getPlatformHelper().itemStackToCompund(getChest()));
    }
    if (hasSaddle()) {
        info.getCompoundData().put("Saddle", MyPetApi.getPlatformHelper().itemStackToCompund(getSaddle()));
    }
    return info;
}
Also used : TagInt(de.keyle.knbt.TagInt) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Example 59 with TagCompound

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

the class MyIllusioner method writeExtendedInfo.

@Override
public TagCompound writeExtendedInfo() {
    TagCompound info = super.writeExtendedInfo();
    if (getEquipment(EquipmentSlot.MainHand) != null && getEquipment(EquipmentSlot.MainHand).getType() != Material.AIR) {
        TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(getEquipment(EquipmentSlot.MainHand));
        info.getCompoundData().put("Weapon", item);
    }
    if (getEquipment(EquipmentSlot.Helmet) != null && getEquipment(EquipmentSlot.Helmet).getType() != Material.AIR) {
        TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(getEquipment(EquipmentSlot.Helmet));
        info.getCompoundData().put("Banner", item);
    }
    return info;
}
Also used : TagCompound(de.keyle.knbt.TagCompound)

Example 60 with TagCompound

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

the class NbtRepository method createMyPetPlayer.

public static MyPetPlayer createMyPetPlayer(TagCompound playerTag) {
    MyPetPlayerImpl petPlayer = null;
    UUID mojangUUID = null;
    UUID internalUUID = null;
    String playerName = null;
    if (playerTag.containsKeyAs("UUID", TagCompound.class)) {
        TagCompound uuidTag = playerTag.getAs("UUID", TagCompound.class);
        if (uuidTag.getCompoundData().containsKey("Internal-UUID")) {
            internalUUID = UUID.fromString(uuidTag.getAs("Internal-UUID", TagString.class).getStringData());
        }
        if (uuidTag.getCompoundData().containsKey("Mojang-UUID")) {
            mojangUUID = UUID.fromString(uuidTag.getAs("Mojang-UUID", TagString.class).getStringData());
        }
        if (uuidTag.containsKeyAs("Name", TagString.class)) {
            playerName = uuidTag.getAs("Name", TagString.class).getStringData();
        }
    }
    if (playerTag.containsKeyAs("Name", TagString.class)) {
        playerName = playerTag.getAs("Name", TagString.class).getStringData();
    }
    if (internalUUID == null) {
        return null;
    }
    if (mojangUUID != null) {
        petPlayer = new MyPetPlayerImpl(internalUUID, mojangUUID);
        petPlayer.setLastKnownName(playerName);
    } else if (playerName != null) {
        petPlayer = new MyPetPlayerImpl(internalUUID, playerName);
        petPlayer.setLastKnownName(playerName);
    }
    if (petPlayer != null) {
        petPlayer.load(playerTag);
    }
    return petPlayer;
}
Also used : MyPetPlayerImpl(de.Keyle.MyPet.util.player.MyPetPlayerImpl) TagString(de.keyle.knbt.TagString) TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound)

Aggregations

TagCompound (de.keyle.knbt.TagCompound)199 TagInt (de.keyle.knbt.TagInt)67 TagByte (de.keyle.knbt.TagByte)65 TagList (de.keyle.knbt.TagList)57 ItemStack (org.bukkit.inventory.ItemStack)53 ArrayList (java.util.ArrayList)27 TagString (de.keyle.knbt.TagString)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 CompoundTag (net.minecraft.nbt.CompoundTag)12 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)11 TagShort (de.keyle.knbt.TagShort)10 HashSet (java.util.HashSet)9 MaterialData (org.bukkit.material.MaterialData)9 ListTag (net.minecraft.nbt.ListTag)8 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)6 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)6 TagBase (de.keyle.knbt.TagBase)5 List (java.util.List)5 ItemStack (net.minecraft.world.item.ItemStack)4 WorldGroup (de.Keyle.MyPet.api.WorldGroup)3