mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 06:06:45 +01:00
45 lines
1.5 KiB
Java
45 lines
1.5 KiB
Java
package com.gmail.nossr50.runnables.skills;
|
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
|
import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
import org.bukkit.entity.LivingEntity;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
public class AwardCombatXpTask extends BukkitRunnable {
|
|
private final McMMOPlayer mcMMOPlayer;
|
|
private final double baseXp;
|
|
private final PrimarySkillType primarySkillType;
|
|
private final LivingEntity target;
|
|
private final XPGainReason xpGainReason;
|
|
private final double baseHealth;
|
|
|
|
public AwardCombatXpTask(McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, double baseXp, LivingEntity target, XPGainReason xpGainReason) {
|
|
this.mcMMOPlayer = mcMMOPlayer;
|
|
this.primarySkillType = primarySkillType;
|
|
this.baseXp = baseXp;
|
|
this.target = target;
|
|
this.xpGainReason = xpGainReason;
|
|
baseHealth = target.getHealth();
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
double health = target.getHealth();
|
|
double 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(primarySkillType, (int) (damage * baseXp), xpGainReason, XPGainSource.SELF);
|
|
}
|
|
}
|