001 package org.bukkit.event.player;
002
003 import java.net.InetAddress;
004 import java.util.UUID;
005
006 import org.bukkit.Warning;
007 import org.bukkit.event.Event;
008 import org.bukkit.event.HandlerList;
009
010 /**
011 * Stores details for players attempting to log in
012 *
013 * @deprecated This event causes synchronization from the login thread; {@link
014 * AsyncPlayerPreLoginEvent} is preferred to keep the secondary threads
015 * asynchronous.
016 */
017 @Deprecated
018 @Warning(reason="This event causes a login thread to synchronize with the main thread")
019 public class PlayerPreLoginEvent extends Event {
020 private static final HandlerList handlers = new HandlerList();
021 private Result result;
022 private String message;
023 private final String name;
024 private final InetAddress ipAddress;
025 private final UUID uniqueId;
026
027 @Deprecated
028 public PlayerPreLoginEvent(final String name, final InetAddress ipAddress) {
029 this(name, ipAddress, null);
030 }
031
032 public PlayerPreLoginEvent(final String name, final InetAddress ipAddress, final UUID uniqueId) {
033 this.result = Result.ALLOWED;
034 this.message = "";
035 this.name = name;
036 this.ipAddress = ipAddress;
037 this.uniqueId = uniqueId;
038 }
039
040 /**
041 * Gets the current result of the login, as an enum
042 *
043 * @return Current Result of the login
044 */
045 public Result getResult() {
046 return result;
047 }
048
049 /**
050 * Sets the new result of the login, as an enum
051 *
052 * @param result New result to set
053 */
054 public void setResult(final Result result) {
055 this.result = result;
056 }
057
058 /**
059 * Gets the current kick message that will be used if getResult() !=
060 * Result.ALLOWED
061 *
062 * @return Current kick message
063 */
064 public String getKickMessage() {
065 return message;
066 }
067
068 /**
069 * Sets the kick message to display if getResult() != Result.ALLOWED
070 *
071 * @param message New kick message
072 */
073 public void setKickMessage(final String message) {
074 this.message = message;
075 }
076
077 /**
078 * Allows the player to log in
079 */
080 public void allow() {
081 result = Result.ALLOWED;
082 message = "";
083 }
084
085 /**
086 * Disallows the player from logging in, with the given reason
087 *
088 * @param result New result for disallowing the player
089 * @param message Kick message to display to the user
090 */
091 public void disallow(final Result result, final String message) {
092 this.result = result;
093 this.message = message;
094 }
095
096 /**
097 * Gets the player's name.
098 *
099 * @return the player's name
100 */
101 public String getName() {
102 return name;
103 }
104
105 /**
106 * Gets the player IP address.
107 *
108 * @return The IP address
109 */
110 public InetAddress getAddress() {
111 return ipAddress;
112 }
113
114 @Override
115 public HandlerList getHandlers() {
116 return handlers;
117 }
118
119 /**
120 * Gets the player's unique ID.
121 *
122 * @return The unique ID
123 */
124 public UUID getUniqueId() {
125 return uniqueId;
126 }
127
128 public static HandlerList getHandlerList() {
129 return handlers;
130 }
131
132 /**
133 * Basic kick reasons for communicating to plugins
134 */
135 public enum Result {
136
137 /**
138 * The player is allowed to log in
139 */
140 ALLOWED,
141 /**
142 * The player is not allowed to log in, due to the server being full
143 */
144 KICK_FULL,
145 /**
146 * The player is not allowed to log in, due to them being banned
147 */
148 KICK_BANNED,
149 /**
150 * The player is not allowed to log in, due to them not being on the
151 * white list
152 */
153 KICK_WHITELIST,
154 /**
155 * The player is not allowed to log in, for reasons undefined
156 */
157 KICK_OTHER
158 }
159 }