From 2e6412f8b7fc113391df39ef5adab9ffba6c921a Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 15 Jun 2022 18:02:40 +0100 Subject: [PATCH] Added lazy health fix --- .../willfp/ecoenchants/EcoEnchantsPlugin.java | 4 ++- .../util/LazyHealthFixListener.java | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/LazyHealthFixListener.java diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index ee5235fa..281c978a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -23,6 +23,7 @@ import com.willfp.ecoenchants.enchantments.support.obtaining.EnchantingListeners import com.willfp.ecoenchants.enchantments.support.obtaining.LootPopulator; import com.willfp.ecoenchants.enchantments.support.obtaining.VillagerListeners; import com.willfp.ecoenchants.enchantments.util.ItemConversions; +import com.willfp.ecoenchants.enchantments.util.LazyHealthFixListener; import com.willfp.ecoenchants.enchantments.util.TimedRunnable; import com.willfp.ecoenchants.enchantments.util.WatcherTriggers; import com.willfp.ecoenchants.integrations.mythicmobs.MythicMobsManager; @@ -158,7 +159,8 @@ public class EcoEnchantsPlugin extends LibReforgePlugin { new VillagerListeners(this), new ItemConversions(this), new CustomEnchantEnableListeners(this), - new CustomEcoEnchantRequirementListeners(this) + new CustomEcoEnchantRequirementListeners(this), + new LazyHealthFixListener(this) ); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/LazyHealthFixListener.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/LazyHealthFixListener.java new file mode 100644 index 00000000..4b109237 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/LazyHealthFixListener.java @@ -0,0 +1,27 @@ +package com.willfp.ecoenchants.enchantments.util; + +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.PluginDependent; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.jetbrains.annotations.NotNull; + +public class LazyHealthFixListener extends PluginDependent implements Listener { + public LazyHealthFixListener(@NotNull final EcoPlugin plugin) { + super(plugin); + } + + @EventHandler + public void onJoin(@NotNull final PlayerJoinEvent event) { + Player player = event.getPlayer(); + + if (player.getHealth() >= 19.0) { + this.getPlugin().getScheduler().runLater(3, () -> player.setHealth( + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() + )); + } + } +}