From 456e64456df3607f389eae3f97e1fb9598110da6 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 30 Mar 2019 17:44:06 -0700 Subject: [PATCH] Fixing an issue with mmoedit triggering notifications for skills already unlocked --- Changelog.txt | 2 ++ .../commands/experience/MmoeditCommand.java | 2 +- .../java/com/gmail/nossr50/util/EventUtils.java | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Changelog.txt b/Changelog.txt index d1d920694..7b5f0c9fe 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -153,6 +153,8 @@ Version 2.2.0 Version 2.1.31 Fixed a bug where certain SubSkills did not properly send unlock or rank up notifications Fixed a bug where unlock notifications would send simultaneously for a specific skill (still happens if mmoedit changes all skill levels on a player at once) + Fixed NPE with grabbing offline player skill ranks through certain API methods (thanks Ineusia) + Updated German language locale (thanks OverCrave) Version 2.1.30 Fixed double drops behaving oddly diff --git a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java index d5d6de39a..ded4aaa18 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java @@ -36,7 +36,7 @@ public class MmoeditCommand extends ExperienceCommand { return; } - EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND); + EventUtils.handleLevelChangeEventEdit(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel); } @Override diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index e807e01c2..a96474f35 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -198,6 +198,22 @@ public class EventUtils { return !isCancelled; } + public static boolean handleLevelChangeEventEdit(Player player, PrimarySkillType skill, int levelsChanged, float xpRemoved, boolean isLevelUp, XPGainReason xpGainReason, int oldLevel) { + McMMOPlayerLevelChangeEvent event = isLevelUp ? new McMMOPlayerLevelUpEvent(player, skill, levelsChanged - oldLevel, xpGainReason) : new McMMOPlayerLevelDownEvent(player, skill, levelsChanged, xpGainReason); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + boolean isCancelled = event.isCancelled(); + + if (isCancelled) { + PlayerProfile profile = UserManager.getPlayer(player).getProfile(); + + profile.modifySkill(skill, profile.getSkillLevel(skill) - (isLevelUp ? levelsChanged : -levelsChanged)); + profile.addXp(skill, xpRemoved); + } + + return !isCancelled; + } + /** * Simulate a block break event. *