From 519d469cb28ca07c4f60a34abde761ad25f85523 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Tue, 7 Dec 2021 22:54:48 -0500 Subject: [PATCH] Add null check to XP gain handler, fixes #4663 (#4677) * Add null check to XP gain handler, fixes #4663 Co-authored-by: Robert Alan Chapton --- src/main/java/com/gmail/nossr50/util/EventUtils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 828f43906..4dd661aba 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -379,14 +379,18 @@ public final class EventUtils { } public static boolean handleXpGainEvent(Player player, PrimarySkillType skill, float xpGained, XPGainReason xpGainReason) { + McMMOPlayer mmoPlayer = UserManager.getPlayer(player); + if(mmoPlayer == null) + return true; + McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, xpGained, xpGainReason); mcMMO.p.getServer().getPluginManager().callEvent(event); boolean isCancelled = event.isCancelled(); if (!isCancelled) { - UserManager.getPlayer(player).addXp(skill, event.getRawXpGained()); - UserManager.getPlayer(player).getProfile().registerXpGain(skill, event.getRawXpGained()); + mmoPlayer.addXp(skill, event.getRawXpGained()); + mmoPlayer.getProfile().registerXpGain(skill, event.getRawXpGained()); } return !isCancelled;