mcMMO/src/main/java/com/gmail/nossr50/skills/runnables/CombatXpGiver.java

41 lines
1.2 KiB
Java
Raw Normal View History

package com.gmail.nossr50.skills.runnables;
2012-03-14 07:10:16 +01:00
import org.bukkit.entity.LivingEntity;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.skills.utilities.SkillType;
2012-03-14 07:10:16 +01:00
public class CombatXpGiver implements Runnable {
private McMMOPlayer mcMMOPlayer;
2013-01-26 23:01:55 +01:00
private double baseXp;
private SkillType skillType;
private LivingEntity target;
private int baseHealth;
2012-03-14 07:10:16 +01:00
public CombatXpGiver(McMMOPlayer mcMMOPlayer, SkillType skillType, double baseXp, LivingEntity target) {
this.mcMMOPlayer = mcMMOPlayer;
2012-03-14 07:10:16 +01:00
this.skillType = skillType;
this.baseXp = baseXp;
this.target = target;
baseHealth = target.getHealth();
}
@Override
public void run() {
int health = target.getHealth();
int damage = baseHealth - health;
2012-03-14 07:10:16 +01:00
//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));
2012-03-14 07:10:16 +01:00
}
}