Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.event.player;
2
3import net.minecraft.server.NetLoginHandler;
4import org.bukkit.entity.Player;
5
6import java.net.InetAddress;
7import java.net.InetSocketAddress;
8
9/**
10 * Stores details for players attempting to log in
11 */
12public class PlayerLoginEvent extends PlayerEvent {
13 private Result result;
14 private String message;
15 private InetAddress playerAddress; //Project Poseidon
16 private InetAddress localAddress;
17
18 public PlayerLoginEvent(final Player player, final NetLoginHandler netLoginHandler) {
19 super(Type.PLAYER_LOGIN, player);
20 this.playerAddress = ((InetSocketAddress) netLoginHandler.networkManager.getSocketAddress()).getAddress();
21 this.localAddress = netLoginHandler.networkManager.socket.getLocalAddress();
22 this.result = Result.ALLOWED;
23 this.message = "";
24 }
25
26 public PlayerLoginEvent(final Type type, final Player player, final Result result, final String message) {
27 super(type, player);
28 this.result = result;
29 this.message = message;
30 }
31
32 //TODO: JavaDoc
33 public InetAddress getAddress() {
34 return playerAddress;
35 }
36
37 public InetAddress getLocalAddress() {
38 return localAddress;
39 }
40
41
42 /**
43 * Gets the current result of the login, as an enum
44 *
45 * @return Current Result of the login
46 */
47 public Result getResult() {
48 return result;
49 }
50
51 /**
52 * Sets the new result of the login, as an enum
53 *
54 * @param result New result to set
55 */
56 public void setResult(final Result result) {
57 this.result = result;
58 }
59
60 /**
61 * Gets the current kick message that will be used if getResult() != Result.ALLOWED
62 *
63 * @return Current kick message
64 */
65 public String getKickMessage() {
66 return message;
67 }
68
69 /**
70 * Sets the kick message to display if getResult() != Result.ALLOWED
71 *
72 * @param message New kick message
73 */
74 public void setKickMessage(final String message) {
75 this.message = message;
76 }
77
78 /**
79 * Allows the player to log in
80 */
81 public void allow() {
82 result = Result.ALLOWED;
83 message = "";
84 }
85
86 /**
87 * Disallows the player from logging in, with the given reason
88 *
89 * @param result New result for disallowing the player
90 * @param message Kick message to display to the user
91 */
92 public void disallow(final Result result, final String message) {
93 this.result = result;
94 this.message = message;
95 }
96
97 /**
98 * Basic kick reasons for communicating to plugins
99 */
100 public enum Result {
101
102 /**
103 * The player is allowed to log in
104 */
105 ALLOWED,
106 /**
107 * The player is not allowed to log in, due to the server being full
108 */
109 KICK_FULL,
110 /**
111 * The player is not allowed to log in, due to them being banned
112 */
113 KICK_BANNED,
114 /**
115 * The player is not allowed to log in, due to their ip being banned
116 */
117 KICK_BANNED_IP,
118 /**
119 * The player is not allowed to log in, due to them not being on the white list
120 */
121 KICK_WHITELIST,
122 /**
123 * The player is not allowed to log in, for reasons undefined
124 */
125 KICK_OTHER
126 }
127}