Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerLoginEvent.java
1 package org.bukkit.event.player;
2 
3 import java.net.InetAddress;
4 
5 import org.bukkit.entity.Player;
7 
8 /**
9  * Stores details for players attempting to log in
10  */
11 public class PlayerLoginEvent extends PlayerEvent {
12  private static final HandlerList handlers = new HandlerList();
13  private final InetAddress address;
14  private final String hostname;
15  private Result result = Result.ALLOWED;
16  private String message = "";
17 
18  /**
19  * @deprecated Address should be provided in other constructor
20  */
21  @Deprecated
22  public PlayerLoginEvent(final Player player) {
23  this(player, "", null);
24  }
25 
26  /**
27  * @deprecated Address should be provided in other constructor
28  */
29  @Deprecated
30  public PlayerLoginEvent(final Player player, final String hostname) {
31  this(player, hostname, null);
32  }
33 
34  /**
35  * This constructor defaults message to an empty string, and result to
36  * ALLOWED
37  *
38  * @param player The {@link Player} for this event
39  * @param hostname The hostname that was used to connect to the server
40  * @param address The address the player used to connect, provided for
41  * timing issues
42  */
43  public PlayerLoginEvent(final Player player, final String hostname, final InetAddress address) {
44  super(player);
45  this.hostname = hostname;
46  this.address = address;
47  }
48 
49  /**
50  * @deprecated Address and hostname should be provided in other
51  * constructor
52  */
53  @Deprecated
54  public PlayerLoginEvent(final Player player, final Result result, final String message) {
55  this(player, "", null, result, message);
56  }
57 
58  /**
59  * This constructor pre-configures the event with a result and message
60  *
61  * @param player The {@link Player} for this event
62  * @param hostname The hostname that was used to connect to the server
63  * @param address The address the player used to connect, provided for
64  * timing issues
65  * @param result The result status for this event
66  * @param message The message to be displayed if result denies login
67  */
68  public PlayerLoginEvent(final Player player, String hostname, final InetAddress address, final Result result, final String message) {
69  this(player, hostname, address);
70  this.result = result;
71  this.message = message;
72  }
73 
74  /**
75  * Gets the current result of the login, as an enum
76  *
77  * @return Current Result of the login
78  */
79  public Result getResult() {
80  return result;
81  }
82 
83  /**
84  * Sets the new result of the login, as an enum
85  *
86  * @param result New result to set
87  */
88  public void setResult(final Result result) {
89  this.result = result;
90  }
91 
92  /**
93  * Gets the current kick message that will be used if getResult() !=
94  * Result.ALLOWED
95  *
96  * @return Current kick message
97  */
98  public String getKickMessage() {
99  return message;
100  }
101 
102  /**
103  * Sets the kick message to display if getResult() != Result.ALLOWED
104  *
105  * @param message New kick message
106  */
107  public void setKickMessage(final String message) {
108  this.message = message;
109  }
110 
111  /**
112  * Gets the hostname that the player used to connect to the server, or
113  * blank if unknown
114  *
115  * @return The hostname
116  */
117  public String getHostname() {
118  return hostname;
119  }
120 
121  /**
122  * Allows the player to log in
123  */
124  public void allow() {
125  result = Result.ALLOWED;
126  message = "";
127  }
128 
129  /**
130  * Disallows the player from logging in, with the given reason
131  *
132  * @param result New result for disallowing the player
133  * @param message Kick message to display to the user
134  */
135  public void disallow(final Result result, final String message) {
136  this.result = result;
137  this.message = message;
138  }
139 
140  /**
141  * Gets the {@link InetAddress} for the Player associated with this event.
142  * This method is provided as a workaround for player.getAddress()
143  * returning null during PlayerLoginEvent.
144  *
145  * @return The address for this player. For legacy compatibility, this may
146  * be null.
147  */
148  public InetAddress getAddress() {
149  return address;
150  }
151 
152  @Override
153  public HandlerList getHandlers() {
154  return handlers;
155  }
156 
157  public static HandlerList getHandlerList() {
158  return handlers;
159  }
160 
161  /**
162  * Basic kick reasons for communicating to plugins
163  */
164  public enum Result {
165 
166  /**
167  * The player is allowed to log in
168  */
170  /**
171  * The player is not allowed to log in, due to the server being full
172  */
174  /**
175  * The player is not allowed to log in, due to them being banned
176  */
178  /**
179  * The player is not allowed to log in, due to them not being on the
180  * white list
181  */
183  /**
184  * The player is not allowed to log in, for reasons undefined
185  */
186  KICK_OTHER
187  }
188 }
PlayerLoginEvent(final Player player, final Result result, final String message)
PlayerLoginEvent(final Player player, final String hostname)
PlayerLoginEvent(final Player player, String hostname, final InetAddress address, final Result result, final String message)
PlayerLoginEvent(final Player player, final String hostname, final InetAddress address)
void disallow(final Result result, final String message)