Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.raptor.mob.neutral.vikings;
- import java.io.File;
- import java.util.HashMap;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.NamespacedKey;
- import org.bukkit.Sound;
- import org.bukkit.attribute.Attribute;
- import org.bukkit.entity.Damageable;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Zombie;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import org.bukkit.scheduler.BukkitRunnable;
- import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobSpawnEvent;
- import me.raptor.merchant.AbstractEntityListener;
- import me.raptor.merchant.MerchantConversation;
- public class Berserker extends AbstractEntityListener {
- Plugin plugin;
- private static NamespacedKey key;
- HashMap<Integer, String> sounds = new HashMap<>();
- //skin file
- File file;
- Random r = new Random();
- public Berserker(Plugin plugin, String path) {
- this.plugin = plugin;
- Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
- key = new NamespacedKey(plugin, "Viking_Berserker");
- file = new File(path + "berserker.png");
- }
- public static NamespacedKey getKey() {
- return key;
- }
- @EventHandler
- public void onBerserkerSpawn(MythicMobSpawnEvent e) {
- new BukkitRunnable() {
- @Override
- public void run() {
- if (e.getEntity() instanceof Zombie) {
- Zombie z = (Zombie) e.getEntity();
- if (checkName(z, "Viking_Berserker")) {
- setKey(z, "Viking_Berserker", key);
- //Give it a name, why not?
- String name = MerchantConversation.chooseRandomName("Berserker");
- z.setCustomName(name);
- z.setCustomNameVisible(true);
- MerchantConversation.activateSpeakingAbility(z, "Viking_Berserker", 10, 30, name + ": ");
- z.teleport(z.getWorld().getHighestBlockAt(z.getLocation()).getLocation().add(0, 2, 0));
- z.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.4);
- setSkin(z, file, name);
- }
- }
- }
- }.runTaskLater(plugin, 1);
- }
- @EventHandler
- public void onBerserkerThunderRoar(EntityDamageByEntityEvent e) {
- if (e.getEntity() instanceof Zombie && e.getDamager() instanceof LivingEntity) {
- Zombie z = (Zombie) e.getEntity();
- if (checkKey(z, "Viking_Berserker", key)) {
- Roar(z, (LivingEntity) e.getDamager(), 10);
- }
- }
- }
- public void Roar(Zombie z, LivingEntity d, int percent) {
- if (!(r.nextInt(101) <= percent)) return;
- z.getWorld().playSound(z.getLocation(), Sound.ENTITY_LIGHTNING_BOLT_THUNDER, 5, 1);
- z.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20*3, 1));
- z.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20*3, 1));
- z.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 20*3, 1));
- z.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20*3, 1));
- z.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20*3, 1));
- if(d instanceof Damageable) {
- ((Damageable) d).damage(6, z);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment