2013-01-30 17:53:51 +01:00
|
|
|
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;
|
2013-01-30 17:53:51 +01:00
|
|
|
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();
|
2012-06-06 01:19:39 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|