Advertisement
WayKillerZ

VikingArcher

Jun 16th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. package me.raptor.mob.allies.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.Color;
  9. import org.bukkit.Material;
  10. import org.bukkit.NamespacedKey;
  11. import org.bukkit.Particle.DustOptions;
  12. import org.bukkit.attribute.Attribute;
  13. import org.bukkit.entity.Damageable;
  14. import org.bukkit.entity.LivingEntity;
  15. import org.bukkit.entity.Skeleton;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  18. import org.bukkit.inventory.ItemStack;
  19. import org.bukkit.plugin.Plugin;
  20. import org.bukkit.potion.PotionEffect;
  21. import org.bukkit.potion.PotionEffectType;
  22. import org.bukkit.scheduler.BukkitRunnable;
  23.  
  24. import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobSpawnEvent;
  25. import me.raptor.main.ParticleUtils;
  26. import me.raptor.merchant.AbstractEntityListener;
  27. import me.raptor.merchant.MerchantConversation;
  28.  
  29. public class VikingArcher extends AbstractEntityListener{
  30. Plugin plugin;
  31. private static NamespacedKey key;
  32. HashMap<Integer, String> sounds = new HashMap<>();
  33. //skin file
  34. File file;
  35. Random r = new Random();
  36. public VikingArcher(Plugin plugin, String path) {
  37. this.plugin = plugin;
  38. Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
  39. key = new NamespacedKey(plugin, "VikingArcher");
  40. file = new File(path + "viking_archer.png");
  41. }
  42.  
  43. public static NamespacedKey getKey() {
  44. return key;
  45. }
  46.  
  47. @EventHandler
  48. public void onArcherSpawn(MythicMobSpawnEvent e) {
  49. new BukkitRunnable() {
  50. @Override
  51. public void run() {
  52. if (e.getEntity() instanceof Skeleton) {
  53. Skeleton z = (Skeleton) e.getEntity();
  54. if (checkName(z, "VikingArcher")) {
  55. setKey(z, "VikingArcher", key);
  56. VArcherEquipments(z);
  57. //Give it a name, why not?
  58. String name = MerchantConversation.chooseRandomName("VikingArcher");
  59. z.setCustomName(name);
  60. z.setCustomNameVisible(true);
  61. MerchantConversation.activateSpeakingAbility(z, "VikingArcher", 15, 7, name + ": ");
  62. z.teleport(z.getWorld().getHighestBlockAt(z.getLocation()).getLocation().add(0, 2, 0));
  63. z.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.3);
  64. setSkin(z, file, name);
  65.  
  66. }
  67. }
  68. }
  69. }.runTaskLater(plugin, 1);
  70.  
  71. }
  72.  
  73. @EventHandler
  74. public void onArcherShoot(EntityDamageByEntityEvent e) {
  75. if (e.getDamager() instanceof Skeleton && e.getEntity() instanceof LivingEntity) {
  76. Skeleton z = (Skeleton) e.getDamager();
  77. if (checkKey(z, "VikingArcher", key)) {
  78. FrostbiteArrow(z, (LivingEntity) e.getEntity(), 15);
  79. }
  80. }
  81. }
  82.  
  83. public void FrostbiteArrow(Skeleton z, LivingEntity le, int percent) {
  84. if (!(r.nextInt(101) <= percent)) {
  85. le.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 30, 1));
  86. } else {
  87. if(le instanceof Damageable) {
  88. ((Damageable) le).damage(3, z);
  89. }
  90. le.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 2));
  91. le.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1));
  92. le.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 40, 1));
  93. ParticleUtils.SoulSpiralUp(le.getLocation(), 3, 1.5f, 1, 3, 10, 1, new DustOptions(Color.fromRGB(230, 0, 0), (float) 0.75));
  94. }
  95. }
  96.  
  97. public void VArcherEquipments(Skeleton z) {
  98. z.setCanPickupItems(false);
  99. z.getEquipment().setItemInMainHand(new ItemStack(Material.BOW));
  100. z.getEquipment().setHelmet(new ItemStack(Material.IRON_HELMET));
  101. if (r.nextInt(2) == 0) {
  102. z.getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
  103. }
  104. }
  105.  
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement