From b8a146f8bd22ec5dedeac37950efdf79e67bca11 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 19 Jan 2019 20:30:19 -0800 Subject: [PATCH] Fixed a sync problem where XP bars were 1-step behind --- .../gmail/nossr50/datatypes/player/McMMOPlayer.java | 12 +++++++++--- .../com/gmail/nossr50/listeners/SelfListener.java | 11 ++--------- .../java/com/gmail/nossr50/skills/SkillManager.java | 1 + src/main/java/com/gmail/nossr50/util/EventUtils.java | 1 + .../util/experience/ExperienceBarManager.java | 6 +++--- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 788d83945..75d8af808 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -50,6 +50,7 @@ import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -143,18 +144,18 @@ public class McMMOPlayer { experienceBarManager.hideExperienceBar(primarySkillType); }*/ - public void processPostXpEvent(XPGainReason xpGainReason, PrimarySkillType primarySkillType, mcMMO plugin, int xpGained) + public void processPostXpEvent(XPGainReason xpGainReason, PrimarySkillType primarySkillType, Plugin plugin) { if(xpGainReason != XPGainReason.SHARED_PVP && xpGainReason != XPGainReason.SHARED_PVE && xpGainReason != XPGainReason.VAMPIRISM) updateXPBar(primarySkillType, plugin); } - public void processUnlockNotifications(mcMMO plugin, PrimarySkillType primarySkillType, int level) + public void processUnlockNotifications(mcMMO plugin, PrimarySkillType primarySkillType) { RankUtils.executeSkillUnlockNotifications(plugin, this, primarySkillType, profile.getSkillLevel(primarySkillType)); } - public void updateXPBar(PrimarySkillType primarySkillType, mcMMO plugin) + public void updateXPBar(PrimarySkillType primarySkillType, Plugin plugin) { //Skill Unlock Notifications @@ -533,6 +534,7 @@ public class McMMOPlayer { */ private void checkXp(PrimarySkillType primarySkillType, XPGainReason xpGainReason) { if (getSkillXpLevelRaw(primarySkillType) < getXpToLevel(primarySkillType)) { + UserManager.getPlayer(player).processPostXpEvent(xpGainReason, primarySkillType, mcMMO.p); return; } @@ -550,6 +552,7 @@ public class McMMOPlayer { } if (!EventUtils.handleLevelChangeEvent(player, primarySkillType, levelsGained, xpRemoved, true, xpGainReason)) { + UserManager.getPlayer(player).processPostXpEvent(xpGainReason, primarySkillType, mcMMO.p); return; } @@ -562,6 +565,9 @@ public class McMMOPlayer { */ NotificationManager.sendPlayerLevelUpNotification(UserManager.getPlayer(player), primarySkillType, profile.getSkillLevel(primarySkillType)); + + //UPDATE XP BARS + UserManager.getPlayer(player).processPostXpEvent(xpGainReason, primarySkillType, mcMMO.p); } /* diff --git a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java index f9e6308b3..50de80bfd 100644 --- a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java @@ -30,7 +30,8 @@ public class SelfListener implements Listener { Player player = event.getPlayer(); PrimarySkillType skill = event.getSkill(); - UserManager.getPlayer(player).processUnlockNotifications(plugin, event.getSkill(), event.getSkillLevel()); + //Send player skill unlock notifications + UserManager.getPlayer(player).processUnlockNotifications(plugin, event.getSkill()); if(Config.getInstance().getScoreboardsEnabled()) ScoreboardManager.handleLevelUp(player, skill); @@ -64,8 +65,6 @@ public class SelfListener implements Listener { if (event.getXpGainReason() == XPGainReason.COMMAND) { - //Update the XP Bar - mcMMOPlayer.processPostXpEvent(event.getXpGainReason(), primarySkillType, plugin, (int) event.getRawXpGained()); return; } @@ -73,8 +72,6 @@ public class SelfListener implements Listener { if (threshold <= 0 || !ExperienceConfig.getInstance().getDiminishedReturnsEnabled()) { // Diminished returns is turned off - //Update the XP Bar - mcMMOPlayer.processPostXpEvent(event.getXpGainReason(), primarySkillType, plugin, (int) event.getRawXpGained()); return; } @@ -117,9 +114,5 @@ public class SelfListener implements Listener { } } - - //Update the XP Bar - if(!event.isCancelled()) - mcMMOPlayer.processPostXpEvent(event.getXpGainReason(), primarySkillType, plugin, (int) event.getRawXpGained()); } } diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManager.java b/src/main/java/com/gmail/nossr50/skills/SkillManager.java index 0201c9ad8..e1dcb2616 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillManager.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillManager.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.skills; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.XPGainReason; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.skills.PerksUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 512cecd55..67a0cda41 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -41,6 +41,7 @@ import org.bukkit.event.Event; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import java.util.HashMap; diff --git a/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java b/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java index b8cc12cb8..e21843c8a 100644 --- a/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java +++ b/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java @@ -3,8 +3,8 @@ package com.gmail.nossr50.util.experience; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.runnables.skills.ExperienceBarHideTask; +import org.bukkit.plugin.Plugin; import java.util.HashMap; @@ -27,7 +27,7 @@ public class ExperienceBarManager { this.mcMMOPlayer = mcMMOPlayer; } - public void updateExperienceBar(PrimarySkillType primarySkillType, mcMMO plugin) + public void updateExperienceBar(PrimarySkillType primarySkillType, Plugin plugin) { if(!ExperienceConfig.getInstance().isExperienceBarsEnabled() || !ExperienceConfig.getInstance().isExperienceBarEnabled(primarySkillType)) return; @@ -55,7 +55,7 @@ public class ExperienceBarManager { } } - private void scheduleHideTask(PrimarySkillType primarySkillType, mcMMO plugin) { + private void scheduleHideTask(PrimarySkillType primarySkillType, Plugin plugin) { ExperienceBarHideTask experienceBarHideTask = new ExperienceBarHideTask(this, mcMMOPlayer, primarySkillType); experienceBarHideTask.runTaskLater(plugin, 20*2); experienceBarHideTaskHashMap.put(primarySkillType, experienceBarHideTask);