Search in sources :

Example 6 with InactiveMyPet

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

the class MyPetManager method getInactiveMyPetFromMyPet.

// Inactive -----------------------------------------------------------------
public StoredMyPet getInactiveMyPetFromMyPet(StoredMyPet myPet) {
    InactiveMyPet inactiveMyPet = new InactiveMyPet(myPet.getOwner());
    inactiveMyPet.setUUID(myPet.getUUID());
    inactiveMyPet.setPetName(myPet.getPetName());
    inactiveMyPet.setWorldGroup(myPet.getWorldGroup());
    inactiveMyPet.setExp(myPet.getExp());
    inactiveMyPet.setHealth(myPet.getHealth());
    inactiveMyPet.setSaturation(myPet.getSaturation());
    inactiveMyPet.setRespawnTime(myPet.getRespawnTime());
    inactiveMyPet.setSkills(myPet.getSkillInfo());
    inactiveMyPet.setInfo(myPet.getInfo());
    inactiveMyPet.setPetType(myPet.getPetType());
    inactiveMyPet.setSkilltree(myPet.getSkilltree());
    inactiveMyPet.setLastUsed(myPet.getLastUsed());
    inactiveMyPet.wantsToRespawn = myPet.wantsToRespawn();
    return inactiveMyPet;
}
Also used : InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet)

Example 7 with InactiveMyPet

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

the class MongoDbRepository method documentToMyPet.

// Pets ------------------------------------------------------------------------------------------------------------
private StoredMyPet documentToMyPet(MyPetPlayer owner, Document document) {
    try {
        InactiveMyPet pet = new InactiveMyPet(owner);
        pet.setUUID(UUID.fromString(document.getString("uuid")));
        pet.setWorldGroup(document.getString("world_group"));
        pet.setExp(document.getDouble("exp"));
        pet.setHealth(document.getDouble("health"));
        pet.setRespawnTime(document.getInteger("respawn_time"));
        pet.setPetName(document.getString("name"));
        pet.setPetType(MyPetType.valueOf(document.getString("type")));
        pet.setLastUsed(document.getLong("last_used"));
        pet.setSaturation(((Number) document.get("hunger")).doubleValue());
        pet.wantsToRespawn = document.getBoolean("wants_to_spawn");
        String skillTreeName = document.getString("skilltree");
        if (skillTreeName != null) {
            Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
            if (skilltree != null) {
                pet.setSkilltree(skilltree);
            }
        }
        try {
            pet.setSkills(TagStream.readTag(((Binary) document.get("skills")).getData(), true));
        } catch (ZipException exception) {
            MyPetApi.getMyPetLogger().warning("Pet skills of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
        }
        try {
            pet.setInfo(TagStream.readTag(((Binary) document.get("info")).getData(), true));
        } catch (ZipException exception) {
            MyPetApi.getMyPetLogger().warning("Pet info of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
        }
        List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
        for (RepositoryMyPetConverterService converter : converters) {
            converter.convert(pet);
        }
        return pet;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
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) ZipException(java.util.zip.ZipException) Binary(org.bson.types.Binary) IOException(java.io.IOException)

Example 8 with InactiveMyPet

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

the class NbtRepository method getMyPets.

@Override
public void getMyPets(final MyPetPlayer owner, final RepositoryCallback<List<StoredMyPet>> callback) {
    if (callback != null) {
        List<StoredMyPet> petList = new ArrayList<>();
        for (UUID petUUID : petPlayerMultiMap.get(owner.getInternalUUID())) {
            if (petTags.containsKey(petUUID)) {
                InactiveMyPet myPet = new InactiveMyPet(owner);
                myPet.load(petTags.get(petUUID));
                List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
                for (RepositoryMyPetConverterService converter : converters) {
                    converter.convert(myPet);
                }
                petList.add(myPet);
            }
        }
        callback.run(petList);
    }
}
Also used : RepositoryMyPetConverterService(de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 9 with InactiveMyPet

use of de.Keyle.MyPet.entity.InactiveMyPet 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)

Example 10 with InactiveMyPet

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

the class MySqlRepository method getAllMyPets.

@Override
public List<StoredMyPet> getAllMyPets() {
    try (Connection connection = dataSource.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM pets;")) {
        List<MyPetPlayer> playerList = getAllMyPetPlayers();
        Map<UUID, MyPetPlayer> owners = new HashMap<>();
        for (MyPetPlayer player : playerList) {
            owners.put(player.getInternalUUID(), player);
        }
        List<StoredMyPet> pets = new ArrayList<>();
        while (resultSet.next()) {
            if (!owners.containsKey(UUID.fromString(resultSet.getString("owner_uuid")))) {
                continue;
            }
            MyPetPlayer owner = owners.get(UUID.fromString(resultSet.getString("owner_uuid")));
            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(resultSet.getString("name"));
            pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
            pet.setLastUsed(resultSet.getLong("last_used"));
            pet.setSaturation(resultSet.getInt("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.getBlob("skills").getBinaryStream(), true));
            pet.setInfo(TagStream.readTag(resultSet.getBlob("info").getBinaryStream(), true));
            pets.add(pet);
        }
        return pets;
    } catch (SQLException | IOException e) {
        e.printStackTrace();
    }
    return new ArrayList<>();
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) TagString(de.keyle.knbt.TagString) IOException(java.io.IOException) 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