Search in sources :

Example 11 with InactiveMyPet

use of de.Keyle.MyPet.entity.InactiveMyPet in project MyPet by xXKeyleXx.

the class SqLiteRepository method resultSetToMyPet.

// Pets ------------------------------------------------------------------------------------------------------------
private List<StoredMyPet> resultSetToMyPet(MyPetPlayer owner, ResultSet resultSet, boolean next) {
    List<StoredMyPet> pets = new ArrayList<>();
    try {
        while (!next || resultSet.next()) {
            next = true;
            InactiveMyPet pet = new InactiveMyPet(owner);
            pet.setUUID(UUID.fromString(resultSet.getString("uuid")));
            pet.setWorldGroup(resultSet.getString("world_group"));
            pet.setExp(resultSet.getDouble("exp"));
            pet.setHealth(resultSet.getDouble("health"));
            pet.setRespawnTime(resultSet.getInt("respawn_time"));
            pet.setPetName(new String(resultSet.getBytes("name"), StandardCharsets.UTF_8));
            pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
            pet.setLastUsed(resultSet.getLong("last_used"));
            pet.setSaturation(resultSet.getDouble("hunger"));
            pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
            String skillTreeName = resultSet.getString("skilltree");
            if (skillTreeName != null) {
                Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
                if (skilltree != null) {
                    pet.setSkilltree(skilltree);
                }
            }
            pet.setSkills(TagStream.readTag(resultSet.getBytes("skills"), true));
            pet.setInfo(TagStream.readTag(resultSet.getBytes("info"), true));
            List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
            for (RepositoryMyPetConverterService converter : converters) {
                converter.convert(pet);
            }
            pets.add(pet);
        }
    } catch (SQLException | IOException e) {
        e.printStackTrace();
    }
    return pets;
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) RepositoryMyPetConverterService(de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) IOException(java.io.IOException) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 12 with InactiveMyPet

use of de.Keyle.MyPet.entity.InactiveMyPet in project MyPet by xXKeyleXx.

the class NbtRepository method getAllMyPets.

// Pets ------------------------------------------------------------------------------------------------------------
@Override
public List<StoredMyPet> getAllMyPets() {
    List<MyPetPlayer> playerList = getAllMyPetPlayers();
    Map<UUID, MyPetPlayer> owners = new HashMap<>();
    for (MyPetPlayer player : playerList) {
        owners.put(player.getInternalUUID(), player);
    }
    List<StoredMyPet> pets = new ArrayList<>();
    for (UUID petUUID : petTags.keySet()) {
        TagCompound petTag = petTags.get(petUUID);
        if (petTag.containsKeyAs("Internal-Owner-UUID", TagString.class)) {
            UUID ownerUUID = UUID.fromString(petTag.getAs("Internal-Owner-UUID", TagString.class).getStringData());
            if (owners.containsKey(ownerUUID)) {
                InactiveMyPet myPet = new InactiveMyPet(owners.get(ownerUUID));
                myPet.load(petTag);
                pets.add(myPet);
            }
        }
    }
    return pets;
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) TagCompound(de.keyle.knbt.TagCompound) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Aggregations

InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)12 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)7 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)6 RepositoryMyPetConverterService (de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService)6 Skilltree (de.Keyle.MyPet.api.skill.skilltree.Skilltree)5 IOException (java.io.IOException)5 TagString (de.keyle.knbt.TagString)4 WorldGroup (de.Keyle.MyPet.api.WorldGroup)3 MyPetSaveEvent (de.Keyle.MyPet.api.event.MyPetSaveEvent)3 TagCompound (de.keyle.knbt.TagCompound)3 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2 MyPetCreateEvent (de.Keyle.MyPet.api.event.MyPetCreateEvent)2 ZipException (java.util.zip.ZipException)2 Player (org.bukkit.entity.Player)2 MyPet (de.Keyle.MyPet.api.entity.MyPet)1 MyPetBukkitEntity (de.Keyle.MyPet.api.entity.MyPetBukkitEntity)1 LeashFlag (de.Keyle.MyPet.api.entity.leashing.LeashFlag)1 MyPetTypeNotFoundException (de.Keyle.MyPet.api.exceptions.MyPetTypeNotFoundException)1 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)1 Settings (de.Keyle.MyPet.api.util.configuration.settings.Settings)1