Search in sources :

Example 16 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer 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 17 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer 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);
                Optional<RepositoryMyPetConverterService> converter = MyPetApi.getServiceManager().getService(RepositoryMyPetConverterService.class);
                if (converter.isPresent()) {
                    converter.get().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 18 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class SqLiteRepository method getAllMyPetPlayers.

@Override
public List<MyPetPlayer> getAllMyPetPlayers() {
    try {
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM players;");
        List<MyPetPlayer> players = new ArrayList<>();
        MyPetPlayer player;
        while (true) {
            player = resultSetToMyPetPlayer(resultSet);
            if (player == null) {
                break;
            }
            players.add(player);
        }
        return players;
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return new ArrayList<>();
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer)

Example 19 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class SqLiteRepository method getAllMyPets.

@Override
public List<StoredMyPet> getAllMyPets() {
    try {
        List<MyPetPlayer> playerList = getAllMyPetPlayers();
        Map<UUID, MyPetPlayer> owners = new HashMap<>();
        for (MyPetPlayer player : playerList) {
            owners.put(player.getInternalUUID(), player);
        }
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM pets;");
        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.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.setHungerValue(resultSet.getInt("hunger"));
            pet.setWorldGroup(resultSet.getString("world_group"));
            pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
            String skillTreeName = resultSet.getString("skilltree");
            if (skillTreeName != null) {
                if (SkillTreeMobType.byPetType(pet.getPetType()) != null) {
                    SkillTreeMobType mobType = SkillTreeMobType.byPetType(pet.getPetType());
                    if (mobType.hasSkillTree(skillTreeName)) {
                        pet.setSkilltree(mobType.getSkillTree(skillTreeName));
                    }
                }
            }
            pet.setSkills(TagStream.readTag(resultSet.getBytes("skills"), true));
            pet.setInfo(TagStream.readTag(resultSet.getBytes("info"), true));
            pets.add(pet);
        }
        return pets;
    } catch (SQLException | IOException e) {
        e.printStackTrace();
    }
    return new ArrayList<>();
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) IOException(java.io.IOException) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 20 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class MinigamesHook method onSpectateMinigame.

@EventHandler
public void onSpectateMinigame(SpectateMinigameEvent event) {
    if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
        MyPetPlayer player = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
        if (player.hasMyPet() && player.getMyPet().getStatus() == MyPet.PetState.Here) {
            player.getMyPet().removePet();
            player.getPlayer().sendMessage(Translation.getString("Message.No.AllowedHere", player.getPlayer()));
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)46 EventHandler (org.bukkit.event.EventHandler)19 MyPet (de.Keyle.MyPet.api.entity.MyPet)17 Player (org.bukkit.entity.Player)16 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)14 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)8 WorldGroup (de.Keyle.MyPet.api.WorldGroup)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 TagCompound (de.keyle.knbt.TagCompound)5 List (java.util.List)5 UUID (java.util.UUID)4 Optional (com.google.common.base.Optional)3 RepositoryCallback (de.Keyle.MyPet.api.repository.RepositoryCallback)3 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)3 SqLiteRepository (de.Keyle.MyPet.repository.types.SqLiteRepository)3 MyPetPlayerImpl (de.Keyle.MyPet.util.player.MyPetPlayerImpl)3 FancyMessage (de.keyle.fanciful.FancyMessage)3 IOException (java.io.IOException)3 MyPetSaveEvent (de.Keyle.MyPet.api.event.MyPetSaveEvent)2 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)2