Search in sources :

Example 61 with TagCompound

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

the class RepositoryMyPetConverterService method v1_11_R1.

public void v1_11_R1(StoredMyPet pet) {
    TagCompound info = pet.getInfo();
    switch(pet.getPetType()) {
        case Horse:
            if (info.containsKey("Type")) {
                byte type = info.getAs("Type", TagByte.class).getByteData();
                switch(type) {
                    case 1:
                        pet.setPetType(MyPetType.Donkey);
                        break;
                    case 2:
                        pet.setPetType(MyPetType.Mule);
                        break;
                    case 3:
                        pet.setPetType(MyPetType.ZombieHorse);
                        break;
                    case 4:
                        pet.setPetType(MyPetType.SkeletonHorse);
                        break;
                }
                info.remove("Type");
            }
            break;
        case Skeleton:
            if (info.containsKey("Type")) {
                int type = info.getAs("Type", TagInt.class).getIntData();
                switch(type) {
                    case 1:
                        pet.setPetType(MyPetType.WitherSkeleton);
                        break;
                    case 2:
                        pet.setPetType(MyPetType.Stray);
                        break;
                }
                info.remove("Type");
            }
            if (info.containsKey("Wither")) {
                if (info.getAs("Wither", TagByte.class).getBooleanData()) {
                    pet.setPetType(MyPetType.WitherSkeleton);
                    info.remove("Wither");
                }
            }
            break;
        case Zombie:
            if (info.containsKey("Type")) {
                int type = info.getAs("Type", TagInt.class).getIntData();
                switch(type) {
                    case 6:
                        pet.setPetType(MyPetType.Husk);
                        break;
                    case 0:
                        break;
                    default:
                        if (type == 2) {
                            if (info.containsKey("Profession")) {
                                pet.setPetType(MyPetType.ZombieVillager);
                                info.put("Profession", new TagInt(info.getAs("Profession", TagInt.class).getIntData() - 1));
                            } else {
                                pet.setPetType(MyPetType.Husk);
                            }
                        } else {
                            pet.setPetType(MyPetType.ZombieVillager);
                            if (info.containsKey("Profession")) {
                                info.put("Profession", new TagInt(info.getAs("Profession", TagInt.class).getIntData() - 1));
                            }
                        }
                }
                info.remove("Type");
            }
            if (info.containsKey("Villager")) {
                if (info.getAs("Villager", TagByte.class).getBooleanData()) {
                    pet.setPetType(MyPetType.ZombieVillager);
                    info.remove("Villager");
                }
            }
            if (info.containsKey("Husk")) {
                if (info.getAs("Husk", TagByte.class).getBooleanData()) {
                    pet.setPetType(MyPetType.Husk);
                    info.remove("Husk");
                }
            }
            break;
        case Guardian:
            if (info.containsKey("Elder")) {
                if (info.getAs("Elder", TagByte.class).getBooleanData()) {
                    pet.setPetType(MyPetType.ElderGuardian);
                    info.remove("Elder");
                }
            }
            break;
    }
}
Also used : TagInt(de.keyle.knbt.TagInt) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Example 62 with TagCompound

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

the class NbtRepository method getMyPetPlayer.

@Override
public void getMyPetPlayer(final Player player, final RepositoryCallback<MyPetPlayer> callback) {
    if (callback != null) {
        for (TagCompound playerTag : playerTags.values()) {
            if (playerTag.containsKeyAs("UUID", TagCompound.class)) {
                TagCompound uuidTag = playerTag.getAs("UUID", TagCompound.class);
                if (uuidTag.getCompoundData().containsKey("Mojang-UUID")) {
                    if (UUID.fromString(uuidTag.getAs("Mojang-UUID", TagString.class).getStringData()).equals(player.getUniqueId())) {
                        MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
                        callback.run(myPetPlayer);
                        return;
                    }
                }
                if (uuidTag.getCompoundData().containsKey("Name")) {
                    if (uuidTag.getAs("Name", TagString.class).getStringData().equals(player.getName())) {
                        MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
                        callback.run(myPetPlayer);
                        return;
                    }
                }
                if (playerTag.getCompoundData().containsKey("Name")) {
                    if (playerTag.getAs("Name", TagString.class).getStringData().equals(player.getName())) {
                        MyPetPlayer myPetPlayer = createMyPetPlayer(playerTag);
                        callback.run(myPetPlayer);
                        return;
                    }
                }
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound)

Example 63 with TagCompound

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

the class NbtRepository method loadPlayers.

private int loadPlayers(TagList playerList) {
    int playerCount = 0;
    for (int i = 0; i < playerList.getReadOnlyList().size(); i++) {
        TagCompound playerTag = playerList.getTagAs(i, TagCompound.class);
        UUID internalUUID = getInternalUUID(playerTag);
        if (internalUUID != null) {
            playerTags.put(internalUUID, playerTag);
            playerCount++;
        }
    }
    return playerCount;
}
Also used : TagCompound(de.keyle.knbt.TagCompound)

Example 64 with TagCompound

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

the class NbtRepository method countMyPets.

@Override
public void countMyPets(MyPetType type, final RepositoryCallback<Integer> callback) {
    int counter = 0;
    for (TagCompound petTag : petTags.values()) {
        if (petTag.getAs("Type", TagString.class).equals(type.name())) {
            counter++;
        }
    }
    callback.run(counter);
}
Also used : TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound)

Example 65 with TagCompound

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

the class NbtRepository method getMyPet.

@Override
public void getMyPet(final UUID uuid, final RepositoryCallback<StoredMyPet> callback) {
    if (callback != null) {
        if (petTags.containsKey(uuid)) {
            TagCompound petTag = petTags.get(uuid);
            UUID ownerUUID;
            if (petTag.containsKeyAs("Internal-Owner-UUID", TagString.class)) {
                ownerUUID = UUID.fromString(petTag.getAs("Internal-Owner-UUID", TagString.class).getStringData());
            } else {
                return;
            }
            if (!playerTags.containsKey(ownerUUID)) {
                return;
            }
            MyPetPlayer owner = MyPetApi.getPlayerManager().getMyPetPlayer(ownerUUID);
            if (owner != null) {
                InactiveMyPet myPet = new InactiveMyPet(owner);
                myPet.load(petTag);
                List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
                for (RepositoryMyPetConverterService converter : converters) {
                    converter.convert(myPet);
                }
                callback.run(myPet);
            }
        }
    }
}
Also used : RepositoryMyPetConverterService(de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) 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