001 package org.bukkit.event.player;
002
003 import java.net.InetAddress;
004 import java.util.UUID;
005
006 import org.bukkit.event.Event;
007 import org.bukkit.event.HandlerList;
008
009 /**
010 * Stores details for players attempting to log in.
011 * <p>
012 * This event is asynchronous, and not run using main thread.
013 */
014 public class AsyncPlayerPreLoginEvent extends Event {
015 private static final HandlerList handlers = new HandlerList();
016 private Result result;
017 private String message;
018 private final String name;
019 private final InetAddress ipAddress;
020 private final UUID uniqueId;
021
022 @Deprecated
023 public AsyncPlayerPreLoginEvent(final String name, final InetAddress ipAddress) {
024 this(name, ipAddress, null);
025 }
026
027 public AsyncPlayerPreLoginEvent(final String name, final InetAddress ipAddress, final UUID uniqueId) {
028 super(true);
029 this.result = Result.ALLOWED;
030 this.message = "";
031 this.name = name;
032 this.ipAddress = ipAddress;
033 this.uniqueId = uniqueId;
034 }
035
036 /**
037 * Gets the current result of the login, as an enum
038 *
039 * @return Current Result of the login
040 */
041 public Result getLoginResult() {
042 return result;
043 }
044
045 /**
046 * Gets the current result of the login, as an enum
047 *
048 * @return Current Result of the login
049 * @deprecated This method uses a deprecated enum from {@link
050 * PlayerPreLoginEvent}
051 * @see #getLoginResult()
052 */
053 @Deprecated
054 public PlayerPreLoginEvent.Result getResult() {
055 return result == null ? null : result.old();
056 }
057
058 /**
059 * Sets the new result of the login, as an enum
060 *
061 * @param result New result to set
062 */
063 public void setLoginResult(final Result result) {
064 this.result = result;
065 }
066
067 /**
068 * Sets the new result of the login, as an enum
069 *
070 * @param result New result to set
071 * @deprecated This method uses a deprecated enum from {@link
072 * PlayerPreLoginEvent}
073 * @see #setLoginResult(Result)
074 */
075 @Deprecated
076 public void setResult(final PlayerPreLoginEvent.Result result) {
077 this.result = result == null ? null : Result.valueOf(result.name());
078 }
079
080 /**
081 * Gets the current kick message that will be used if getResult() !=
082 * Result.ALLOWED
083 *
084 * @return Current kick message
085 */
086 public String getKickMessage() {
087 return message;
088 }
089
090 /**
091 * Sets the kick message to display if getResult() != Result.ALLOWED
092 *
093 * @param message New kick message
094 */
095 public void setKickMessage(final String message) {
096 this.message = message;
097 }
098
099 /**
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 */
177 ALLOWED,
178 /**
179 * The player is not allowed to log in, due to the server being full
180 */
181 KICK_FULL,
182 /**
183 * The player is not allowed to log in, due to them being banned
184 */
185 KICK_BANNED,
186 /**
187 * The player is not allowed to log in, due to them not being on the
188 * white list
189 */
190 KICK_WHITELIST,
191 /**
192 * The player is not allowed to log in, for reasons undefined
193 */
194 KICK_OTHER;
195
196 @Deprecated
197 private PlayerPreLoginEvent.Result old() {
198 return PlayerPreLoginEvent.Result.valueOf(name());
199 }
200 }
201 }