Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.38 KB | None | 0 0
  1. package ru.meloncode.cristalix.prison.mobs;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Random;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Effect;
  9. import org.bukkit.Material;
  10. import org.bukkit.Sound;
  11. import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
  12. import org.bukkit.entity.EntityType;
  13. import org.bukkit.entity.LivingEntity;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.event.Event;
  16. import org.bukkit.event.entity.EntityDamageEvent;
  17. import org.bukkit.event.entity.EntityRegainHealthEvent;
  18. import org.bukkit.inventory.ItemStack;
  19. import org.bukkit.potion.PotionEffect;
  20. import org.bukkit.potion.PotionEffectType;
  21. import org.bukkit.scheduler.BukkitRunnable;
  22. import org.bukkit.util.Vector;
  23.  
  24. import net.md_5.bungee.api.ChatMessageType;
  25. import net.md_5.bungee.api.chat.ComponentBuilder;
  26. import net.minecraft.server.v1_12_R1.DamageSource;
  27. import net.minecraft.server.v1_12_R1.Entity;
  28. import net.minecraft.server.v1_12_R1.EntityCreature;
  29. import net.minecraft.server.v1_12_R1.EntityHuman;
  30. import net.minecraft.server.v1_12_R1.EntityInsentient;
  31. import net.minecraft.server.v1_12_R1.EntityPlayer;
  32. import net.minecraft.server.v1_12_R1.EntityVindicator;
  33. import net.minecraft.server.v1_12_R1.GenericAttributes;
  34. import net.minecraft.server.v1_12_R1.PathfinderGoal;
  35. import net.minecraft.server.v1_12_R1.PathfinderGoalHurtByTarget;
  36. import net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer;
  37. import net.minecraft.server.v1_12_R1.PathfinderGoalMeleeAttack;
  38. import net.minecraft.server.v1_12_R1.PathfinderGoalMoveTowardsRestriction;
  39. import net.minecraft.server.v1_12_R1.PathfinderGoalNearestAttackableTarget;
  40. import net.minecraft.server.v1_12_R1.PathfinderGoalRandomStroll;
  41. import net.minecraft.server.v1_12_R1.World;
  42. import ru.meloncode.cristalix.prison.Main;
  43. import ru.meloncode.cristalix.prison.PrisonPlayer;
  44. import ru.meloncode.cristalix.prison.Utils;
  45.  
  46. public class EntityFilimPidor extends EntityVindicator
  47. {
  48. Spawner spawner;
  49. int hp_delay;
  50. int jump_delay = 80;
  51. int storm = 400;
  52. HashMap<String, Integer> attackers = new HashMap<>();
  53. int totalDamage = 0;
  54. Random rand;
  55.  
  56. public EntityFilimPidor(final Spawner spawner) {
  57. super((World)((CraftWorld)spawner.getSpawnLocation().getWorld()).getHandle());
  58. this.hp_delay = 20;
  59. this.rand = new Random();
  60. this.getAttributeInstance(GenericAttributes.maxHealth).setValue((double)Main.BERSERK_HEALTH);
  61. this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128.0);
  62. this.getAttributeInstance(GenericAttributes.c).setValue(-1.0);
  63. this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0);
  64. this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(1);
  65. this.setHealth((float)Main.BERSERK_HEALTH);
  66. this.goalSelector.a(1, (PathfinderGoal)new PathfinderGoalLookAtPlayer((EntityInsentient)this, (Class<EntityHuman>)EntityHuman.class, 128.0f));
  67. this.goalSelector.a(5, (PathfinderGoal)new PathfinderGoalMoveTowardsRestriction((EntityCreature)this, 1.0));
  68. this.goalSelector.a(7, (PathfinderGoal)new PathfinderGoalRandomStroll((EntityCreature)this, 1.0));
  69. this.targetSelector.a(4, (PathfinderGoal)new PathfinderGoalNearestAttackableTarget<EntityHuman>((EntityCreature)this, (Class<EntityHuman>)EntityHuman.class, true));
  70. this.targetSelector.a(5, (PathfinderGoal)new PathfinderGoalHurtByTarget((EntityCreature)this, true, new Class[0]));
  71. this.goalSelector.a(9, (PathfinderGoal)new PathfinderGoalLookAtPlayer((EntityInsentient)this, (Class<EntityHuman>)EntityHuman.class, 64.0f));
  72. this.goalSelector.a(2, (PathfinderGoal)new PathfinderGoalMeleeAttack((EntityCreature)this, (double)Main.BERSERK_DAMAGE, true));
  73. this.spawner = spawner;
  74. this.setCustomName(Main.BERSERK_NAME.replace("#", String.valueOf((int)this.getHealth())).replace("<3", "\u2764"));
  75. this.setCustomNameVisible(true);
  76. this.canPickUpLoot = false;
  77. this.fireProof = true;
  78. if (this.spawner != null) {
  79. this.spawner.register((Entity)this);
  80. }
  81. this.persistent = true;
  82. this.expToDrop = 0;
  83. LivingEntity entity = (LivingEntity) this.getBukkitEntity();
  84. entity.getEquipment().setItemInHand(new ItemStack(Material.IRON_AXE));
  85. }
  86.  
  87. public void superJump() {
  88. this.getBukkitEntity().setVelocity(new Vector(0, 0, 0).multiply(0));
  89. new BukkitRunnable() {
  90. public void run() {
  91. EntityFilimPidor.this.getBukkitEntity().getWorld().playSound(EntityFilimPidor.this.getBukkitEntity().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0f, 1.0f);
  92. for (final org.bukkit.entity.Entity entity : EntityFilimPidor.this.getBukkitEntity().getNearbyEntities(7.0, 6.0, 7.0)) {
  93. if (entity.getType() == EntityType.PLAYER) {
  94. entity.setVelocity(entity.getVelocity().add(entity.getLocation().getDirection()).multiply(-3));
  95. final EntityDamageEvent event = new EntityDamageEvent(entity, EntityDamageEvent.DamageCause.MAGIC, 5);
  96. Bukkit.getPluginManager().callEvent((Event)event);
  97. if (event.isCancelled()) {
  98. continue;
  99. }
  100. ((LivingEntity)entity).damage(5.0);
  101. }
  102. }
  103. }
  104. }.runTaskLater(Main.getInstance(), 25L);
  105. }
  106.  
  107. public boolean damageEntity(final DamageSource source, float a) {
  108. if ((this.passengers.size() != 0 && source.getEntity() == this.passengers.get(0)) || source == DamageSource.STUCK || source == DamageSource.FALL) {
  109. return false;
  110. }
  111. this.setCustomName(Main.BERSERK_NAME.replace("#", String.valueOf((int)this.getHealth())).replace("<3", "\u2764"));
  112. if (this.passengers.size() != 0) {
  113. return source != DamageSource.projectile((net.minecraft.server.v1_12_R1.Entity)this, this.passengers.get(0)) && this.passengers.get(0).damageEntity(source, a);
  114. }
  115. final net.minecraft.server.v1_12_R1.Entity entity = source.i();
  116. if (entity != null && entity.getBukkitEntity().getType() == EntityType.PLAYER) {
  117. Player p = (Player) Bukkit.getPlayer(entity.getBukkitEntity().getName());
  118. final PrisonPlayer pp = PrisonPlayer.getPrisonPlayer(p);
  119. if (!this.attackers.containsKey(pp.getName())) {
  120. this.attackers.put(pp.getName(), (int)a);
  121. }
  122. else {
  123. this.attackers.put(pp.getName(), (int)(this.attackers.get(pp.getName()) + a));
  124. }
  125. this.totalDamage += (int)a;
  126. }
  127. float newhp = getHealth() - a;
  128. double dmg = this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
  129. if(newhp <= 300 && dmg == Main.BERSERK_DAMAGE) this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(Main.BERSERK_DAMAGE * 5);
  130. return super.damageEntity(source, a);
  131. }
  132.  
  133.  
  134. public void n() {
  135. if(this.spawner.getCurrent() == null) return;
  136. if (this.spawner.getCurrent() != null && this.spawner.getSpawnLocation().distance(this.spawner.getCurrent().getBukkitEntity().getLocation()) > 20.0) {
  137. this.spawner.getCurrent().setLocation(this.spawner.getSpawnLocation().getX(), this.spawner.getSpawnLocation().getY(), this.spawner.getSpawnLocation().getZ(), 0.0f, 0.0f);
  138. }
  139. if (this.hp_delay-- <= 0) {
  140. this.setCustomName(Main.BERSERK_NAME.replace("#", String.valueOf((int)this.getHealth())).replace("<3", "\u2764"));
  141. if (this.getHealth() < Main.BERSERK_HEALTH) {
  142. this.heal(1.0f, EntityRegainHealthEvent.RegainReason.REGEN);
  143. }
  144. this.hp_delay = 5;
  145. }
  146. if (this.jump_delay-- <= 0) {
  147. this.jump_delay = 25;
  148. superJump();
  149. }
  150. if (this.getGoalTarget() != null && this.passengers.size() == 0) {
  151. final boolean isSameWorld = this.getBukkitEntity().getLocation().getWorld() == this.getGoalTarget().getBukkitEntity().getLocation().getWorld();
  152. final double distance = isSameWorld ? this.getBukkitEntity().getLocation().distance(this.getGoalTarget().getBukkitEntity().getLocation()) : 32.0;
  153. if (distance > 16.0) {
  154. this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.0);
  155. }
  156. else {
  157. this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(Main.BERSERK_SPEED);
  158. }
  159. }
  160. super.n();
  161. }
  162.  
  163. @Override
  164. public boolean r(final Entity entity) {
  165. return super.r(entity);
  166. }
  167.  
  168.  
  169. public void summonEffect(PotionEffectType type, int duration, int level) {
  170. this.getBukkitEntity().getNearbyEntities(15d, 10d, 15d).stream().filter(e -> e.getType() == EntityType.PLAYER).forEach(e -> ((Player) e).addPotionEffect(new PotionEffect(type, duration, level)));
  171. }
  172.  
  173.  
  174.  
  175. public void die() {
  176. if (this.spawner != null) {
  177. this.spawner.iDead();
  178. }
  179. if (this.killer instanceof EntityPlayer) {
  180. final Player p = (Player)this.killer.getBukkitEntity();
  181. if (this.spawner != null) {
  182. PrisonPlayer.getPrisonPlayer(p).addMobKill(this.spawner.getType());
  183. }
  184. }
  185. if (this.killer != null) {
  186. final HashMap<String, Double> percents = Utils.calculatePercents(this.attackers, this.totalDamage);
  187. for (final String key : percents.keySet()) {
  188. final int money = (int)(percents.get(key) * Main.BERSERK_MONEY / 100.0);
  189. Main.economy.depositPlayer(key, (double)money * PrisonPlayer.getPrisonPlayer(key).getResourcesMultiplier());
  190. Player p = Bukkit.getPlayer(key);
  191. if (p != null) {
  192. PrisonPlayer.getPrisonPlayer(p).addShards(Main.BERSERK_SHARD * PrisonPlayer.getPrisonPlayer(key).getCrystalsMultiplier());
  193. p.sendMessage(Utils.f("&a&l\u041d\u0430\u0433\u0440\u0430\u0434\u0430: &b" + Main.BERSERK_SHARD * PrisonPlayer.getPrisonPlayer(key).getCrystalsMultiplier()) + " \u0448\u0430\u0440\u0434\u043e\u0432");
  194. p.sendMessage(ChatColor.GREEN + "\u041d\u0430 \u0432\u0430\u0448 \u0441\u0447\u0435\u0442 \u0431\u044b\u043b\u043e \u0437\u0430\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e " + ChatColor.GREEN + money * PrisonPlayer.getPrisonPlayer(key).getExpMultiplier() + "$");
  195. PrisonPlayer.getPrisonPlayer(p).addExp((int)(Main.BERSERK_EXP * PrisonPlayer.getPrisonPlayer(key).getExpMultiplier()));
  196. p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder("+" + (int)(Main.BERSERK_EXP * PrisonPlayer.getPrisonPlayer(key).getExpMultiplier()) + " \u043e\u043f\u044b\u0442").color(net.md_5.bungee.api.ChatColor.GOLD).create());
  197. }
  198. }
  199. Bukkit.broadcastMessage(ChatColor.RED +(Utils.f("&a\u0411\u043e\u0441\u0441 &c\u0411\u0435\u0440\u0441\u0435\u0440\u043a &a\u0431\u044b\u043b \u0443\u0431\u0438\u0442!")));
  200. Main.dropBerserkDropOn(this.getBukkitEntity().getLocation());
  201. }
  202. super.die();
  203. }
  204.  
  205. @Override
  206. public String getName() {
  207. return Main.BERSERK_NAME.replace("<3", "").replace("#", "");
  208. }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement