WayKillerZ

Berserker

Jun 15th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. package me.raptor.mob.neutral.vikings;
  2.  
  3. import java.io.File;
  4. import java.util.HashMap;
  5. import java.util.Random;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.NamespacedKey;
  9. import org.bukkit.Sound;
  10. import org.bukkit.attribute.Attribute;
  11. import org.bukkit.entity.Damageable;
  12. import org.bukkit.entity.LivingEntity;
  13. import org.bukkit.entity.Zombie;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  16. import org.bukkit.plugin.Plugin;
  17. import org.bukkit.potion.PotionEffect;
  18. import org.bukkit.potion.PotionEffectType;
  19. import org.bukkit.scheduler.BukkitRunnable;
  20.  
  21. import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobSpawnEvent;
  22. import me.raptor.merchant.AbstractEntityListener;
  23. import me.raptor.merchant.MerchantConversation;
  24.  
  25. public class Berserker extends AbstractEntityListener {
  26. Plugin plugin;
  27. private static NamespacedKey key;
  28. HashMap<Integer, String> sounds = new HashMap<>();
  29. //skin file
  30. File file;
  31. Random r = new Random();
  32. public Berserker(Plugin plugin, String path) {
  33. this.plugin = plugin;
  34. Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
  35. key = new NamespacedKey(plugin, "Viking_Berserker");
  36. file = new File(path + "berserker.png");
  37. }
  38.  
  39. public static NamespacedKey getKey() {
  40. return key;
  41. }
  42.  
  43. @EventHandler
  44. public void onBerserkerSpawn(MythicMobSpawnEvent e) {
  45. new BukkitRunnable() {
  46. @Override
  47. public void run() {
  48. if (e.getEntity() instanceof Zombie) {
  49. Zombie z = (Zombie) e.getEntity();
  50. if (checkName(z, "Viking_Berserker")) {
  51. setKey(z, "Viking_Berserker", key);
  52. //Give it a name, why not?
  53. String name = MerchantConversation.chooseRandomName("Berserker");
  54. z.setCustomName(name);
  55. z.setCustomNameVisible(true);
  56. MerchantConversation.activateSpeakingAbility(z, "Viking_Berserker", 10, 30, name + ": ");
  57. z.teleport(z.getWorld().getHighestBlockAt(z.getLocation()).getLocation().add(0, 2, 0));
  58. z.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.4);
  59. setSkin(z, file, name);
  60.  
  61. }
  62. }
  63. }
  64. }.runTaskLater(plugin, 1);
  65.  
  66. }
  67.  
  68. @EventHandler
  69. public void onBerserkerThunderRoar(EntityDamageByEntityEvent e) {
  70. if (e.getEntity() instanceof Zombie && e.getDamager() instanceof LivingEntity) {
  71. Zombie z = (Zombie) e.getEntity();
  72. if (checkKey(z, "Viking_Berserker", key)) {
  73. Roar(z, (LivingEntity) e.getDamager(), 10);
  74. }
  75. }
  76. }
  77.  
  78. public void Roar(Zombie z, LivingEntity d, int percent) {
  79. if (!(r.nextInt(101) <= percent)) return;
  80. z.getWorld().playSound(z.getLocation(), Sound.ENTITY_LIGHTNING_BOLT_THUNDER, 5, 1);
  81. z.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20*3, 1));
  82. z.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20*3, 1));
  83. z.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 20*3, 1));
  84. z.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20*3, 1));
  85. z.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20*3, 1));
  86. if(d instanceof Damageable) {
  87. ((Damageable) d).damage(6, z);
  88. }
  89. }
  90.  
  91.  
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment