use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class ZombieBloat method bloatEffect.
private void bloatEffect(LivingEntity eventZombie) {
/*
Spawn giant for "bloat" effect
*/
Giant giant = (Giant) eventZombie.getWorld().spawnEntity(eventZombie.getLocation(), EntityType.GIANT);
giant.setAI(false);
/*
Apply knockback to all living entities around the giant except for the original zombie entity
*/
List<Entity> nearbyEntities = giant.getNearbyEntities(4, 15, 4);
List<LivingEntity> nearbyValidLivingEntities = new ArrayList<>();
if (nearbyEntities.size() > 0)
for (Entity entity : nearbyEntities) if (entity instanceof LivingEntity && !entity.equals(eventZombie))
nearbyValidLivingEntities.add((LivingEntity) entity);
Location entityLocation = eventZombie.getLocation();
for (LivingEntity livingEntity : nearbyValidLivingEntities) {
Location livingEntityLocation = livingEntity.getLocation();
Vector toLivingEntityVector = livingEntityLocation.subtract(entityLocation).toVector();
/*
Normalize vector to apply powers uniformly
*/
Vector normalizedVector = toLivingEntityVector.normalize();
normalizedVector = normalizedVector.multiply(new Vector(2, 0, 2)).add(new Vector(0, 1, 0));
try {
livingEntity.setVelocity(normalizedVector);
} catch (Exception e) {
livingEntity.setVelocity(new Vector(0, 1.5, 0));
}
}
livingEntityEffect(nearbyValidLivingEntities);
/*
Effect is done, start task to remove giant
*/
new BukkitRunnable() {
@Override
public void run() {
giant.remove();
eventZombie.setAI(true);
}
}.runTaskLater(MetadataHandler.PLUGIN, 10);
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class ZombieBloat method onHit.
@EventHandler
public void onHit(EliteMobDamagedByPlayerEvent event) {
ZombieBloat zombieBloat = (ZombieBloat) event.getEliteMobEntity().getPower(this);
if (zombieBloat == null)
return;
if (zombieBloat.isInGlobalCooldown())
return;
if (ThreadLocalRandom.current().nextDouble() > 0.20)
return;
zombieBloat.doGlobalCooldown(20 * 10);
/*
Create early warning that entity is about to bloat
*/
new BukkitRunnable() {
final LivingEntity eventZombie = (LivingEntity) event.getEntity();
int timer = 0;
@Override
public void run() {
if (timer > 40) {
bloatEffect(eventZombie);
cancel();
}
if (timer == 21)
eventZombie.setAI(false);
if (MobCombatSettingsConfig.isEnableWarningVisualEffects())
eventZombie.getWorld().spawnParticle(Particle.TOTEM, new Location(eventZombie.getWorld(), eventZombie.getLocation().getX(), eventZombie.getLocation().getY() + eventZombie.getHeight(), eventZombie.getLocation().getZ()), 20, timer / 24, timer / 9d, timer / 24d, 0.1);
timer++;
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class ZombieNecronomicon method spawnReinforcements.
private void spawnReinforcements(EliteEntity eliteEntity, LivingEntity targetted, ZombieNecronomicon zombieNecronomicon) {
LivingEntity targetter = eliteEntity.getLivingEntity();
new BukkitRunnable() {
final ArrayList<Entity> entityList = new ArrayList<>();
@Override
public void run() {
if (!eliteEntity.isValid() || !targetted.isValid() || !targetter.isValid() || targetted.getWorld() != targetter.getWorld() || targetted.getLocation().distance(targetter.getLocation()) > 30) {
for (Entity entity : entityList) if (entity.isValid())
entity.remove();
if (eliteEntity.isValid())
targetter.setAI(true);
cancel();
return;
}
int randomizedNumber = ThreadLocalRandom.current().nextInt(5) + 1;
entityList.removeIf(currentEntity -> !currentEntity.isValid());
if (entityList.size() < 11) {
targetter.setAI(false);
if (!zombieNecronomicon.isFiring())
necronomiconVisualEffect(eliteEntity, zombieNecronomicon);
if (randomizedNumber < 5) {
CustomBossEntity customBossEntity = CustomBossEntity.createCustomBossEntity("necronomicon_zombie.yml");
if (customBossEntity == null) {
new WarningMessage("necronomicon_zombie.yml is not valid!");
return;
}
customBossEntity.spawn(targetter.getLocation(), eliteEntity.getLevel(), false);
if (!customBossEntity.getLivingEntity().isValid()) {
targetter.setAI(true);
cancel();
targetter.setAI(true);
cancel();
return;
}
customBossEntity.getLivingEntity().setVelocity(new Vector((ThreadLocalRandom.current().nextDouble() - 0.5) / 30, 0.5, (ThreadLocalRandom.current().nextDouble() - 0.5) / 30));
eliteEntity.addReinforcement(customBossEntity);
entityList.add(customBossEntity.getLivingEntity());
} else {
CustomBossEntity customBossEntity = CustomBossEntity.createCustomBossEntity("necronomicon_skeleton.yml");
if (customBossEntity == null) {
new WarningMessage("necronomicon_skeleton.yml is not valid!");
targetter.setAI(true);
cancel();
return;
}
customBossEntity.spawn(targetter.getLocation(), eliteEntity.getLevel(), false);
if (!customBossEntity.getLivingEntity().isValid()) {
targetter.setAI(true);
cancel();
return;
}
customBossEntity.getLivingEntity().setVelocity(new Vector((ThreadLocalRandom.current().nextDouble() - 0.5) / 30, 0.5, (ThreadLocalRandom.current().nextDouble() - 0.5) / 30));
eliteEntity.addReinforcement(customBossEntity);
entityList.add(customBossEntity.getLivingEntity());
}
} else
targetter.setAI(true);
}
}.runTaskTimer(MetadataHandler.PLUGIN, 20 * 3L, 20 * 3L);
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class Bombardment method activate.
public void activate(EliteEntity eliteEntity) {
if (isActive)
return;
isActive = true;
task = new BukkitRunnable() {
int counter = 0;
@Override
public void run() {
counter++;
if (stopCondition(eliteEntity))
return;
if (firing || isInCooldown(eliteEntity))
return;
if (ThreadLocalRandom.current().nextDouble() > 0.1)
return;
if (eliteEntity.getLivingEntity().getType().equals(EntityType.ENDER_DRAGON)) {
EnderDragon.Phase phase = ((EnderDragon) eliteEntity.getLivingEntity()).getPhase();
if (phase.equals(EnderDragon.Phase.DYING) || phase.equals(EnderDragon.Phase.HOVER) || phase.equals(EnderDragon.Phase.ROAR_BEFORE_ATTACK) || phase.equals(EnderDragon.Phase.FLY_TO_PORTAL) || phase.equals(EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET)) {
return;
}
}
for (Entity entity : eliteEntity.getLivingEntity().getNearbyEntities(10, 100, 10)) {
if (entity.getType().equals(EntityType.PLAYER)) {
firing = true;
fire(eliteEntity);
return;
}
}
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 5);
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class ZombieFriends method onHit.
@EventHandler
public void onHit(EliteMobDamagedByPlayerEvent event) {
ZombieFriends zombieFriendConfig = (ZombieFriends) event.getEliteMobEntity().getPower(this);
if (zombieFriendConfig == null)
return;
if (zombieFriendConfig.isFiring())
return;
if (ThreadLocalRandom.current().nextDouble() > 0.01)
return;
zombieFriendConfig.setFiring(true);
CustomBossEntity reinforcement1 = CustomBossEntity.createCustomBossEntity("zombie_friends_friend.yml");
reinforcement1.spawn(event.getEntity().getLocation(), event.getEliteMobEntity().getLevel(), false);
CustomBossEntity reinforcement2 = CustomBossEntity.createCustomBossEntity("zombie_friends_friend.yml");
reinforcement2.spawn(event.getEntity().getLocation(), event.getEliteMobEntity().getLevel(), false);
new BukkitRunnable() {
@Override
public void run() {
if (!event.getEliteMobEntity().isValid() || !reinforcement1.isValid() && !reinforcement2.isValid()) {
if (reinforcement1 != null && reinforcement1.isValid()) {
nameClearer(reinforcement1);
reinforcement1.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.friendDeathMessage.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.friendDeathMessage.size()))));
}
if (reinforcement2 != null && reinforcement2.isValid()) {
nameClearer(reinforcement2);
reinforcement2.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.friendDeathMessage.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.friendDeathMessage.size()))));
}
cancel();
return;
} else {
if (ThreadLocalRandom.current().nextDouble() < 0.5) {
nameClearer(event.getEliteMobEntity());
event.getEliteMobEntity().getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.originalEntityDialog.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.originalEntityDialog.size()))));
}
if (ThreadLocalRandom.current().nextDouble() < 0.5 && reinforcement1.isValid()) {
nameClearer(reinforcement1);
reinforcement1.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.reinforcementDialog.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.reinforcementDialog.size()))));
}
if (ThreadLocalRandom.current().nextDouble() < 0.5 && reinforcement2.isValid()) {
nameClearer(reinforcement2);
reinforcement2.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.reinforcementDialog.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.reinforcementDialog.size()))));
}
}
}
}.runTaskTimer(MetadataHandler.PLUGIN, 20, 20 * 8);
}
Aggregations