Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.event.player;
2
3import com.projectposeidon.johnymuffin.ConnectionPause;
4import com.projectposeidon.johnymuffin.LoginProcessHandler;
5import org.bukkit.event.Event;
6import org.bukkit.plugin.Plugin;
7
8import java.net.InetAddress;
9
10/**
11 * Stores details for players attempting to log in
12 */
13public class PlayerPreLoginEvent extends Event {
14 private Result result;
15 private String message;
16 private String name;
17 private InetAddress ipAddress;
18 private LoginProcessHandler loginProcessHandler; // Project Poseidon
19
20 public PlayerPreLoginEvent(String name, InetAddress ipAddress, LoginProcessHandler loginProcessHandler) {
21 super(Type.PLAYER_PRELOGIN);
22 this.loginProcessHandler = loginProcessHandler;
23 this.result = Result.ALLOWED;
24 this.message = "";
25 this.name = name;
26 this.ipAddress = ipAddress;
27 }
28 //Project Poseidon Start
29
30 /**
31 * Set a pause for your plugin
32 * Connection pauses are for fetching data for a player before they MIGHT be allowed to join
33 *
34 * @param plugin Instance of plugin
35 * @param connectionPauseName Name of connection pause (Ensure no duplicates)
36 * @return ConnectionPause Object, used to remove a connection pause
37 */
38 public ConnectionPause addConnectionPause(Plugin plugin, String connectionPauseName) {
39 return loginProcessHandler.addConnectionInterrupt(plugin, connectionPauseName);
40 }
41
42 /**
43 * Remove a pause for your plugin by the returned ConnectionPause object
44 */
45 public void removeConnectionPause(ConnectionPause connectionPause) {
46 loginProcessHandler.removeConnectionPause(connectionPause);
47 }
48
49 /**
50 * Cancel a players login before join or login events if a connection pause is still active
51 */
52 public void cancelPlayerLogin(String kickMessage) {
53 loginProcessHandler.cancelLoginProcess(kickMessage);
54 }
55
56 /**
57 * See if the players connection currently paused
58 */
59 public boolean isPlayerConnectionPaused() {
60 return loginProcessHandler.isPlayerConnectionPaused();
61 }
62
63 /**
64 * Gets the LoginProcessHandler instance for the connection
65 *
66 * @return Gets the LoginProcessHandler
67 */
68 @Deprecated
69 public LoginProcessHandler getLoginProcessHandler() {
70 return loginProcessHandler;
71 }
72
73 //Project Poseidon End
74
75
76 /**
77 * Gets the current result of the login, as an enum
78 *
79 * @return Current Result of the login
80 */
81 public Result getResult() {
82 return result;
83 }
84
85 /**
86 * Sets the new result of the login, as an enum
87 *
88 * @param result New result to set
89 */
90 public void setResult(final Result result) {
91 this.result = result;
92 }
93
94 /**
95 * Gets the current kick message that will be used if getResult() != Result.ALLOWED
96 *
97 * @return Current kick message
98 */
99 public String getKickMessage() {
100 return message;
101 }
102
103 /**
104 * Sets the kick message to display if getResult() != Result.ALLOWED
105 *
106 * @param message New kick message
107 */
108 public void setKickMessage(final String message) {
109 this.message = message;
110 }
111
112 /**
113 * Allows the player to log in
114 */
115 public void allow() {
116 result = Result.ALLOWED;
117 message = "";
118 }
119
120 /**
121 * Disallows the player from logging in, with the given reason
122 *
123 * @param result New result for disallowing the player
124 * @param message Kick message to display to the user
125 */
126 public void disallow(final Result result, final String message) {
127 this.result = result;
128 this.message = message;
129 }
130
131 /**
132 * Gets the player's name.
133 *
134 * @return the player's name
135 */
136 public String getName() {
137 return name;
138 }
139
140 /**
141 * Gets the player IP address.
142 *
143 * @return
144 */
145 public InetAddress getAddress() {
146 return ipAddress;
147 }
148
149 /**
150 * Basic kick reasons for communicating to plugins
151 */
152 public enum Result {
153
154 /**
155 * The player is allowed to log in
156 */
157 ALLOWED,
158 /**
159 * The player is not allowed to log in, due to the server being full
160 */
161 KICK_FULL,
162 /**
163 * The player is not allowed to log in, due to them being banned
164 */
165 KICK_BANNED,
166 /**
167 * The player is not allowed to log in, due to them not being on the white list
168 */
169 KICK_WHITELIST,
170 /**
171 * The player is not allowed to log in, for reasons undefined
172 */
173 KICK_OTHER
174 }
175}