From 2006356ccd84ae9a8e90168d0eacc0efa689c15b Mon Sep 17 00:00:00 2001 From: bm01 Date: Sat, 2 Feb 2013 05:00:39 +0100 Subject: [PATCH] Fixing Xp share awarding full Xp to the original player --- .../com/gmail/nossr50/datatypes/McMMOPlayer.java | 11 ++++++----- .../com/gmail/nossr50/party/ShareHandler.java | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java index 21999e676..825a2b9b0 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java @@ -99,16 +99,17 @@ public class McMMOPlayer { * @param xp The amount of Xp to add */ public void addXp(SkillType skillType, int xp) { - if ((skillType.getMaxLevel() < profile.getSkillLevel(skillType) + 1) || (Misc.getPowerLevelCap() < getPowerLevel() + 1)) { - return; - } - if (player.getGameMode() == GameMode.CREATIVE) { return; } if (party != null && !ShareHandler.isRunning()) { - ShareHandler.handleEqualXpShare(xp, player, party, skillType); + ShareHandler.handleEqualXpShare(xp, this, skillType); + return; + } + + if ((skillType.getMaxLevel() < profile.getSkillLevel(skillType) + 1) || (Misc.getPowerLevelCap() < getPowerLevel() + 1)) { + return; } xp = (int) (xp / skillType.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier()); diff --git a/src/main/java/com/gmail/nossr50/party/ShareHandler.java b/src/main/java/com/gmail/nossr50/party/ShareHandler.java index 9b10fa4fa..55d60a631 100644 --- a/src/main/java/com/gmail/nossr50/party/ShareHandler.java +++ b/src/main/java/com/gmail/nossr50/party/ShareHandler.java @@ -5,6 +5,7 @@ import java.util.List; import org.bukkit.entity.Player; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Users; @@ -31,14 +32,18 @@ public final class ShareHandler { private ShareHandler() {} /** - * Distribute XP amongst party members. + * Distribute Xp amongst party members. * - * @param xp XP without party sharing + * @param xp Xp without party sharing + * @param mcMMOPlayer Player initiating the Xp gain + * @param skillType Skill being used */ - public static void handleEqualXpShare(int xp, Player player, Party party, SkillType skillType) { + public static void handleEqualXpShare(int xp, McMMOPlayer mcMMOPlayer, SkillType skillType) { running = true; + Party party = mcMMOPlayer.getParty(); if (party.getXpShareMode() == XpShareMode.EQUAL) { + Player player = mcMMOPlayer.getPlayer(); List nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); if (nearMembers.isEmpty()) { @@ -48,10 +53,13 @@ public final class ShareHandler { double partySize = nearMembers.size() + 1; double splitXp = xp / partySize * Config.getInstance().getPartyShareBonus(); + int roundedXp = (int) Math.ceil(splitXp); for (Player member : nearMembers) { - Users.getPlayer(member).addXp(skillType, (int) Math.ceil(splitXp)); + Users.getPlayer(member).addXp(skillType, roundedXp); } + + mcMMOPlayer.addXp(skillType, roundedXp); } running = false;