9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-23 08:59:31 +00:00

Cleaned up code

This commit is contained in:
Auxilor
2021-01-30 11:38:59 +00:00
parent 7881c5e94a
commit efbbd7d623
16 changed files with 193 additions and 249 deletions

View File

@@ -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;
}

View File

@@ -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());
}
}

View File

@@ -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;
}

View File

@@ -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());
}
}

View File

@@ -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;
}

View File

@@ -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());
}
}

View File

@@ -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;
}

View File

@@ -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());
}
}