Search in sources :

Example 1 with CustomRegenEvent

use of com.archyx.aureliumskills.api.event.CustomRegenEvent in project AureliumSkills by Archy-X.

the class Regeneration method startRegen.

public void startRegen() {
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
        if (OptionL.getBoolean(Option.REGENERATION_CUSTOM_REGEN_MECHANICS)) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData != null) {
                    // Check for disabled world
                    if (!plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
                        if (!player.isDead()) {
                            AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
                            if (attribute != null) {
                                if (player.getHealth() < attribute.getValue()) {
                                    if (player.getFoodLevel() >= 14 && player.getFoodLevel() < 20) {
                                        double amountGained = Math.min(OptionL.getDouble(Option.REGENERATION_BASE_REGEN) + playerData.getStatLevel(Stats.REGENERATION) * OptionL.getDouble(Option.REGENERATION_HUNGER_ALMOST_FULL_MODIFIER), attribute.getValue() - player.getHealth());
                                        CustomRegenEvent event = new CustomRegenEvent(player, amountGained, RegenReason.HUNGER_FULL);
                                        Bukkit.getPluginManager().callEvent(event);
                                        if (!event.isCancelled()) {
                                            player.setHealth(player.getHealth() + amountGained);
                                            if (player.getFoodLevel() - 1 >= 0) {
                                                player.setFoodLevel(player.getFoodLevel() - 1);
                                            }
                                        }
                                    } else if (player.getFoodLevel() == 20 && player.getSaturation() == 0) {
                                        double amountGained = Math.min(OptionL.getDouble(Option.REGENERATION_BASE_REGEN) + playerData.getStatLevel(Stats.REGENERATION) * OptionL.getDouble(Option.REGENERATION_HUNGER_FULL_MODIFIER), attribute.getValue() - player.getHealth());
                                        CustomRegenEvent event = new CustomRegenEvent(player, amountGained, RegenReason.HUNGER_ALMOST_FULL);
                                        Bukkit.getPluginManager().callEvent(event);
                                        if (!event.isCancelled()) {
                                            player.setHealth(player.getHealth() + amountGained);
                                            if (player.getFoodLevel() - 1 >= 0) {
                                                player.setFoodLevel(player.getFoodLevel() - 1);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }, 0L, OptionL.getInt(Option.REGENERATION_HUNGER_DELAY));
}
Also used : Player(org.bukkit.entity.Player) AttributeInstance(org.bukkit.attribute.AttributeInstance) CustomRegenEvent(com.archyx.aureliumskills.api.event.CustomRegenEvent) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 2 with CustomRegenEvent

use of com.archyx.aureliumskills.api.event.CustomRegenEvent in project AureliumSkills by Archy-X.

the class Regeneration method startSaturationRegen.

public void startSaturationRegen() {
    Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
        if (OptionL.getBoolean(Option.REGENERATION_CUSTOM_REGEN_MECHANICS)) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData != null) {
                    // Check for disabled world
                    if (!plugin.getWorldManager().isInDisabledWorld(player.getLocation())) {
                        if (!player.isDead()) {
                            if (player.getSaturation() > 0 && player.getFoodLevel() >= 20) {
                                AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
                                if (attribute != null) {
                                    double amountGained = Math.min(OptionL.getDouble(Option.REGENERATION_BASE_REGEN) + playerData.getStatLevel(Stats.REGENERATION) * OptionL.getDouble(Option.REGENERATION_SATURATED_MODIFIER), attribute.getValue() - player.getHealth());
                                    CustomRegenEvent event = new CustomRegenEvent(player, amountGained, RegenReason.SATURATED);
                                    Bukkit.getPluginManager().callEvent(event);
                                    if (!event.isCancelled()) {
                                        player.setHealth(player.getHealth() + amountGained);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }, 0L, OptionL.getInt(Option.REGENERATION_SATURATED_DELAY));
}
Also used : Player(org.bukkit.entity.Player) AttributeInstance(org.bukkit.attribute.AttributeInstance) CustomRegenEvent(com.archyx.aureliumskills.api.event.CustomRegenEvent) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Aggregations

CustomRegenEvent (com.archyx.aureliumskills.api.event.CustomRegenEvent)2 PlayerData (com.archyx.aureliumskills.data.PlayerData)2 AttributeInstance (org.bukkit.attribute.AttributeInstance)2 Player (org.bukkit.entity.Player)2