Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerPortalEvent.java
1 package org.bukkit.event.player;
2 
3 import org.bukkit.Location;
4 import org.bukkit.TravelAgent;
5 import org.bukkit.entity.Player;
7 
8 /**
9  * Called when a player is about to teleport because it is in contact with a
10  * portal.
11  * <p>
12  * For other entities see {@link org.bukkit.event.entity.EntityPortalEvent}
13  */
14 public class PlayerPortalEvent extends PlayerTeleportEvent {
15  private static final HandlerList handlers = new HandlerList();
16  protected boolean useTravelAgent = true;
17  protected TravelAgent travelAgent;
18 
19  public PlayerPortalEvent(final Player player, final Location from, final Location to, final TravelAgent pta) {
20  super(player, from, to);
21  this.travelAgent = pta;
22  }
23 
24  public PlayerPortalEvent(Player player, Location from, Location to, TravelAgent pta, TeleportCause cause) {
25  super(player, from, to, cause);
26  this.travelAgent = pta;
27  }
28 
29  /**
30  * Sets whether or not the Travel Agent will be used.
31  * <p>
32  * If this is set to true, the TravelAgent will try to find a Portal at
33  * the {@link #getTo()} Location, and will try to create one if there is
34  * none.
35  * <p>
36  * If this is set to false, the {@link #getPlayer()} will only be
37  * teleported to the {@link #getTo()} Location.
38  *
39  * @param useTravelAgent whether to use the Travel Agent
40  */
41  public void useTravelAgent(boolean useTravelAgent) {
42  this.useTravelAgent = useTravelAgent;
43  }
44 
45  /**
46  * Gets whether or not the Travel Agent will be used.
47  * <p>
48  * If this is set to true, the TravelAgent will try to find a Portal at
49  * the {@link #getTo()} Location, and will try to create one if there is
50  * none.
51  * <p>
52  * If this is set to false, the {@link #getPlayer()}} will only be
53  * teleported to the {@link #getTo()} Location.
54  *
55  * @return whether to use the Travel Agent
56  */
57  public boolean useTravelAgent() {
58  return useTravelAgent && travelAgent != null;
59  }
60 
61  /**
62  * Gets the Travel Agent used (or not) in this event.
63  *
64  * @return the Travel Agent used (or not) in this event
65  */
67  return this.travelAgent;
68  }
69 
70  /**
71  * Sets the Travel Agent used (or not) in this event.
72  *
73  * @param travelAgent the Travel Agent used (or not) in this event
74  */
75  public void setPortalTravelAgent(TravelAgent travelAgent) {
76  this.travelAgent = travelAgent;
77  }
78 
79  @Override
80  public HandlerList getHandlers() {
81  return handlers;
82  }
83 
84  public static HandlerList getHandlerList() {
85  return handlers;
86  }
87 }
void setPortalTravelAgent(TravelAgent travelAgent)
void useTravelAgent(boolean useTravelAgent)