Added lazy health fix

This commit is contained in:
Auxilor 2022-06-15 18:02:40 +01:00
parent acadaf7371
commit 2e6412f8b7
2 changed files with 30 additions and 1 deletions

View File

@ -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)
);
}

View File

@ -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<EcoPlugin> 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()
));
}
}
}