Search in sources :

Example 1 with Scheduler

use of de.Keyle.MyPet.api.util.Scheduler in project MyPet by xXKeyleXx.

the class MyPet method schedule.

public void schedule() {
    if (status != PetState.Despawned && getOwner().isOnline()) {
        for (SkillInstance skill : skills.getSkills()) {
            if (skill instanceof Scheduler) {
                ((Scheduler) skill).schedule();
            }
        }
        if (status == PetState.Dead) {
            respawnTime--;
            if (respawnTime <= 0) {
                respawnPet();
            } else if (MyPetApi.getPluginHookManager().isHookActive(VaultHook.class) && getOwner().hasAutoRespawnEnabled() && respawnTime >= getOwner().getAutoRespawnMin() && Permissions.has(getOwner().getPlayer(), "MyPet.user.respawn")) {
                double cost = respawnTime * Configuration.Respawn.COSTS_FACTOR + Configuration.Respawn.COSTS_FIXED;
                VaultHook vaultHook = MyPetApi.getPluginHookManager().getHook(VaultHook.class);
                if (vaultHook.canPay(getOwner().getPlayer(), cost)) {
                    vaultHook.pay(getOwner().getPlayer(), cost);
                    getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Respawn.Paid", petOwner.getLanguage()), petName, cost + " " + vaultHook.currencyNameSingular()));
                    respawnTime = 1;
                }
            }
        }
        if (status == PetState.Here) {
            if (Configuration.HungerSystem.USE_HUNGER_SYSTEM) {
                if (saturation > 1 && --hungerTime <= 0) {
                    saturation--;
                    hungerTime = Configuration.HungerSystem.HUNGER_SYSTEM_TIME;
                    if (saturation == 66) {
                        getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Rumbling", getOwner()), getPetName()));
                    } else if (saturation == 33) {
                        getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Hungry", getOwner()), getPetName()));
                    } else if (saturation == 1) {
                        getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Starving", getOwner()), getPetName()));
                    }
                }
                if (saturation == 1 && getHealth() >= 2) {
                    getEntity().get().damage(1.);
                }
            }
        }
    }
}
Also used : SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) Scheduler(de.Keyle.MyPet.api.util.Scheduler) VaultHook(de.Keyle.MyPet.util.hooks.VaultHook)

Aggregations

SkillInstance (de.Keyle.MyPet.api.skill.SkillInstance)1 Scheduler (de.Keyle.MyPet.api.util.Scheduler)1 VaultHook (de.Keyle.MyPet.util.hooks.VaultHook)1