Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
AsyncPlayerPreLoginEvent.java
1 package org.bukkit.event.player;
2 
3 import java.net.InetAddress;
4 import java.util.UUID;
5 
6 import org.bukkit.event.Event;
8 
9 /**
10  * Stores details for players attempting to log in.
11  * <p>
12  * This event is asynchronous, and not run using main thread.
13  */
14 public class AsyncPlayerPreLoginEvent extends Event {
15  private static final HandlerList handlers = new HandlerList();
16  private Result result;
17  private String message;
18  private final String name;
19  private final InetAddress ipAddress;
20  private final UUID uniqueId;
21 
22  @Deprecated
23  public AsyncPlayerPreLoginEvent(final String name, final InetAddress ipAddress) {
24  this(name, ipAddress, null);
25  }
26 
27  public AsyncPlayerPreLoginEvent(final String name, final InetAddress ipAddress, final UUID uniqueId) {
28  super(true);
29  this.result = Result.ALLOWED;
30  this.message = "";
31  this.name = name;
32  this.ipAddress = ipAddress;
33  this.uniqueId = uniqueId;
34  }
35 
36  /**
37  * Gets the current result of the login, as an enum
38  *
39  * @return Current Result of the login
40  */
42  return result;
43  }
44 
45  /**
46  * Gets the current result of the login, as an enum
47  *
48  * @return Current Result of the login
49  * @deprecated This method uses a deprecated enum from {@link
50  * PlayerPreLoginEvent}
51  * @see #getLoginResult()
52  */
53  @Deprecated
55  return result == null ? null : result.old();
56  }
57 
58  /**
59  * Sets the new result of the login, as an enum
60  *
61  * @param result New result to set
62  */
63  public void setLoginResult(final Result result) {
64  this.result = result;
65  }
66 
67  /**
68  * Sets the new result of the login, as an enum
69  *
70  * @param result New result to set
71  * @deprecated This method uses a deprecated enum from {@link
72  * PlayerPreLoginEvent}
73  * @see #setLoginResult(Result)
74  */
75  @Deprecated
76  public void setResult(final PlayerPreLoginEvent.Result result) {
77  this.result = result == null ? null : Result.valueOf(result.name());
78  }
79 
80  /**
81  * Gets the current kick message that will be used if getResult() !=
82  * Result.ALLOWED
83  *
84  * @return Current kick message
85  */
86  public String getKickMessage() {
87  return message;
88  }
89 
90  /**
91  * Sets the kick message to display if getResult() != Result.ALLOWED
92  *
93  * @param message New kick message
94  */
95  public void setKickMessage(final String message) {
96  this.message = message;
97  }
98 
99  /**
100  * Allows the player to log in
101  */
102  public void allow() {
103  result = Result.ALLOWED;
104  message = "";
105  }
106 
107  /**
108  * Disallows the player from logging in, with the given reason
109  *
110  * @param result New result for disallowing the player
111  * @param message Kick message to display to the user
112  */
113  public void disallow(final Result result, final String message) {
114  this.result = result;
115  this.message = message;
116  }
117 
118  /**
119  * Disallows the player from logging in, with the given reason
120  *
121  * @param result New result for disallowing the player
122  * @param message Kick message to display to the user
123  * @deprecated This method uses a deprecated enum from {@link
124  * PlayerPreLoginEvent}
125  * @see #disallow(Result, String)
126  */
127  @Deprecated
128  public void disallow(final PlayerPreLoginEvent.Result result, final String message) {
129  this.result = result == null ? null : Result.valueOf(result.name());
130  this.message = message;
131  }
132 
133  /**
134  * Gets the player's name.
135  *
136  * @return the player's name
137  */
138  public String getName() {
139  return name;
140  }
141 
142  /**
143  * Gets the player IP address.
144  *
145  * @return The IP address
146  */
147  public InetAddress getAddress() {
148  return ipAddress;
149  }
150 
151  /**
152  * Gets the player's unique ID.
153  *
154  * @return The unique ID
155  */
156  public UUID getUniqueId() {
157  return uniqueId;
158  }
159 
160  @Override
161  public HandlerList getHandlers() {
162  return handlers;
163  }
164 
165  public static HandlerList getHandlerList() {
166  return handlers;
167  }
168 
169  /**
170  * Basic kick reasons for communicating to plugins
171  */
172  public enum Result {
173 
174  /**
175  * The player is allowed to log in
176  */
178  /**
179  * The player is not allowed to log in, due to the server being full
180  */
182  /**
183  * The player is not allowed to log in, due to them being banned
184  */
186  /**
187  * The player is not allowed to log in, due to them not being on the
188  * white list
189  */
191  /**
192  * The player is not allowed to log in, for reasons undefined
193  */
195 
196  @Deprecated
197  private PlayerPreLoginEvent.Result old() {
198  return PlayerPreLoginEvent.Result.valueOf(name());
199  }
200  }
201 }
void setResult(final PlayerPreLoginEvent.Result result)
void disallow(final PlayerPreLoginEvent.Result result, final String message)
void disallow(final Result result, final String message)