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.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
@ -81,6 +82,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (Entity e : giants) {
|
for (Entity e : giants) {
|
||||||
|
if (!(e.isValid())) continue;
|
||||||
Collection<Entity> nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(
|
Collection<Entity> nearby = e.getWorld().getNearbyEntities(e.getBoundingBox().expand(
|
||||||
attackReach, expandUp, attackReach), n -> (n instanceof Player));
|
attackReach, expandUp, attackReach), n -> (n instanceof Player));
|
||||||
for (Entity p : nearby) {
|
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
|
@EventHandler
|
||||||
public void entityDeath(EntityDeathEvent e) {
|
public void entityDeath(EntityDeathEvent e) {
|
||||||
Entity entity = e.getEntity();
|
LivingEntity entity = e.getEntity();
|
||||||
if (entity.getType() == EntityType.GIANT) {
|
if (entity.getType() == EntityType.GIANT) {
|
||||||
|
giants.remove(entity);
|
||||||
for (Entity p : entity.getPassengers()) ((LivingEntity) p).setHealth(0);
|
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);
|
LivingEntity entity = (LivingEntity) pos.getWorld().spawnEntity(pos, EntityType.GIANT);
|
||||||
if (ai) {
|
if (ai) {
|
||||||
LivingEntity passenger = (LivingEntity) pos.getWorld().spawnEntity(pos, EntityType.HUSK);
|
LivingEntity passenger = (LivingEntity) pos.getWorld().spawnEntity(pos, EntityType.HUSK);
|
||||||
new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1)
|
new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1)
|
||||||
.apply((LivingEntity) passenger);
|
.apply((LivingEntity) passenger);
|
||||||
new PotionEffect(PotionEffectType.WEAKNESS, Integer.MAX_VALUE, 255)
|
|
||||||
.apply((LivingEntity) passenger);
|
|
||||||
passenger.setCustomName("Giant");
|
passenger.setCustomName("Giant");
|
||||||
passenger.setCustomNameVisible(false);
|
passenger.setCustomNameVisible(false);
|
||||||
passenger.setInvulnerable(true);
|
passenger.setInvulnerable(true);
|
||||||
|
|
Loading…
Reference in a new issue