GainXp.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.gmail.nossr50.runnables;
  2. import org.bukkit.entity.LivingEntity;
  3. import org.bukkit.entity.Player;
  4. import com.gmail.nossr50.datatypes.PlayerProfile;
  5. import com.gmail.nossr50.datatypes.SkillType;
  6. import com.gmail.nossr50.util.Skills;
  7. public class GainXp implements Runnable {
  8. private Player player = null;
  9. private PlayerProfile profile = null;
  10. private double baseXp = 0;
  11. private SkillType skillType = null;
  12. private LivingEntity target = null;
  13. private int baseHealth = 0;
  14. public GainXp(Player player, PlayerProfile profile, SkillType skillType, double baseXp, LivingEntity target) {
  15. this.player = player;
  16. this.profile = profile;
  17. this.skillType = skillType;
  18. this.baseXp = baseXp;
  19. this.target = target;
  20. baseHealth = target.getHealth();
  21. }
  22. @Override
  23. public void run() {
  24. int health = target.getHealth();
  25. int damage = baseHealth - health;
  26. //May avoid negative xp, we don't know what other plugins do with the entity health
  27. if (damage <= 0) {
  28. return;
  29. }
  30. //Don't reward the player for overkills
  31. if (health < 0) {
  32. damage += health;
  33. }
  34. Skills.xpProcessing(player, profile, skillType, (int) (damage * baseXp));
  35. }
  36. }