From 966ef01b363299f918090a4f157acb2a05ccd978 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 3 Apr 2022 01:10:25 +0200 Subject: [PATCH] Fixed an issue with citizens --- .../listener/option/DeathExperienceLoss.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/listener/option/DeathExperienceLoss.java b/src/main/java/net/Indyuce/mmocore/listener/option/DeathExperienceLoss.java index 83de996a..b6afa74d 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/option/DeathExperienceLoss.java +++ b/src/main/java/net/Indyuce/mmocore/listener/option/DeathExperienceLoss.java @@ -1,23 +1,25 @@ package net.Indyuce.mmocore.listener.option; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.ConfigMessage; +import net.Indyuce.mmocore.api.player.PlayerData; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.ConfigMessage; -import net.Indyuce.mmocore.api.player.PlayerData; - public class DeathExperienceLoss implements Listener { - private final double loss = MMOCore.plugin.getConfig().getDouble("death-exp-loss.percent") / 100; + private final double loss = MMOCore.plugin.getConfig().getDouble("death-exp-loss.percent") / 100; - @EventHandler(priority = EventPriority.HIGH) - public void a(PlayerDeathEvent event) { - PlayerData data = PlayerData.get(event.getEntity()); - int loss = (int) (data.getExperience() * this.loss); - data.setExperience(data.getExperience() - loss); - if(data.isOnline()) - new ConfigMessage("death-exp-loss").addPlaceholders("loss", "" + loss).send(data.getPlayer()); - } + @EventHandler(priority = EventPriority.HIGH) + public void a(PlayerDeathEvent event) { + if (!PlayerData.has(event.getEntity())) + return; + + PlayerData data = PlayerData.get(event.getEntity()); + int loss = (int) (data.getExperience() * this.loss); + data.setExperience(data.getExperience() - loss); + if (data.isOnline()) + new ConfigMessage("death-exp-loss").addPlaceholders("loss", "" + loss).send(data.getPlayer()); + } }