Skip to content

Commit

Permalink
Fixing an issue with mmoedit triggering notifications for skills alre…
Browse files Browse the repository at this point in the history
…ady unlocked
  • Loading branch information
nossr50 committed Mar 31, 2019
1 parent 57b31b6 commit b125600
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog.txt
Expand Up @@ -10,6 +10,8 @@ Key:
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
Expand Down
Expand Up @@ -36,7 +36,7 @@ protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillT
return;
}

EventUtils.handleLevelChangeEvent(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND);
EventUtils.handleLevelChangeEventEdit(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel);
}

@Override
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/gmail/nossr50/util/EventUtils.java
Expand Up @@ -198,6 +198,22 @@ public static boolean handleLevelChangeEvent(Player player, PrimarySkillType ski
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.
*
Expand Down

0 comments on commit b125600

Please sign in to comment.