use of com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesPreExperienceDropEvent in project Parties by AlessioDP.
the class BukkitExpManager method distributeExp.
/**
* Distribute the experience to the player
* @return Returns true if the distribution has been done
*/
public boolean distributeExp(ExpDrop drop) {
boolean ret = false;
// Flags used to messages
double totalParty = 0;
double totalNormal = 0;
double totalLevelPoints = 0;
double totalMmoCore = 0;
double totalSkillapi = 0;
PartyImpl party = plugin.getPartyManager().getParty(drop.getKiller().getPartyId());
if (party != null) {
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_EXP_RECEIVED, drop.getNormal(), drop.getSkillApi()), true);
Player player = Bukkit.getPlayer(drop.getKiller().getPlayerUUID());
User user = plugin.getPlayer(drop.getKiller().getPlayerUUID());
if (player != null && user != null) {
// Calling API event
BukkitPartiesPreExperienceDropEvent partiesPreExperienceDropEvent = ((BukkitEventManager) plugin.getEventManager()).preparePreExperienceDropEvent(party, drop.getKiller(), drop.getEntityKilled(), drop.getNormal(), drop.getSkillApi());
plugin.getEventManager().callEvent(partiesPreExperienceDropEvent);
if (!partiesPreExperienceDropEvent.isCancelled()) {
drop.setNormal(partiesPreExperienceDropEvent.getNormalExperience());
drop.setSkillApi(partiesPreExperienceDropEvent.getSkillApiExperience());
if (drop.getNormal() > 0) {
switch(convertNormal) {
case PARTY:
totalParty += drop.getNormal();
break;
case NORMAL:
totalNormal += drop.getNormal();
break;
case LEVELPOINTS:
totalLevelPoints += drop.getNormal();
break;
case MMOCORE:
totalMmoCore += drop.getNormal();
break;
case SKILLAPI:
totalSkillapi += drop.getNormal();
break;
default:
// Convert option not set
return false;
}
}
if (drop.getSkillApi() > 0) {
switch(convertSkillapi) {
case PARTY:
totalParty += drop.getSkillApi();
break;
case NORMAL:
totalNormal += drop.getSkillApi();
break;
case LEVELPOINTS:
totalLevelPoints += drop.getSkillApi();
break;
case MMOCORE:
totalMmoCore += drop.getSkillApi();
break;
case SKILLAPI:
totalSkillapi += drop.getSkillApi();
break;
default:
// Convert option not set
return false;
}
}
// Send experience
if (totalParty > 0) {
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_EXP_SEND_PARTY, CommonUtils.formatDouble(totalParty), party.getId().toString()), true);
party.giveExperience(totalParty, drop.getKiller());
user.sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.ADDCMD_EXP_PARTY_GAINED.replace("%exp%", CommonUtils.formatDouble(totalParty)), drop.getKiller(), party), true);
ret = true;
}
if (totalNormal > 0)
ret = shareExperience(totalNormal, drop.getKiller(), party, drop.getEntityKilled(), ExpConvert.NORMAL) || ret;
if (totalLevelPoints > 0)
ret = shareExperience(totalLevelPoints, drop.getKiller(), party, drop.getEntityKilled(), ExpConvert.LEVELPOINTS) || ret;
if (totalMmoCore > 0)
ret = shareExperience(totalMmoCore, drop.getKiller(), party, drop.getEntityKilled(), ExpConvert.MMOCORE) || ret;
if (totalSkillapi > 0)
ret = shareExperience(totalSkillapi, drop.getKiller(), party, drop.getEntityKilled(), ExpConvert.SKILLAPI) || ret;
}
}
}
return ret;
}
Aggregations