mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 06:06:45 +01:00
6d5ce1357e
Sorry, broke your party settings in config.yml. So now when there are more party members near, the party share bonus is increased. :)
74 lines
2.2 KiB
Java
74 lines
2.2 KiB
Java
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;
|
|
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;
|
|
}
|
|
}
|
|
};
|
|
|
|
private ShareHandler() {}
|
|
|
|
/**
|
|
* Distribute Xp amongst party members.
|
|
*
|
|
* @param xp Xp without party sharing
|
|
* @param mcMMOPlayer Player initiating the Xp gain
|
|
* @param skillType Skill being used
|
|
* @return True is the xp has been shared
|
|
*/
|
|
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());
|
|
|
|
if (nearMembers.isEmpty()) {
|
|
return false;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
mcMMOPlayer.beginUnsharedXpGain(skillType, roundedXp);
|
|
|
|
return true;
|
|
case NONE:
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|