2012-03-14 07:10:16 +01:00
|
|
|
package com.gmail.nossr50.runnables;
|
|
|
|
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-05-01 19:58:47 +02:00
|
|
|
import com.gmail.nossr50.util.Skills;
|
2012-03-14 07:10:16 +01:00
|
|
|
|
|
|
|
public class GainXp implements Runnable {
|
|
|
|
private Player player = null;
|
|
|
|
private PlayerProfile PP = null;
|
|
|
|
private double baseXp = 0;
|
|
|
|
private SkillType skillType = null;
|
|
|
|
private LivingEntity target = null;
|
|
|
|
private int baseHealth = 0;
|
|
|
|
|
|
|
|
public GainXp(Player player, PlayerProfile PP, SkillType skillType, double baseXp, LivingEntity target) {
|
|
|
|
this.player = player;
|
|
|
|
this.PP = PP;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-04 15:30:51 +02:00
|
|
|
Skills.xpProcessing(player, PP, skillType, (int) (damage * baseXp));
|
2012-03-14 07:10:16 +01:00
|
|
|
}
|
|
|
|
}
|