Search in sources :

Example 41 with MyPetPlayer

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

the class PlayerListener method onMyPet.

@EventHandler
public void onMyPet(PlayerTeleportEvent event) {
    if (!event.getPlayer().isOnline()) {
        return;
    }
    if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer().getName())) {
        final MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
        if (myPetPlayer.hasMyPet()) {
            final MyPet myPet = myPetPlayer.getMyPet();
            if (myPet.getStatus() == MyPet.PetState.Here) {
                if (myPet.getLocation().get().getWorld() != event.getTo().getWorld() || MyPetApi.getPlatformHelper().distance(myPet.getLocation().get(), event.getTo()) > 10) {
                    final boolean sameWorld = myPet.getLocation().get().getWorld() == event.getTo().getWorld();
                    myPet.removePet();
                    new BukkitRunnable() {

                        public void run() {
                            if (myPetPlayer.isOnline() && myPetPlayer.hasMyPet()) {
                                MyPet runMyPet = myPetPlayer.getMyPet();
                                switch(runMyPet.createEntity()) {
                                    case Canceled:
                                        myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", myPetPlayer), runMyPet.getPetName()));
                                        break;
                                    case NoSpace:
                                        if (sameWorld) {
                                            myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", myPetPlayer), runMyPet.getPetName()));
                                        }
                                        break;
                                    case Flying:
                                        if (sameWorld) {
                                            myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", myPetPlayer), runMyPet.getPetName()));
                                        }
                                        break;
                                    case NotAllowed:
                                        myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", myPetPlayer), runMyPet.getPetName()));
                                        break;
                                }
                            }
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 20L);
                }
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPet(de.Keyle.MyPet.api.entity.MyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 42 with MyPetPlayer

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

the class PlayerListener method on.

@EventHandler
public void on(final PlayerDeathEvent event) {
    if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getEntity())) {
        MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getEntity());
        if (myPetPlayer.hasMyPet()) {
            final MyPet myPet = myPetPlayer.getMyPet();
            if (myPet.getStatus() == MyPet.PetState.Here && Configuration.Skilltree.Skill.Inventory.DROP_WHEN_OWNER_DIES) {
                if (myPet.getSkills().isSkillActive(Inventory.class)) {
                    CustomInventory inv = myPet.getSkills().getSkill(Inventory.class).get().getInventory();
                    inv.dropContentAt(myPet.getLocation().get());
                }
            }
            myPet.removePet();
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPet(de.Keyle.MyPet.api.entity.MyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) CustomInventory(de.Keyle.MyPet.api.util.inventory.CustomInventory) EventHandler(org.bukkit.event.EventHandler)

Example 43 with MyPetPlayer

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

the class PlayerListener method on.

@EventHandler
public void on(final PlayerRespawnEvent event) {
    if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
        final MyPetPlayer respawnedMyPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
        final MyPet myPet = respawnedMyPetPlayer.getMyPet();
        if (respawnedMyPetPlayer.hasMyPet() && myPet.wantsToRespawn()) {
            new BukkitRunnable() {

                public void run() {
                    if (respawnedMyPetPlayer.hasMyPet()) {
                        MyPet runMyPet = respawnedMyPetPlayer.getMyPet();
                        switch(runMyPet.createEntity()) {
                            case Canceled:
                                respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", respawnedMyPetPlayer), runMyPet.getPetName()));
                                break;
                            case NoSpace:
                                respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", respawnedMyPetPlayer), runMyPet.getPetName()));
                                break;
                            case NotAllowed:
                                respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", respawnedMyPetPlayer), runMyPet.getPetName()));
                                break;
                            case Dead:
                                if (runMyPet != myPet) {
                                    respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Call.Dead", respawnedMyPetPlayer), runMyPet.getPetName(), runMyPet.getRespawnTime()));
                                }
                                break;
                            case Flying:
                                respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", respawnedMyPetPlayer), runMyPet.getPetName()));
                                break;
                            case Success:
                                if (runMyPet != myPet) {
                                    respawnedMyPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Command.Call.Success", respawnedMyPetPlayer), runMyPet.getPetName()));
                                }
                                break;
                        }
                    }
                }
            }.runTaskLater(MyPetApi.getPlugin(), 25L);
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPet(de.Keyle.MyPet.api.entity.MyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Example 44 with MyPetPlayer

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

the class PlayerListener method onMyPetPlayerChangeWorld.

@EventHandler
public void onMyPetPlayerChangeWorld(final PlayerChangedWorldEvent event) {
    if (!event.getPlayer().isOnline()) {
        return;
    }
    if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
        final MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
        final WorldGroup fromGroup = WorldGroup.getGroupByWorld(event.getFrom().getName());
        final WorldGroup toGroup = WorldGroup.getGroupByWorld(event.getPlayer().getWorld().getName());
        final MyPet myPet = myPetPlayer.hasMyPet() ? myPetPlayer.getMyPet() : null;
        final BukkitRunnable callPet = new BukkitRunnable() {

            public void run() {
                if (myPetPlayer.isOnline() && myPetPlayer.hasMyPet()) {
                    MyPet runMyPet = myPetPlayer.getMyPet();
                    switch(runMyPet.createEntity()) {
                        case Canceled:
                            myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", myPetPlayer), runMyPet.getPetName()));
                            break;
                        case NoSpace:
                            myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", myPetPlayer), runMyPet.getPetName()));
                            break;
                        case NotAllowed:
                            myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", myPetPlayer), runMyPet.getPetName()));
                            break;
                        case Dead:
                            if (runMyPet != myPet) {
                                myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Call.Dead", myPetPlayer), runMyPet.getPetName(), runMyPet.getRespawnTime()));
                            }
                            break;
                        case Flying:
                            myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", myPetPlayer), runMyPet.getPetName()));
                            break;
                        case Success:
                            if (runMyPet != myPet) {
                                myPetPlayer.sendMessage(Util.formatText(Translation.getString("Message.Command.Call.Success", myPetPlayer), runMyPet.getPetName()));
                            }
                            break;
                    }
                }
            }
        };
        if (fromGroup != toGroup) {
            final boolean hadMyPetInFromWorld = MyPetApi.getMyPetManager().deactivateMyPet(myPetPlayer, true);
            if (myPetPlayer.hasMyPetInWorldGroup(toGroup)) {
                final UUID groupMyPetUUID = myPetPlayer.getMyPetForWorldGroup(toGroup);
                MyPetApi.getRepository().getMyPets(myPetPlayer, new RepositoryCallback<List<StoredMyPet>>() {

                    @Override
                    public void callback(List<StoredMyPet> pets) {
                        for (StoredMyPet myPet : pets) {
                            if (myPet.getUUID().equals(groupMyPetUUID)) {
                                MyPetApi.getMyPetManager().activateMyPet(myPet);
                                break;
                            }
                        }
                        if (myPetPlayer.hasMyPet()) {
                            if (myPetPlayer.getMyPet().wantsToRespawn()) {
                                callPet.runTaskLater(MyPetApi.getPlugin(), 20L);
                            }
                        } else {
                            myPetPlayer.setMyPetForWorldGroup(toGroup, null);
                        }
                    }
                });
            } else if (hadMyPetInFromWorld) {
                myPetPlayer.getPlayer().sendMessage(Translation.getString("Message.MultiWorld.NoActivePetInThisWorld", myPetPlayer));
            }
        } else if (myPet != null) {
            if (myPet.wantsToRespawn()) {
                callPet.runTaskLater(MyPetApi.getPlugin(), 20L);
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) WorldGroup(de.Keyle.MyPet.api.WorldGroup) MyPet(de.Keyle.MyPet.api.entity.MyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) List(java.util.List) UUID(java.util.UUID) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) EventHandler(org.bukkit.event.EventHandler)

Example 45 with MyPetPlayer

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

the class NbtRepository method getMyPetPlayer.

public void getMyPetPlayer(final UUID uuid, final RepositoryCallback<MyPetPlayer> callback) {
    if (playerTags.containsKey(uuid)) {
        if (callback != null) {
            MyPetPlayer myPetPlayer = createMyPetPlayer(playerTags.get(uuid));
            callback.run(myPetPlayer);
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer)

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