almost there
This commit is contained in:
parent
3e183bb48e
commit
af78559783
1 changed files with 15 additions and 5 deletions
|
@ -20,6 +20,7 @@ import org.bukkit.entity.LivingEntity;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
@ -80,7 +81,8 @@ public class Main extends JavaPlugin implements Listener {
|
|||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entity e : giants) {
|
||||
for (Entity e : giants) {
|
||||
if (!(e.isValid())) continue;
|
||||
Collection<Entity> nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(
|
||||
attackReach, expandUp, attackReach), n -> (n instanceof Player));
|
||||
for (Entity p : nearby) {
|
||||
|
@ -116,22 +118,30 @@ public class Main extends JavaPlugin implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityDamage(EntityDamageByEntityEvent e) {
|
||||
LivingEntity entity = (LivingEntity) e.getDamager();
|
||||
if (entity.hasMetadata("giant")) {
|
||||
entity.setInvulnerable(false);
|
||||
entity.setHealth(0);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityDeath(EntityDeathEvent e) {
|
||||
Entity entity = e.getEntity();
|
||||
LivingEntity entity = e.getEntity();
|
||||
if (entity.getType() == EntityType.GIANT) {
|
||||
giants.remove(entity);
|
||||
for (Entity p : entity.getPassengers()) ((LivingEntity) p).setHealth(0);
|
||||
}
|
||||
}
|
||||
|
||||
Entity spawnGiant(boolean ai, Location pos) {
|
||||
LivingEntity spawnGiant(boolean ai, Location pos) {
|
||||
LivingEntity entity = (LivingEntity) pos.getWorld().spawnEntity(pos, EntityType.GIANT);
|
||||
if (ai) {
|
||||
LivingEntity passenger = (LivingEntity) pos.getWorld().spawnEntity(pos, EntityType.HUSK);
|
||||
new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1)
|
||||
.apply((LivingEntity) passenger);
|
||||
new PotionEffect(PotionEffectType.WEAKNESS, Integer.MAX_VALUE, 255)
|
||||
.apply((LivingEntity) passenger);
|
||||
passenger.setCustomName("Giant");
|
||||
passenger.setCustomNameVisible(false);
|
||||
passenger.setInvulnerable(true);
|
||||
|
|
Loading…
Reference in a new issue