Fixing Xp share awarding full Xp to the original player

This commit is contained in:
bm01 2013-02-02 05:00:39 +01:00
parent 63e827aefb
commit 2006356ccd
2 changed files with 18 additions and 9 deletions

View File

@ -99,16 +99,17 @@ public class McMMOPlayer {
* @param xp The amount of Xp to add * @param xp The amount of Xp to add
*/ */
public void addXp(SkillType skillType, int xp) { public void addXp(SkillType skillType, int xp) {
if ((skillType.getMaxLevel() < profile.getSkillLevel(skillType) + 1) || (Misc.getPowerLevelCap() < getPowerLevel() + 1)) {
return;
}
if (player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() == GameMode.CREATIVE) {
return; return;
} }
if (party != null && !ShareHandler.isRunning()) { 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()); xp = (int) (xp / skillType.getXpModifier() * Config.getInstance().getExperienceGainsGlobalMultiplier());

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -31,14 +32,18 @@ public final class ShareHandler {
private 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; running = true;
Party party = mcMMOPlayer.getParty();
if (party.getXpShareMode() == XpShareMode.EQUAL) { if (party.getXpShareMode() == XpShareMode.EQUAL) {
Player player = mcMMOPlayer.getPlayer();
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
if (nearMembers.isEmpty()) { if (nearMembers.isEmpty()) {
@ -48,10 +53,13 @@ public final class ShareHandler {
double partySize = nearMembers.size() + 1; double partySize = nearMembers.size() + 1;
double splitXp = xp / partySize * Config.getInstance().getPartyShareBonus(); double splitXp = xp / partySize * Config.getInstance().getPartyShareBonus();
int roundedXp = (int) Math.ceil(splitXp);
for (Player member : nearMembers) { 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; running = false;