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

45 lines
1.3 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 org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
2012-03-14 07:10:16 +01:00
public class GainXp implements Runnable {
2013-01-26 23:01:55 +01:00
private Player player;
private PlayerProfile profile;
private double baseXp;
private SkillType skillType;
private LivingEntity target;
private int baseHealth;
2012-03-14 07:10:16 +01:00
2012-07-03 16:04:04 +02:00
public GainXp(Player player, PlayerProfile profile, SkillType skillType, double baseXp, LivingEntity target) {
2012-03-14 07:10:16 +01:00
this.player = player;
2012-07-03 16:04:04 +02:00
this.profile = profile;
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;
}
2013-01-26 23:01:55 +01:00
SkillTools.xpProcessing(player, profile, skillType, (int) (damage * baseXp));
2012-03-14 07:10:16 +01:00
}
}