diff --git a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/EntityIllusioner.java b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/EntityIllusioner.java index 815c928..20ac0cb 100644 --- a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/EntityIllusioner.java +++ b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/EntityIllusioner.java @@ -1,5 +1,7 @@ package com.willfp.illusioner.proxy.v1_15_R1; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.illusioner.illusioner.IllusionerManager; import com.willfp.illusioner.proxy.proxies.EntityIllusionerProxy; import net.minecraft.server.v1_15_R1.EntityHuman; import net.minecraft.server.v1_15_R1.EntityIllagerIllusioner; @@ -20,18 +22,13 @@ import net.minecraft.server.v1_15_R1.PathfinderGoalRandomStroll; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.attribute.Attribute; -import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; -import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; -@SuppressWarnings("unchecked") public class EntityIllusioner extends EntityIllagerIllusioner implements EntityIllusionerProxy { /** * The display name for the illusioner. @@ -47,23 +44,18 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI * Instantiate a new illusioner entity. * * @param location The location to spawn it at. - * @param maxHealth The max health for the illusioner to have. - * @param attackDamage The attack damage for the illusioner to have. - * @param name The name of the illusioner. */ - public EntityIllusioner(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusioner(@NotNull final Location location) { super(EntityTypes.ILLUSIONER, ((CraftWorld) location.getWorld()).getHandle()); - this.displayName = name; + + this.displayName = IllusionerManager.OPTIONS.getName(); this.setPosition(location.getX(), location.getY(), location.getZ()); - this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(maxHealth); - this.setHealth((float) maxHealth); + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(IllusionerManager.OPTIONS.getMaxHealth()); + this.setHealth((float) IllusionerManager.OPTIONS.getMaxHealth()); - this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(attackDamage); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(IllusionerManager.OPTIONS.getAttackDamage()); this.goalSelector.a(0, new PathfinderGoalFloat(this)); this.goalSelector.a(1, new EntityIllagerWizard.b()); @@ -71,45 +63,48 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI this.goalSelector.a(2, new PathfinderGoalBowShoot<>(this, 1.0D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(0, new PathfinderGoalFloat(this)); - this.goalSelector.a(6, new PathfinderGoalBowShoot(this, 0.5D, 20, 15.0F)); + this.goalSelector.a(6, new PathfinderGoalBowShoot<>(this, 0.5D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(9, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 3.0F, 1.0F)); this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityInsentient.class, 8.0F)); this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[]{EntityRaider.class})).a(new Class[0])); - this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, true)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityVillagerAbstract.class, false)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityIronGolem.class, false)).a(300)); + this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityVillagerAbstract.class, false)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityIronGolem.class, false)).a(300)); } @Override - public BossBar createBossbar(@NotNull final Plugin plugin, - @NotNull final BarColor color, - @NotNull final BarStyle style) { + public BossBar createBossbar(@NotNull final AbstractEcoPlugin plugin) { if (bossBar != null) { return bossBar; } - BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, color, style, (BarFlag) null); + BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, IllusionerManager.OPTIONS.getColor(), IllusionerManager.OPTIONS.getStyle(), (BarFlag) null); this.bossBar = bossBar; + LivingEntity entity = (LivingEntity) this.getBukkitEntity(); - entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { - if (entity1 instanceof Player) { - bossBar.addPlayer((Player) entity1); + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.getPlayers().forEach(bossBar::removePlayer); + entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { + if (entity1 instanceof Player) { + bossBar.addPlayer((Player) entity1); + } + }); + } else { + runnable.cancel(); } - }); + }).runTaskTimer(0, 40); - new BukkitRunnable() { - @Override - public void run() { - if (!entity.isDead()) { - bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - } else { - bossBar.getPlayers().forEach(bossBar::removePlayer); - bossBar.setVisible(false); - this.cancel(); - } + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + } else { + bossBar.getPlayers().forEach(bossBar::removePlayer); + bossBar.setVisible(false); + runnable.cancel(); } - }.runTaskTimer(plugin, 0, 1); + }).runTaskTimer(0, 1); return bossBar; } diff --git a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/IllusionerHelper.java b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/IllusionerHelper.java index e3a42c5..bbae6d6 100644 --- a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/IllusionerHelper.java +++ b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/illusioner/proxy/v1_15_R1/IllusionerHelper.java @@ -10,21 +10,14 @@ import org.jetbrains.annotations.NotNull; public class IllusionerHelper implements IllusionerHelperProxy { @Override - public EntityIllusionerProxy spawn(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { - EntityIllusioner illusioner = new EntityIllusioner(location, maxHealth, attackDamage, name); + public EntityIllusionerProxy spawn(@NotNull final Location location) { + EntityIllusioner illusioner = new EntityIllusioner(location); ((CraftWorld) location.getWorld()).getHandle().addEntity(illusioner); return illusioner; } @Override - public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner, - @NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner) { if (illusioner instanceof CraftIllusioner) { if (((CraftIllusioner) illusioner).getHandle() instanceof EntityIllusionerProxy) { return null; @@ -33,6 +26,6 @@ public class IllusionerHelper implements IllusionerHelperProxy { return null; } illusioner.remove(); - return spawn(location, maxHealth, attackDamage, name); + return spawn(illusioner.getLocation()); } } diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/EntityIllusioner.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/EntityIllusioner.java index 5b04d8d..debd3fa 100644 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/EntityIllusioner.java +++ b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/EntityIllusioner.java @@ -1,6 +1,7 @@ package com.willfp.illusioner.proxy.v1_16_R1; - +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.illusioner.illusioner.IllusionerManager; import com.willfp.illusioner.proxy.proxies.EntityIllusionerProxy; import net.minecraft.server.v1_16_R1.EntityHuman; import net.minecraft.server.v1_16_R1.EntityIllagerIllusioner; @@ -21,18 +22,13 @@ import net.minecraft.server.v1_16_R1.PathfinderGoalRandomStroll; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.attribute.Attribute; -import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; -import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; -@SuppressWarnings("unchecked") public class EntityIllusioner extends EntityIllagerIllusioner implements EntityIllusionerProxy { /** * The display name for the illusioner. @@ -48,23 +44,18 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI * Instantiate a new illusioner entity. * * @param location The location to spawn it at. - * @param maxHealth The max health for the illusioner to have. - * @param attackDamage The attack damage for the illusioner to have. - * @param name The name of the illusioner. */ - public EntityIllusioner(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusioner(@NotNull final Location location) { super(EntityTypes.ILLUSIONER, ((CraftWorld) location.getWorld()).getHandle()); - this.displayName = name; + + this.displayName = IllusionerManager.OPTIONS.getName(); this.setPosition(location.getX(), location.getY(), location.getZ()); - this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(maxHealth); - this.setHealth((float) maxHealth); + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(IllusionerManager.OPTIONS.getMaxHealth()); + this.setHealth((float) IllusionerManager.OPTIONS.getMaxHealth()); - this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(attackDamage); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(IllusionerManager.OPTIONS.getAttackDamage()); this.goalSelector.a(0, new PathfinderGoalFloat(this)); this.goalSelector.a(1, new EntityIllagerWizard.b()); @@ -72,45 +63,48 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI this.goalSelector.a(2, new PathfinderGoalBowShoot<>(this, 1.0D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(0, new PathfinderGoalFloat(this)); - this.goalSelector.a(6, new PathfinderGoalBowShoot(this, 0.5D, 20, 15.0F)); + this.goalSelector.a(6, new PathfinderGoalBowShoot<>(this, 0.5D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(9, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 3.0F, 1.0F)); this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityInsentient.class, 8.0F)); this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[]{EntityRaider.class})).a(new Class[0])); - this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, true)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityVillagerAbstract.class, false)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityIronGolem.class, false)).a(300)); + this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityVillagerAbstract.class, false)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityIronGolem.class, false)).a(300)); } @Override - public BossBar createBossbar(@NotNull final Plugin plugin, - @NotNull final BarColor color, - @NotNull final BarStyle style) { + public BossBar createBossbar(@NotNull final AbstractEcoPlugin plugin) { if (bossBar != null) { return bossBar; } - BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, color, style, (BarFlag) null); + BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, IllusionerManager.OPTIONS.getColor(), IllusionerManager.OPTIONS.getStyle(), (BarFlag) null); this.bossBar = bossBar; + LivingEntity entity = (LivingEntity) this.getBukkitEntity(); - entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { - if (entity1 instanceof Player) { - bossBar.addPlayer((Player) entity1); + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.getPlayers().forEach(bossBar::removePlayer); + entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { + if (entity1 instanceof Player) { + bossBar.addPlayer((Player) entity1); + } + }); + } else { + runnable.cancel(); } - }); + }).runTaskTimer(0, 40); - new BukkitRunnable() { - @Override - public void run() { - if (!entity.isDead()) { - bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - } else { - bossBar.getPlayers().forEach(bossBar::removePlayer); - bossBar.setVisible(false); - this.cancel(); - } + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + } else { + bossBar.getPlayers().forEach(bossBar::removePlayer); + bossBar.setVisible(false); + runnable.cancel(); } - }.runTaskTimer(plugin, 0, 1); + }).runTaskTimer(0, 1); return bossBar; } diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/IllusionerHelper.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/IllusionerHelper.java index acf4f8b..8997b1b 100644 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/IllusionerHelper.java +++ b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/illusioner/proxy/v1_16_R1/IllusionerHelper.java @@ -10,21 +10,14 @@ import org.jetbrains.annotations.NotNull; public class IllusionerHelper implements IllusionerHelperProxy { @Override - public EntityIllusionerProxy spawn(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { - EntityIllusioner illusioner = new EntityIllusioner(location, maxHealth, attackDamage, name); + public EntityIllusionerProxy spawn(@NotNull final Location location) { + EntityIllusioner illusioner = new EntityIllusioner(location); ((CraftWorld) location.getWorld()).getHandle().addEntity(illusioner); return illusioner; } @Override - public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner, - @NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner) { if (illusioner instanceof CraftIllusioner) { if (((CraftIllusioner) illusioner).getHandle() instanceof EntityIllusionerProxy) { return null; @@ -33,6 +26,6 @@ public class IllusionerHelper implements IllusionerHelperProxy { return null; } illusioner.remove(); - return spawn(location, maxHealth, attackDamage, name); + return spawn(illusioner.getLocation()); } } diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/EntityIllusioner.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/EntityIllusioner.java index 345d3a9..627d3f8 100644 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/EntityIllusioner.java +++ b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/EntityIllusioner.java @@ -1,6 +1,7 @@ package com.willfp.illusioner.proxy.v1_16_R2; - +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.illusioner.illusioner.IllusionerManager; import com.willfp.illusioner.proxy.proxies.EntityIllusionerProxy; import net.minecraft.server.v1_16_R2.EntityHuman; import net.minecraft.server.v1_16_R2.EntityIllagerIllusioner; @@ -21,18 +22,13 @@ import net.minecraft.server.v1_16_R2.PathfinderGoalRandomStroll; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.attribute.Attribute; -import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; -import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; import org.bukkit.craftbukkit.v1_16_R2.CraftWorld; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; -@SuppressWarnings("unchecked") public class EntityIllusioner extends EntityIllagerIllusioner implements EntityIllusionerProxy { /** * The display name for the illusioner. @@ -48,23 +44,18 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI * Instantiate a new illusioner entity. * * @param location The location to spawn it at. - * @param maxHealth The max health for the illusioner to have. - * @param attackDamage The attack damage for the illusioner to have. - * @param name The name of the illusioner. */ - public EntityIllusioner(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusioner(@NotNull final Location location) { super(EntityTypes.ILLUSIONER, ((CraftWorld) location.getWorld()).getHandle()); - this.displayName = name; + + this.displayName = IllusionerManager.OPTIONS.getName(); this.setPosition(location.getX(), location.getY(), location.getZ()); - this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(maxHealth); - this.setHealth((float) maxHealth); + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(IllusionerManager.OPTIONS.getMaxHealth()); + this.setHealth((float) IllusionerManager.OPTIONS.getMaxHealth()); - this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(attackDamage); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(IllusionerManager.OPTIONS.getAttackDamage()); this.goalSelector.a(0, new PathfinderGoalFloat(this)); this.goalSelector.a(1, new EntityIllagerWizard.b()); @@ -72,45 +63,48 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI this.goalSelector.a(2, new PathfinderGoalBowShoot<>(this, 1.0D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(0, new PathfinderGoalFloat(this)); - this.goalSelector.a(6, new PathfinderGoalBowShoot(this, 0.5D, 20, 15.0F)); + this.goalSelector.a(6, new PathfinderGoalBowShoot<>(this, 0.5D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(9, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 3.0F, 1.0F)); this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityInsentient.class, 8.0F)); this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[]{EntityRaider.class})).a(new Class[0])); - this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, true)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityVillagerAbstract.class, false)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityIronGolem.class, false)).a(300)); + this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityVillagerAbstract.class, false)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityIronGolem.class, false)).a(300)); } @Override - public BossBar createBossbar(@NotNull final Plugin plugin, - @NotNull final BarColor color, - @NotNull final BarStyle style) { + public BossBar createBossbar(@NotNull final AbstractEcoPlugin plugin) { if (bossBar != null) { return bossBar; } - BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, color, style, (BarFlag) null); + BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, IllusionerManager.OPTIONS.getColor(), IllusionerManager.OPTIONS.getStyle(), (BarFlag) null); this.bossBar = bossBar; + LivingEntity entity = (LivingEntity) this.getBukkitEntity(); - entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { - if (entity1 instanceof Player) { - bossBar.addPlayer((Player) entity1); + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.getPlayers().forEach(bossBar::removePlayer); + entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { + if (entity1 instanceof Player) { + bossBar.addPlayer((Player) entity1); + } + }); + } else { + runnable.cancel(); } - }); + }).runTaskTimer(0, 40); - new BukkitRunnable() { - @Override - public void run() { - if (!entity.isDead()) { - bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - } else { - bossBar.getPlayers().forEach(bossBar::removePlayer); - bossBar.setVisible(false); - this.cancel(); - } + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + } else { + bossBar.getPlayers().forEach(bossBar::removePlayer); + bossBar.setVisible(false); + runnable.cancel(); } - }.runTaskTimer(plugin, 0, 1); + }).runTaskTimer(0, 1); return bossBar; } diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/IllusionerHelper.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/IllusionerHelper.java index 51e6101..19dce11 100644 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/IllusionerHelper.java +++ b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/illusioner/proxy/v1_16_R2/IllusionerHelper.java @@ -10,21 +10,14 @@ import org.jetbrains.annotations.NotNull; public class IllusionerHelper implements IllusionerHelperProxy { @Override - public EntityIllusionerProxy spawn(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { - EntityIllusioner illusioner = new EntityIllusioner(location, maxHealth, attackDamage, name); + public EntityIllusionerProxy spawn(@NotNull final Location location) { + EntityIllusioner illusioner = new EntityIllusioner(location); ((CraftWorld) location.getWorld()).getHandle().addEntity(illusioner); return illusioner; } @Override - public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner, - @NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner) { if (illusioner instanceof CraftIllusioner) { if (((CraftIllusioner) illusioner).getHandle() instanceof EntityIllusionerProxy) { return null; @@ -33,6 +26,6 @@ public class IllusionerHelper implements IllusionerHelperProxy { return null; } illusioner.remove(); - return spawn(location, maxHealth, attackDamage, name); + return spawn(illusioner.getLocation()); } } diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/EntityIllusioner.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/EntityIllusioner.java index 5979dab..ef61d64 100644 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/EntityIllusioner.java +++ b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/EntityIllusioner.java @@ -1,5 +1,7 @@ package com.willfp.illusioner.proxy.v1_16_R3; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.illusioner.illusioner.IllusionerManager; import com.willfp.illusioner.proxy.proxies.EntityIllusionerProxy; import net.minecraft.server.v1_16_R3.EntityHuman; import net.minecraft.server.v1_16_R3.EntityIllagerIllusioner; @@ -20,18 +22,13 @@ import net.minecraft.server.v1_16_R3.PathfinderGoalRandomStroll; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.attribute.Attribute; -import org.bukkit.boss.BarColor; import org.bukkit.boss.BarFlag; -import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; -@SuppressWarnings("unchecked") public class EntityIllusioner extends EntityIllagerIllusioner implements EntityIllusionerProxy { /** * The display name for the illusioner. @@ -47,23 +44,18 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI * Instantiate a new illusioner entity. * * @param location The location to spawn it at. - * @param maxHealth The max health for the illusioner to have. - * @param attackDamage The attack damage for the illusioner to have. - * @param name The name of the illusioner. */ - public EntityIllusioner(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusioner(@NotNull final Location location) { super(EntityTypes.ILLUSIONER, ((CraftWorld) location.getWorld()).getHandle()); - this.displayName = name; + + this.displayName = IllusionerManager.OPTIONS.getName(); this.setPosition(location.getX(), location.getY(), location.getZ()); - this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(maxHealth); - this.setHealth((float) maxHealth); + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(IllusionerManager.OPTIONS.getMaxHealth()); + this.setHealth((float) IllusionerManager.OPTIONS.getMaxHealth()); - this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(attackDamage); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(IllusionerManager.OPTIONS.getAttackDamage()); this.goalSelector.a(0, new PathfinderGoalFloat(this)); this.goalSelector.a(1, new EntityIllagerWizard.b()); @@ -71,46 +63,48 @@ public class EntityIllusioner extends EntityIllagerIllusioner implements EntityI this.goalSelector.a(2, new PathfinderGoalBowShoot<>(this, 1.0D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(0, new PathfinderGoalFloat(this)); - this.goalSelector.a(6, new PathfinderGoalBowShoot(this, 0.5D, 20, 15.0F)); + this.goalSelector.a(6, new PathfinderGoalBowShoot<>(this, 0.5D, 20, 15.0F)); this.goalSelector.a(8, new PathfinderGoalRandomStroll(this, 0.6D)); this.goalSelector.a(9, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 3.0F, 1.0F)); this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityInsentient.class, 8.0F)); this.targetSelector.a(1, (new PathfinderGoalHurtByTarget(this, new Class[]{EntityRaider.class})).a(new Class[0])); - this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, true)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityVillagerAbstract.class, false)).a(300)); - this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget(this, EntityIronGolem.class, false)).a(300)); + this.targetSelector.a(2, (new PathfinderGoalNearestAttackableTarget<>(this, EntityHuman.class, true)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityVillagerAbstract.class, false)).a(300)); + this.targetSelector.a(3, (new PathfinderGoalNearestAttackableTarget<>(this, EntityIronGolem.class, false)).a(300)); } @Override - public BossBar createBossbar(@NotNull final Plugin plugin, - @NotNull final BarColor color, - @NotNull final BarStyle style) { + public BossBar createBossbar(@NotNull final AbstractEcoPlugin plugin) { if (bossBar != null) { return bossBar; } - BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, color, style, (BarFlag) null); + BossBar bossBar = Bukkit.getServer().createBossBar(this.displayName, IllusionerManager.OPTIONS.getColor(), IllusionerManager.OPTIONS.getStyle(), (BarFlag) null); this.bossBar = bossBar; LivingEntity entity = (LivingEntity) this.getBukkitEntity(); - entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { - if (entity1 instanceof Player) { - bossBar.addPlayer((Player) entity1); + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.getPlayers().forEach(bossBar::removePlayer); + entity.getNearbyEntities(50, 50, 50).forEach(entity1 -> { + if (entity1 instanceof Player) { + bossBar.addPlayer((Player) entity1); + } + }); + } else { + runnable.cancel(); } - }); + }).runTaskTimer(0, 40); - new BukkitRunnable() { - @Override - public void run() { - if (!entity.isDead()) { - bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - } else { - bossBar.getPlayers().forEach(bossBar::removePlayer); - bossBar.setVisible(false); - this.cancel(); - } + plugin.getRunnableFactory().create(runnable -> { + if (!entity.isDead()) { + bossBar.setProgress(entity.getHealth() / entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + } else { + bossBar.getPlayers().forEach(bossBar::removePlayer); + bossBar.setVisible(false); + runnable.cancel(); } - }.runTaskTimer(plugin, 0, 1); + }).runTaskTimer(0, 1); return bossBar; } diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/IllusionerHelper.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/IllusionerHelper.java index df3618f..416f975 100644 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/IllusionerHelper.java +++ b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/illusioner/proxy/v1_16_R3/IllusionerHelper.java @@ -10,21 +10,14 @@ import org.jetbrains.annotations.NotNull; public class IllusionerHelper implements IllusionerHelperProxy { @Override - public EntityIllusionerProxy spawn(@NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { - EntityIllusioner illusioner = new EntityIllusioner(location, maxHealth, attackDamage, name); + public EntityIllusionerProxy spawn(@NotNull final Location location) { + EntityIllusioner illusioner = new EntityIllusioner(location); ((CraftWorld) location.getWorld()).getHandle().addEntity(illusioner); return illusioner; } @Override - public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner, - @NotNull final Location location, - final double maxHealth, - final double attackDamage, - @NotNull final String name) { + public EntityIllusionerProxy adapt(@NotNull final Illusioner illusioner) { if (illusioner instanceof CraftIllusioner) { if (((CraftIllusioner) illusioner).getHandle() instanceof EntityIllusionerProxy) { return null; @@ -33,6 +26,6 @@ public class IllusionerHelper implements IllusionerHelperProxy { return null; } illusioner.remove(); - return spawn(location, maxHealth, attackDamage, name); + return spawn(illusioner.getLocation()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java index 6d7eea9..748d69d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Attacks.java @@ -1,14 +1,13 @@ package com.willfp.illusioner.config.configs; -import com.willfp.eco.util.config.BaseConfig; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.eco.util.config.StaticBaseConfig; import com.willfp.illusioner.IllusionerPlugin; -public class Attacks extends BaseConfig { +public class Attacks extends StaticBaseConfig { /** * Instantiate attacks.yml. */ public Attacks() { - super("attacks", false, IllusionerPlugin.getInstance()); + super("attacks", IllusionerPlugin.getInstance()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Sounds.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Sounds.java index e474a91..e534883 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Sounds.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/config/configs/Sounds.java @@ -1,14 +1,13 @@ package com.willfp.illusioner.config.configs; -import com.willfp.eco.util.config.BaseConfig; -import com.willfp.eco.util.plugin.AbstractEcoPlugin; +import com.willfp.eco.util.config.StaticBaseConfig; import com.willfp.illusioner.IllusionerPlugin; -public class Sounds extends BaseConfig { +public class Sounds extends StaticBaseConfig { /** * Instantiate sounds.yml. */ public Sounds() { - super("sounds", false, IllusionerPlugin.getInstance()); + super("sounds", IllusionerPlugin.getInstance()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java index fa24301..efe51d8 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/AttackListeners.java @@ -116,5 +116,17 @@ public class AttackListeners implements Listener { event.setCancelled(true); } } + + if (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreFire()) { + if (event.getCause().equals(EntityDamageEvent.DamageCause.FIRE) || event.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK)) { + event.setCancelled(true); + } + } + + if (IllusionerManager.OPTIONS.getGameplayOptions().isIgnoreSuffocation()) { + if (event.getCause().equals(EntityDamageEvent.DamageCause.SUFFOCATION)) { + event.setCancelled(true); + } + } } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/SpawnListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/SpawnListeners.java index 6ecde24..0c795e2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/SpawnListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/listeners/SpawnListeners.java @@ -78,13 +78,8 @@ public class SpawnListeners extends PluginDependent implements Listener { } }); - EntityIllusionerProxy illusioner = ProxyUtils.getProxy(IllusionerHelperProxy.class).spawn( - event.getBlock().getLocation(), - IllusionerManager.OPTIONS.getMaxHealth(), - IllusionerManager.OPTIONS.getAttackDamage(), - IllusionerManager.OPTIONS.getName() - ); - illusioner.createBossbar(this.getPlugin(), IllusionerManager.OPTIONS.getColor(), IllusionerManager.OPTIONS.getStyle()); + EntityIllusionerProxy illusioner = ProxyUtils.getProxy(IllusionerHelperProxy.class).spawn(event.getBlock().getLocation()); + illusioner.createBossbar(this.getPlugin()); } /** @@ -104,17 +99,11 @@ public class SpawnListeners extends PluginDependent implements Listener { Illusioner illusioner = (Illusioner) event.getEntity(); - EntityIllusionerProxy internalIllusioner = ProxyUtils.getProxy(IllusionerHelperProxy.class).adapt( - illusioner, - illusioner.getLocation(), - IllusionerManager.OPTIONS.getMaxHealth(), - IllusionerManager.OPTIONS.getAttackDamage(), - IllusionerManager.OPTIONS.getName() - ); + EntityIllusionerProxy internalIllusioner = ProxyUtils.getProxy(IllusionerHelperProxy.class).adapt(illusioner); if (internalIllusioner == null) { return; } - internalIllusioner.createBossbar(this.getPlugin(), IllusionerManager.OPTIONS.getColor(), IllusionerManager.OPTIONS.getStyle()); + internalIllusioner.createBossbar(this.getPlugin()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java index 11ff377..bb5daf9 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/illusioner/illusioner/options/GameplayOptions.java @@ -58,6 +58,18 @@ public class GameplayOptions extends PluginDependent { @Getter private boolean ignoreExplosionDamage; + /** + * If the illusioner is immune to fire damage. + */ + @Getter + private boolean ignoreFire; + + /** + * If the illusioner is immune to suffocation damage. + */ + @Getter + private boolean ignoreSuffocation; + /** * Gameplay options. * @param plugin The plugin. @@ -87,6 +99,8 @@ public class GameplayOptions extends PluginDependent { shuffle = IllusionerConfigs.ATTACKS.getBool("shuffle.enabled"); shuffleChance = IllusionerConfigs.ATTACKS.getDouble("shuffle.chance"); ignoreExplosionDamage = this.getPlugin().getConfigYml().getBool("ignore-explosion-damage"); + ignoreFire = this.getPlugin().getConfigYml().getBool("ignore-fire-damage"); + ignoreSuffocation = this.getPlugin().getConfigYml().getBool("ignore-suffocation-damage"); effectOptions.clear(); IllusionerConfigs.ATTACKS.getConfig().getConfigurationSection("effects").getKeys(false).forEach(key -> { diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 01ed1b1..196e3cf 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -19,6 +19,8 @@ xp: max-health: 600 # Hearts is this number divided by 2, eg 600 is 300 hearts attack-damage: 50 # This isn't an easy boss. Recommend to keep this high ignore-explosion-damage: true +ignore-fire-damage: false +ignore-suffocation-damage: true spawn: # Configure a 3x1 tall column of blocks to summon an illusioner diff --git a/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/EntityIllusionerProxy.java b/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/EntityIllusionerProxy.java index 45c264e..56a0c24 100644 --- a/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/EntityIllusionerProxy.java +++ b/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/EntityIllusionerProxy.java @@ -1,10 +1,8 @@ package com.willfp.illusioner.proxy.proxies; +import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.proxy.AbstractProxy; -import org.bukkit.boss.BarColor; -import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; public interface EntityIllusionerProxy extends AbstractProxy { @@ -12,11 +10,7 @@ public interface EntityIllusionerProxy extends AbstractProxy { * Create boss bar for an illusioner. * * @param plugin The plugin that owns the boss bar. - * @param color The color of the boss bar. - * @param style The style of the boss bar. * @return The created boss bar. */ - BossBar createBossbar(@NotNull Plugin plugin, - @NotNull BarColor color, - @NotNull BarStyle style); + BossBar createBossbar(@NotNull AbstractEcoPlugin plugin); } diff --git a/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/IllusionerHelperProxy.java b/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/IllusionerHelperProxy.java index b58c106..a592d29 100644 --- a/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/IllusionerHelperProxy.java +++ b/eco-core/core-proxy/src/main/java/com/willfp/illusioner/proxy/proxies/IllusionerHelperProxy.java @@ -10,29 +10,15 @@ public interface IllusionerHelperProxy extends AbstractProxy { * Spawn an illusioner. * * @param location The location to spawn it at. - * @param maxHealth The health for the illusioner to have. - * @param attackDamage The attack damage for the illusioner to have. - * @param name The name of the illusioner. * @return The created illusioner. */ - EntityIllusionerProxy spawn(@NotNull Location location, - double maxHealth, - double attackDamage, - @NotNull String name); + EntityIllusionerProxy spawn(@NotNull Location location); /** * Convert a normal illusioner to a plugin-based one. * * @param illusioner The illusioner to convert. - * @param location The location to spawn it at. - * @param maxHealth The health for the illusioner to have. - * @param attackDamage The attack damage for the illusioner to have. - * @param name The name of the illusioner. * @return The created illusioner. */ - EntityIllusionerProxy adapt(@NotNull Illusioner illusioner, - @NotNull Location location, - double maxHealth, - double attackDamage, - @NotNull String name); + EntityIllusionerProxy adapt(@NotNull Illusioner illusioner); }