From 160c5d5699877fd32dff494b1f181a3c033a4ac1 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 15 Oct 2023 18:43:06 +0200 Subject: [PATCH] Fixed exp resetting on death --- .../option/VanillaExperienceOverride.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java index 530390f7..a95e8d40 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java @@ -8,7 +8,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.enchantment.EnchantItemEvent; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerExpChangeEvent; +import org.bukkit.event.player.PlayerRespawnEvent; public class VanillaExperienceOverride implements Listener { @@ -16,10 +18,20 @@ public class VanillaExperienceOverride implements Listener { * When picking up exp orbs or any action like that */ @EventHandler(priority = EventPriority.HIGHEST) - public void a(PlayerExpChangeEvent event) { + public void cancelChange(PlayerExpChangeEvent event) { event.setAmount(0); } + @EventHandler(priority = EventPriority.HIGHEST) + public void cancelDrop(PlayerDeathEvent event) { + event.setDroppedExp(0); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void cancelChange(PlayerRespawnEvent event) { + Bukkit.getScheduler().runTask(MMOCore.plugin, () -> PlayerData.get(event.getPlayer()).refreshVanillaExp()); + } + /** * This event is not supported by the expChangeEvent. Since the event is * actually called before applying the enchant and consuming levels, we must @@ -28,7 +40,7 @@ public class VanillaExperienceOverride implements Listener { * {@link EnchantItemEvent#setExpLevelCost(int)} does NOT work */ @EventHandler - public void b(EnchantItemEvent event) { + public void cancelChange(EnchantItemEvent event) { Player player = event.getEnchanter(); Bukkit.getScheduler().runTask(MMOCore.plugin, () -> player.setLevel(PlayerData.get(player).getLevel())); }