Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerPreLoginEvent.java
1 package org.bukkit.event.player;
2 
3 import java.net.InetAddress;
4 import java.util.UUID;
5 
6 import org.bukkit.Warning;
7 import org.bukkit.event.Event;
9 
10 /**
11  * Stores details for players attempting to log in
12  *
13  * @deprecated This event causes synchronization from the login thread; {@link
14  * AsyncPlayerPreLoginEvent} is preferred to keep the secondary threads
15  * asynchronous.
16  */
17 @Deprecated
18 @Warning(reason="This event causes a login thread to synchronize with the main thread")
19 public class PlayerPreLoginEvent extends Event {
20  private static final HandlerList handlers = new HandlerList();
21  private Result result;
22  private String message;
23  private final String name;
24  private final InetAddress ipAddress;
25  private final UUID uniqueId;
26 
27  @Deprecated
28  public PlayerPreLoginEvent(final String name, final InetAddress ipAddress) {
29  this(name, ipAddress, null);
30  }
31 
32  public PlayerPreLoginEvent(final String name, final InetAddress ipAddress, final UUID uniqueId) {
33  this.result = Result.ALLOWED;
34  this.message = "";
35  this.name = name;
36  this.ipAddress = ipAddress;
37  this.uniqueId = uniqueId;
38  }
39 
40  /**
41  * Gets the current result of the login, as an enum
42  *
43  * @return Current Result of the login
44  */
45  public Result getResult() {
46  return result;
47  }
48 
49  /**
50  * Sets the new result of the login, as an enum
51  *
52  * @param result New result to set
53  */
54  public void setResult(final Result result) {
55  this.result = result;
56  }
57 
58  /**
59  * Gets the current kick message that will be used if getResult() !=
60  * Result.ALLOWED
61  *
62  * @return Current kick message
63  */
64  public String getKickMessage() {
65  return message;
66  }
67 
68  /**
69  * Sets the kick message to display if getResult() != Result.ALLOWED
70  *
71  * @param message New kick message
72  */
73  public void setKickMessage(final String message) {
74  this.message = message;
75  }
76 
77  /**
78  * Allows the player to log in
79  */
80  public void allow() {
81  result = Result.ALLOWED;
82  message = "";
83  }
84 
85  /**
86  * Disallows the player from logging in, with the given reason
87  *
88  * @param result New result for disallowing the player
89  * @param message Kick message to display to the user
90  */
91  public void disallow(final Result result, final String message) {
92  this.result = result;
93  this.message = message;
94  }
95 
96  /**
97  * Gets the player's name.
98  *
99  * @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  */
141  /**
142  * The player is not allowed to log in, due to the server being full
143  */
145  /**
146  * The player is not allowed to log in, due to them being banned
147  */
149  /**
150  * The player is not allowed to log in, due to them not being on the
151  * white list
152  */
154  /**
155  * The player is not allowed to log in, for reasons undefined
156  */
157  KICK_OTHER
158  }
159 }
void disallow(final Result result, final String message)