mcAcrobatics.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.gmail.nossr50;
  2. import org.bukkit.ChatColor;
  3. import org.bukkit.Location;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.event.entity.EntityDamageEvent;
  6. import com.gmail.nossr50.datatypes.PlayerProfile;
  7. public class mcAcrobatics {
  8. private static volatile mcAcrobatics instance;
  9. public static mcAcrobatics getInstance() {
  10. if (instance == null) {
  11. instance = new mcAcrobatics();
  12. }
  13. return instance;
  14. }
  15. public void acrobaticsCheck(Player player, EntityDamageEvent event, Location loc, int xx, int y, int z){
  16. if(player != null && mcPermissions.getInstance().acrobatics(player)){
  17. PlayerProfile PP = mcUsers.getProfile(player);
  18. int acrovar = PP.getAcrobaticsInt();
  19. if(player.isSneaking())
  20. acrovar = acrovar * 2;
  21. if(Math.random() * 1000 <= acrovar && !event.isCancelled()){
  22. int threshold = 7;
  23. if(player.isSneaking())
  24. threshold = 14;
  25. int newDamage = event.getDamage() - threshold;
  26. if(newDamage < 0)
  27. newDamage = 0;
  28. /*
  29. * Check for death
  30. */
  31. if(player.getHealth() - newDamage >= 1){
  32. if(!event.isCancelled())
  33. PP.addAcrobaticsXP((event.getDamage() * 8) * mcLoadProperties.xpGainMultiplier);
  34. mcSkills.XpCheck(player);
  35. event.setDamage(newDamage);
  36. if(event.getDamage() <= 0)
  37. event.setCancelled(true);
  38. if(player.isSneaking()){
  39. player.sendMessage(ChatColor.GREEN+"**GRACEFUL ROLL**");
  40. } else {
  41. player.sendMessage("**ROLL**");
  42. }
  43. }
  44. } else if (!event.isCancelled()){
  45. if(player.getHealth() - event.getDamage() >= 1){
  46. PP.addAcrobaticsXP((event.getDamage() * 12) * mcLoadProperties.xpGainMultiplier);
  47. mcSkills.XpCheck(player);
  48. }
  49. }
  50. }
  51. }
  52. }