mcMMO/src/main/java/com/gmail/nossr50/party/ShareHandler.java

74 lines
2.2 KiB
Java
Raw Normal View History

2013-01-30 15:17:50 +01:00
package com.gmail.nossr50.party;
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;
2013-01-30 15:17:50 +01:00
import com.gmail.nossr50.util.Users;
public final class ShareHandler {
public enum XpShareMode {
NONE,
EQUAL;
public static XpShareMode getFromString(String string) {
try {
return valueOf(string);
}
catch (IllegalArgumentException exception) {
return NONE;
}
catch (NullPointerException exception) {
return NONE;
}
2013-01-30 15:17:50 +01:00
}
};
2013-01-30 17:25:44 +01:00
private ShareHandler() {}
2013-01-30 15:17:50 +01:00
/**
* Distribute Xp amongst party members.
2013-01-30 15:17:50 +01:00
*
* @param xp Xp without party sharing
* @param mcMMOPlayer Player initiating the Xp gain
* @param skillType Skill being used
2013-02-02 05:06:47 +01:00
* @return True is the xp has been shared
2013-01-30 15:17:50 +01:00
*/
public static boolean handleXpShare(int xp, McMMOPlayer mcMMOPlayer, SkillType skillType) {
Party party = mcMMOPlayer.getParty();
switch (party.getXpShareMode()) {
case EQUAL:
Player player = mcMMOPlayer.getPlayer();
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
2013-01-30 15:17:50 +01:00
2013-02-02 04:42:24 +01:00
if (nearMembers.isEmpty()) {
2013-02-02 05:06:47 +01:00
return false;
}
2013-01-30 15:17:50 +01:00
double partySize = nearMembers.size() + 1;
double shareBonus = Config.getInstance().getPartyShareBonusBase() + partySize * Config.getInstance().getPartyShareBonusIncrease();
if (shareBonus > Config.getInstance().getPartyShareBonusCap()) {
shareBonus = Config.getInstance().getPartyShareBonusCap();
}
double splitXp = xp / partySize * shareBonus;
int roundedXp = (int) Math.ceil(splitXp);
for (Player member : nearMembers) {
Users.getPlayer(member).beginUnsharedXpGain(skillType, roundedXp);
2013-01-30 15:17:50 +01:00
}
mcMMOPlayer.beginUnsharedXpGain(skillType, roundedXp);
return true;
case NONE:
default:
return false;
}
}
}