mcMMO/src/main/java/com/gmail/nossr50/skills/runnables/CombatXpGiver.java
bm01 a1ab6f286b Made xp sharing less ugly by reworking McMMOPlayer xp methods
Notable consequence: checkXP and addLevel in ExperienceAPI are no longer
needed and became deprecated
2013-02-03 12:45:19 +01:00

41 lines
1.2 KiB
Java

package com.gmail.nossr50.skills.runnables;
import org.bukkit.entity.LivingEntity;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillType;
public class CombatXpGiver implements Runnable {
private McMMOPlayer mcMMOPlayer;
private double baseXp;
private SkillType skillType;
private LivingEntity target;
private int baseHealth;
public CombatXpGiver(McMMOPlayer mcMMOPlayer, SkillType skillType, double baseXp, LivingEntity target) {
this.mcMMOPlayer = mcMMOPlayer;
this.skillType = skillType;
this.baseXp = baseXp;
this.target = target;
baseHealth = target.getHealth();
}
@Override
public void run() {
int health = target.getHealth();
int damage = baseHealth - health;
//May avoid negative xp, we don't know what other plugins do with the entity health
if (damage <= 0) {
return;
}
//Don't reward the player for overkills
if (health < 0) {
damage += health;
}
mcMMOPlayer.beginXpGain(skillType, (int) (damage * baseXp));
}
}