BleedTimerTask.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //package com.gmail.nossr50.runnables.skills;
  2. //
  3. //import com.gmail.nossr50.config.AdvancedConfig;
  4. //import com.gmail.nossr50.datatypes.interactions.NotificationType;
  5. //import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
  6. //import com.gmail.nossr50.mcMMO;
  7. //import com.gmail.nossr50.util.MobHealthbarUtils;
  8. //import com.gmail.nossr50.util.player.NotificationManager;
  9. //import com.gmail.nossr50.util.skills.CombatUtils;
  10. //import com.gmail.nossr50.util.skills.ParticleEffectUtils;
  11. //import com.gmail.nossr50.util.sounds.SoundManager;
  12. //import com.gmail.nossr50.util.sounds.SoundType;
  13. //import org.bukkit.Bukkit;
  14. //import org.bukkit.entity.LivingEntity;
  15. //import org.bukkit.entity.Player;
  16. //import org.bukkit.event.entity.EntityDamageEvent;
  17. //import org.bukkit.inventory.ItemStack;
  18. //import org.bukkit.scheduler.BukkitRunnable;
  19. //import org.jetbrains.annotations.NotNull;
  20. //
  21. //import java.util.HashMap;
  22. //import java.util.Iterator;
  23. //import java.util.Map;
  24. //import java.util.Map.Entry;
  25. //
  26. //public class BleedTimerTask extends BukkitRunnable {
  27. // private static final @NotNull Map<LivingEntity, BleedContainer> bleedList = new HashMap<>();
  28. // private static boolean isIterating = false;
  29. //
  30. // @Override
  31. // public void run() {
  32. // isIterating = true;
  33. // Iterator<Entry<LivingEntity, BleedContainer>> bleedIterator = bleedList.entrySet().iterator();
  34. //
  35. // while (bleedIterator.hasNext()) {
  36. // Entry<LivingEntity, BleedContainer> containerEntry = bleedIterator.next();
  37. // LivingEntity target = containerEntry.getKey();
  38. // int toolTier = containerEntry.getValue().toolTier;
  39. //
  40. //// String debugMessage = "";
  41. //// debugMessage += ChatColor.GOLD + "Target ["+target.getName()+"]: " + ChatColor.RESET;
  42. //
  43. //// debugMessage+="RemainingTicks=["+containerEntry.getValue().bleedTicks+"], ";
  44. //
  45. // if (containerEntry.getValue().bleedTicks <= 0 || !target.isValid()) {
  46. // if(target instanceof Player)
  47. // {
  48. // NotificationManager.sendPlayerInformation((Player) target, NotificationType.SUBSKILL_MESSAGE, "Swords.Combat.Bleeding.Stopped");
  49. // }
  50. //
  51. // bleedIterator.remove();
  52. // continue;
  53. // }
  54. //
  55. // int armorCount = 0;
  56. //
  57. // double damage;
  58. //
  59. // if (target instanceof Player) {
  60. // damage = AdvancedConfig.getInstance().getRuptureDamagePlayer();
  61. //
  62. // //Above Bleed Rank 3 deals 50% more damage
  63. // if (containerEntry.getValue().toolTier >= 4 && containerEntry.getValue().bleedRank >= 3)
  64. // damage = damage * 1.5;
  65. //
  66. // Player player = (Player) target;
  67. //
  68. // if (!player.isOnline()) {
  69. // continue;
  70. // }
  71. //
  72. // //Count Armor
  73. // for (ItemStack armorPiece : ((Player) target).getInventory().getArmorContents()) {
  74. // //We only want to count slots that contain armor.
  75. // if (armorPiece != null) {
  76. // armorCount++;
  77. // }
  78. // }
  79. //
  80. // } else {
  81. // damage = AdvancedConfig.getInstance().getRuptureDamageMobs();
  82. //
  83. //// debugMessage+="BaseDMG=["+damage+"], ";
  84. //
  85. // //Above Bleed Rank 3 deals 50% more damage
  86. // if (containerEntry.getValue().bleedRank >= 3)
  87. // {
  88. // damage = damage * 1.5;
  89. // }
  90. //
  91. //// debugMessage+="Rank4Bonus=["+String.valueOf(containerEntry.getValue().bleedRank >= 3)+"], ";
  92. //
  93. //
  94. // MobHealthbarUtils.handleMobHealthbars(target, damage, mcMMO.p); //Update health bars
  95. // }
  96. //
  97. //// debugMessage+="FullArmor=["+String.valueOf(armorCount > 3)+"], ";
  98. //
  99. // if(armorCount > 3)
  100. // {
  101. // damage = damage * .75;
  102. // }
  103. //
  104. //// debugMessage+="AfterRankAndArmorChecks["+damage+"], ";
  105. //
  106. // //Weapons below Diamond get damage cut in half
  107. // if(toolTier < 4)
  108. // damage = damage / 2;
  109. //
  110. //// debugMessage+="AfterDiamondCheck=["+String.valueOf(damage)+"], ";
  111. //
  112. // //Wood weapons get damage cut in half again
  113. // if(toolTier < 2)
  114. // damage = damage / 2;
  115. //
  116. //// debugMessage+="AfterWoodenCheck=["+String.valueOf(damage)+"], ";
  117. //
  118. // double victimHealth = target.getHealth();
  119. //
  120. //// debugMessage+="TargetHealthBeforeDMG=["+String.valueOf(target.getHealth())+"], ";
  121. //
  122. // //Fire a fake event
  123. // FakeEntityDamageByEntityEvent fakeEntityDamageByEntityEvent = (FakeEntityDamageByEntityEvent) CombatUtils.sendEntityDamageEvent(containerEntry.getValue().damageSource, target, EntityDamageEvent.DamageCause.CUSTOM, damage);
  124. // Bukkit.getPluginManager().callEvent(fakeEntityDamageByEntityEvent);
  125. //
  126. // CombatUtils.dealNoInvulnerabilityTickDamageRupture(target, damage, containerEntry.getValue().damageSource, toolTier);
  127. //
  128. // double victimHealthAftermath = target.getHealth();
  129. //
  130. //// debugMessage+="TargetHealthAfterDMG=["+String.valueOf(target.getHealth())+"], ";
  131. //
  132. // if(victimHealthAftermath <= 0 || victimHealth != victimHealthAftermath)
  133. // {
  134. // //Play Bleed Sound
  135. // SoundManager.worldSendSound(target.getWorld(), target.getLocation(), SoundType.BLEED);
  136. //
  137. // ParticleEffectUtils.playBleedEffect(target);
  138. // }
  139. //
  140. // //Lower Bleed Ticks
  141. // BleedContainer loweredBleedContainer = copyContainer(containerEntry.getValue());
  142. // loweredBleedContainer.bleedTicks -= 1;
  143. //
  144. //// debugMessage+="RemainingTicks=["+loweredBleedContainer.bleedTicks+"]";
  145. // containerEntry.setValue(loweredBleedContainer);
  146. //
  147. //// Bukkit.broadcastMessage(debugMessage);
  148. // }
  149. // isIterating = false;
  150. // }
  151. //
  152. // public static @NotNull BleedContainer copyContainer(@NotNull BleedContainer container)
  153. // {
  154. // LivingEntity target = container.target;
  155. // LivingEntity source = container.damageSource;
  156. // int bleedTicks = container.bleedTicks;
  157. // int bleedRank = container.bleedRank;
  158. // int toolTier = container.toolTier;
  159. //
  160. // return new BleedContainer(target, bleedTicks, bleedRank, toolTier, source);
  161. // }
  162. //
  163. // /**
  164. // * Instantly Bleed out a LivingEntity
  165. // *
  166. // * @param entity LivingEntity to bleed out
  167. // */
  168. // public static void bleedOut(@NotNull LivingEntity entity) {
  169. // /*
  170. // * Don't remove anything from the list outside of run()
  171. // */
  172. //
  173. // if (bleedList.containsKey(entity)) {
  174. // CombatUtils.dealNoInvulnerabilityTickDamage(entity, bleedList.get(entity).bleedTicks * 2, bleedList.get(entity).damageSource);
  175. // }
  176. // }
  177. //
  178. // /**
  179. // * Add a LivingEntity to the bleedList if it is not in it.
  180. // *
  181. // * @param entity LivingEntity to add
  182. // * @param attacker source of the bleed/rupture
  183. // * @param ticks Number of bleeding ticks
  184. // */
  185. // public static void add(@NotNull LivingEntity entity, @NotNull LivingEntity attacker, int ticks, int bleedRank, int toolTier) {
  186. // if (!Bukkit.isPrimaryThread()) {
  187. // throw new IllegalStateException("Cannot add bleed task async!");
  188. // }
  189. //
  190. // if(isIterating) {
  191. // //Used to throw an error here, but in reality all we are really doing is preventing concurrency issues from other plugins being naughty and its not really needed
  192. // //I'm not really a fan of silent errors, but I'm sick of seeing people using crazy enchantments come in and report this "bug"
  193. // return;
  194. // }
  195. //
  196. //// if (isIterating) throw new IllegalStateException("Cannot add task while iterating timers!");
  197. //
  198. // if(toolTier < 4)
  199. // ticks = Math.max(1, (ticks / 3));
  200. //
  201. // ticks+=1;
  202. //
  203. // BleedContainer newBleedContainer = new BleedContainer(entity, ticks, bleedRank, toolTier, attacker);
  204. // bleedList.put(entity, newBleedContainer);
  205. // }
  206. //
  207. // public static boolean isBleedOperationAllowed() {
  208. // return !isIterating && Bukkit.isPrimaryThread();
  209. // }
  210. //
  211. // public static boolean isBleeding(@NotNull LivingEntity entity) {
  212. // return bleedList.containsKey(entity);
  213. // }
  214. //}