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 <nossr50@gmail.com>
This commit is contained in:
PikaMug 2021-12-07 22:54:48 -05:00 committed by GitHub
parent cf67e3502a
commit 519d469cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -379,14 +379,18 @@ public final class EventUtils {
} }
public static boolean handleXpGainEvent(Player player, PrimarySkillType skill, float xpGained, XPGainReason xpGainReason) { 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); McMMOPlayerXpGainEvent event = new McMMOPlayerXpGainEvent(player, skill, xpGained, xpGainReason);
mcMMO.p.getServer().getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
boolean isCancelled = event.isCancelled(); boolean isCancelled = event.isCancelled();
if (!isCancelled) { if (!isCancelled) {
UserManager.getPlayer(player).addXp(skill, event.getRawXpGained()); mmoPlayer.addXp(skill, event.getRawXpGained());
UserManager.getPlayer(player).getProfile().registerXpGain(skill, event.getRawXpGained()); mmoPlayer.getProfile().registerXpGain(skill, event.getRawXpGained());
} }
return !isCancelled; return !isCancelled;