001    package org.bukkit.event.entity;
002    
003    import org.bukkit.Location;
004    import org.bukkit.TravelAgent;
005    import org.bukkit.entity.Entity;
006    import org.bukkit.event.HandlerList;
007    
008    /**
009     * Called when a non-player entity is about to teleport because it is in
010     * contact with a portal.
011     * <p>
012     * For players see {@link org.bukkit.event.player.PlayerPortalEvent}
013     */
014    public class EntityPortalEvent extends EntityTeleportEvent {
015        private static final HandlerList handlers = new HandlerList();
016        protected boolean useTravelAgent = true;
017        protected TravelAgent travelAgent;
018    
019        public EntityPortalEvent(final Entity entity, final Location from, final Location to, final TravelAgent pta) {
020            super(entity, from, to);
021            this.travelAgent = pta;
022        }
023    
024        /**
025         * Sets whether or not the Travel Agent will be used.
026         * <p>
027         * If this is set to true, the TravelAgent will try to find a Portal at
028         * the {@link #getTo()} Location, and will try to create one if there is
029         * none.
030         * <p>
031         * If this is set to false, the {@link #getEntity()} will only be
032         * teleported to the {@link #getTo()} Location.
033         *
034         * @param useTravelAgent whether to use the Travel Agent
035         */
036        public void useTravelAgent(boolean useTravelAgent) {
037            this.useTravelAgent = useTravelAgent;
038        }
039    
040        /**
041         * Gets whether or not the Travel Agent will be used.
042         * <p>
043         * If this is set to true, the TravelAgent will try to find a Portal at
044         * the {@link #getTo()} Location, and will try to create one if there is
045         * none.
046         * <p>
047         * If this is set to false, the {@link #getEntity()} will only be
048         * teleported to the {@link #getTo()} Location.
049         *
050         * @return whether to use the Travel Agent
051         */
052        public boolean useTravelAgent() {
053            return useTravelAgent;
054        }
055    
056        /**
057         * Gets the Travel Agent used (or not) in this event.
058         *
059         * @return the Travel Agent used (or not) in this event
060         */
061        public TravelAgent getPortalTravelAgent() {
062            return this.travelAgent;
063        }
064    
065        /**
066         * Sets the Travel Agent used (or not) in this event.
067         *
068         * @param travelAgent the Travel Agent used (or not) in this event
069         */
070        public void setPortalTravelAgent(TravelAgent travelAgent) {
071            this.travelAgent = travelAgent;
072        }
073    
074        @Override
075        public HandlerList getHandlers() {
076            return handlers;
077        }
078    
079        public static HandlerList getHandlerList() {
080            return handlers;
081        }
082    }