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