mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 14:16:45 +01:00
a1ab6f286b
Notable consequence: checkXP and addLevel in ExperienceAPI are no longer needed and became deprecated
41 lines
1.2 KiB
Java
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));
|
|
}
|
|
}
|