From cd53bd98952d61f137c9e4320bb69b79b3424644 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 15 Mar 2016 23:28:35 -0400 Subject: SPIGOT-1934: Expand EnderDragon API - adds dragon phases --- src/main/java/org/bukkit/entity/EnderDragon.java | 70 ++++++++++++++++++++ .../event/entity/EnderDragonChangePhaseEvent.java | 76 ++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 src/main/java/org/bukkit/event/entity/EnderDragonChangePhaseEvent.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/bukkit/entity/EnderDragon.java b/src/main/java/org/bukkit/entity/EnderDragon.java index 609f3ba5..9b4b24e3 100644 --- a/src/main/java/org/bukkit/entity/EnderDragon.java +++ b/src/main/java/org/bukkit/entity/EnderDragon.java @@ -5,4 +5,74 @@ package org.bukkit.entity; */ public interface EnderDragon extends ComplexLivingEntity { + /** + * Represents a phase or action that an Ender Dragon can perform. + */ + enum Phase { + /** + * The dragon will circle outside the ring of pillars if ender + * crystals remain or inside the ring if not. + */ + CIRCLING, + /** + * The dragon will fly towards a targetted player and shoot a + * fireball when within 64 blocks. + */ + STRAFING, + /** + * The dragon will fly towards the empty portal (approaching + * from the other side, if applicable). + */ + FLY_TO_PORTAL, + /** + * The dragon will land on on the portal. If the dragon is not near + * the portal, it will fly to it before mounting. + */ + LAND_ON_PORTAL, + /** + * The dragon will leave the portal. + */ + LEAVE_PORTAL, + /** + * The dragon will attack with dragon breath at its current location. + */ + BREATH_ATTACK, + /** + * The dragon will search for a player to attack with dragon breath. + * If no player is close enough to the dragon for 5 seconds, the + * dragon will charge at a player within 150 blocks or will take off + * and begin circling if no player is found. + */ + SEARCH_FOR_BREATH_ATTACK_TARGET, + /** + * The dragon will roar before performing a breath attack. + */ + ROAR_BEFORE_ATTACK, + /** + * The dragon will charge a player. + */ + CHARGE_PLAYER, + /** + * The dragon will fly to the vicinity of the portal and die. + */ + DYING, + /** + * The dragon will hover at its current location, not performing any actions. + */ + HOVER + } + + /** + * Gets the current phase that the dragon is performing. + * + * @return the current phase + */ + Phase getPhase(); + + /** + * Sets the next phase for the dragon to perform. + * + * @param phase the next phase + */ + void setPhase(Phase phase); } diff --git a/src/main/java/org/bukkit/event/entity/EnderDragonChangePhaseEvent.java b/src/main/java/org/bukkit/event/entity/EnderDragonChangePhaseEvent.java new file mode 100644 index 00000000..92b9615f --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EnderDragonChangePhaseEvent.java @@ -0,0 +1,76 @@ +package org.bukkit.event.entity; + +import org.apache.commons.lang.Validate; +import org.bukkit.entity.EnderDragon; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * Called when an EnderDragon switches controller phase. + */ +public class EnderDragonChangePhaseEvent extends EntityEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancel; + private final EnderDragon.Phase currentPhase; + private EnderDragon.Phase newPhase; + + public EnderDragonChangePhaseEvent(EnderDragon enderDragon, EnderDragon.Phase currentPhase, EnderDragon.Phase newPhase) { + super(enderDragon); + this.currentPhase = currentPhase; + this.setNewPhase(newPhase); + } + + @Override + public EnderDragon getEntity() { + return (EnderDragon) entity; + } + + /** + * Gets the current phase that the dragon is in. This method will return null + * when a dragon is first spawned and hasn't yet been assigned a phase. + * + * @return the current dragon phase + */ + public EnderDragon.Phase getCurrentPhase() { + return currentPhase; + } + + /** + * Gets the new phase that the dragon will switch to. + * + * @return the new dragon phase + */ + public EnderDragon.Phase getNewPhase() { + return newPhase; + } + + /** + * Sets the new phase for the ender dragon. + * + * @param newPhase the new dragon phase + */ + public void setNewPhase(EnderDragon.Phase newPhase) { + Validate.notNull(newPhase, "New dragon phase cannot be null"); + this.newPhase = newPhase; + } + + @Override + public boolean isCancelled() { + return cancel; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} -- cgit v1.2.3