Added pre-login event for catching logins right after name verification has completed. This happens in a different thread from the server (and thus can also block).
This commit is contained in:
parent
93a3e2448d
commit
3791a158de
@ -152,6 +152,13 @@ public abstract class Event implements Serializable {
|
|||||||
*/
|
*/
|
||||||
PLAYER_LOGIN (Category.PLAYER),
|
PLAYER_LOGIN (Category.PLAYER),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player has just been authenticated
|
||||||
|
*
|
||||||
|
* @see org.bukkit.event.player.PlayerPreLoginEvent
|
||||||
|
*/
|
||||||
|
PLAYER_PRELOGIN (Category.PLAYER),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player respawns
|
* Called when a player respawns
|
||||||
*
|
*
|
||||||
|
@ -100,6 +100,14 @@ public class PlayerListener implements Listener {
|
|||||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player has just been authenticated
|
||||||
|
*
|
||||||
|
* @param event Relevant event details
|
||||||
|
*/
|
||||||
|
public void onPlayerPreLogin(PlayerPreLoginEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player throws an egg and it might hatch
|
* Called when a player throws an egg and it might hatch
|
||||||
*
|
*
|
||||||
|
126
src/main/java/org/bukkit/event/player/PlayerPreLoginEvent.java
Normal file
126
src/main/java/org/bukkit/event/player/PlayerPreLoginEvent.java
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
|
||||||
|
package org.bukkit.event.player;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores details for players attempting to log in
|
||||||
|
*/
|
||||||
|
public class PlayerPreLoginEvent extends Event {
|
||||||
|
private Result result;
|
||||||
|
private String message;
|
||||||
|
private String name;
|
||||||
|
private InetAddress ipAddress;
|
||||||
|
|
||||||
|
public PlayerPreLoginEvent(String name, InetAddress ipAddress) {
|
||||||
|
super(Type.PLAYER_PRELOGIN);
|
||||||
|
this.result = Result.ALLOWED;
|
||||||
|
this.message = "";
|
||||||
|
this.name = name;
|
||||||
|
this.ipAddress = ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current result of the login, as an enum
|
||||||
|
*
|
||||||
|
* @return Current Result of the login
|
||||||
|
*/
|
||||||
|
public Result getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the new result of the login, as an enum
|
||||||
|
*
|
||||||
|
* @param result New result to set
|
||||||
|
*/
|
||||||
|
public void setResult(final Result result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current kick message that will be used if getResult() != Result.ALLOWED
|
||||||
|
*
|
||||||
|
* @return Current kick message
|
||||||
|
*/
|
||||||
|
public String getKickMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the kick message to display if getResult() != Result.ALLOWED
|
||||||
|
*
|
||||||
|
* @param message New kick message
|
||||||
|
*/
|
||||||
|
public void setKickMessage(final String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows the player to log in
|
||||||
|
*/
|
||||||
|
public void allow() {
|
||||||
|
result = Result.ALLOWED;
|
||||||
|
message = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disallows the player from logging in, with the given reason
|
||||||
|
*
|
||||||
|
* @param result New result for disallowing the player
|
||||||
|
* @param message Kick message to display to the user
|
||||||
|
*/
|
||||||
|
public void disallow(final Result result, final String message) {
|
||||||
|
this.result = result;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player name.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player IP address.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public InetAddress getAddress() {
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic kick reasons for communicating to plugins
|
||||||
|
*/
|
||||||
|
public enum Result {
|
||||||
|
/**
|
||||||
|
* The player is allowed to log in
|
||||||
|
*/
|
||||||
|
ALLOWED,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player is not allowed to log in, due to the server being full
|
||||||
|
*/
|
||||||
|
KICK_FULL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player is not allowed to log in, due to them being banned
|
||||||
|
*/
|
||||||
|
KICK_BANNED,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player is not allowed to log in, due to them not being on the white list
|
||||||
|
*/
|
||||||
|
KICK_WHITELIST,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player is not allowed to log in, for reasons undefined
|
||||||
|
*/
|
||||||
|
KICK_OTHER
|
||||||
|
}
|
||||||
|
}
|
@ -75,10 +75,12 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
|
|
||||||
Pattern[] patterns = instance.getPluginFileFilters();
|
Pattern[] patterns = instance.getPluginFileFilters();
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
for (Pattern pattern : patterns) {
|
for (Pattern pattern : patterns) {
|
||||||
fileAssociations.put(pattern, instance);
|
fileAssociations.put(pattern, instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the plugins contained within the specified directory
|
* Loads the plugins contained within the specified directory
|
||||||
@ -145,7 +147,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
* @throws InvalidPluginException Thrown when the specified file is not a valid plugin
|
* @throws InvalidPluginException Thrown when the specified file is not a valid plugin
|
||||||
* @throws InvalidDescriptionException Thrown when the specified file contains an invalid description
|
* @throws InvalidDescriptionException Thrown when the specified file contains an invalid description
|
||||||
*/
|
*/
|
||||||
public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
|
public synchronized Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
|
||||||
Set<Pattern> filters = fileAssociations.keySet();
|
Set<Pattern> filters = fileAssociations.keySet();
|
||||||
Plugin result = null;
|
Plugin result = null;
|
||||||
|
|
||||||
@ -175,11 +177,11 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
* @param name Name of the plugin to check
|
* @param name Name of the plugin to check
|
||||||
* @return Plugin if it exists, otherwise null
|
* @return Plugin if it exists, otherwise null
|
||||||
*/
|
*/
|
||||||
public Plugin getPlugin(String name) {
|
public synchronized Plugin getPlugin(String name) {
|
||||||
return lookupNames.get(name);
|
return lookupNames.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin[] getPlugins() {
|
public synchronized Plugin[] getPlugins() {
|
||||||
return plugins.toArray(new Plugin[0]);
|
return plugins.toArray(new Plugin[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +248,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||||||
* @param type Type of player related event to call
|
* @param type Type of player related event to call
|
||||||
* @param event Event details
|
* @param event Event details
|
||||||
*/
|
*/
|
||||||
public void callEvent(Event event) {
|
public synchronized void callEvent(Event event) {
|
||||||
SortedSet<RegisteredListener> eventListeners = listeners.get(event.getType());
|
SortedSet<RegisteredListener> eventListeners = listeners.get(event.getType());
|
||||||
|
|
||||||
if (eventListeners != null) {
|
if (eventListeners != null) {
|
||||||
|
@ -258,6 +258,12 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||||||
((PlayerListener) listener).onPlayerLogin((PlayerLoginEvent) event);
|
((PlayerListener) listener).onPlayerLogin((PlayerLoginEvent) event);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
case PLAYER_PRELOGIN:
|
||||||
|
return new EventExecutor() {
|
||||||
|
public void execute(Listener listener, Event event) {
|
||||||
|
((PlayerListener) listener).onPlayerPreLogin((PlayerPreLoginEvent) event);
|
||||||
|
}
|
||||||
|
};
|
||||||
case PLAYER_EGG_THROW:
|
case PLAYER_EGG_THROW:
|
||||||
return new EventExecutor() {
|
return new EventExecutor() {
|
||||||
public void execute(Listener listener, Event event) {
|
public void execute(Listener listener, Event event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user