diff --git a/src/main/java/fr/xephi/authme/events/AbstractTeleportEvent.java b/src/main/java/fr/xephi/authme/events/AbstractTeleportEvent.java new file mode 100644 index 000000000..57a456b6c --- /dev/null +++ b/src/main/java/fr/xephi/authme/events/AbstractTeleportEvent.java @@ -0,0 +1,90 @@ +package fr.xephi.authme.events; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; + +/** + * Common supertype for all AuthMe teleport events. + */ +public abstract class AbstractTeleportEvent extends CustomEvent implements Cancellable { + + private final Player player; + private final Location from; + private Location to; + private boolean isCancelled; + + /** + * Constructor. + * + * @param isAsync Whether to fire the event asynchronously or not + * @param player The player + * @param from The location the player is being teleported away from + * @param to The teleport destination + */ + public AbstractTeleportEvent(boolean isAsync, Player player, Location from, Location to) { + super(isAsync); + this.player = player; + this.from = from; + this.to = to; + } + + /** + * Constructor, using the player's current location as "from" location. + * + * @param isAsync Whether to fire the event asynchronously or not + * @param player The player + * @param to The teleport destination + */ + public AbstractTeleportEvent(boolean isAsync, Player player, Location to) { + this(isAsync, player, player.getLocation(), to); + } + + /** + * Return the player planned to be teleported. + * + * @return The player + */ + public Player getPlayer() { + return player; + } + + /** + * Return the location the player is being teleported away from. + * + * @return The location prior to the teleport + */ + public Location getFrom() { + return from; + } + + /** + * Set the destination of the teleport. + * + * @param to The location to teleport the player to + */ + public void setTo(Location to) { + this.to = to; + } + + /** + * Return the destination the player is being teleported to. + * + * @return The teleport destination + */ + public Location getTo() { + return to; + } + + @Override + public void setCancelled(boolean isCancelled) { + this.isCancelled = isCancelled; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + +} diff --git a/src/main/java/fr/xephi/authme/events/AuthMeAsyncPreLoginEvent.java b/src/main/java/fr/xephi/authme/events/AuthMeAsyncPreLoginEvent.java index bd1cb1c0c..963593fd8 100644 --- a/src/main/java/fr/xephi/authme/events/AuthMeAsyncPreLoginEvent.java +++ b/src/main/java/fr/xephi/authme/events/AuthMeAsyncPreLoginEvent.java @@ -5,21 +5,19 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** - * This event is call when a player try to /login - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * This event is called when a player uses the /login command with correct credentials. + * {@link #setCanLogin(boolean) {@code event.setCanLogin(false)}} prevents the player from logging in. */ -public class AuthMeAsyncPreLoginEvent extends Event { +public class AuthMeAsyncPreLoginEvent extends CustomEvent { private static final HandlerList handlers = new HandlerList(); private final Player player; private boolean canLogin = true; /** - * Constructor for AuthMeAsyncPreLoginEvent. + * Constructor. * - * @param player Player + * @param player The player */ public AuthMeAsyncPreLoginEvent(Player player) { super(true); @@ -27,37 +25,41 @@ public class AuthMeAsyncPreLoginEvent extends Event { } /** - * Method getPlayer. + * Return the player concerned by this event. * - * @return Player + * @return The player who executed a valid {@code /login} command */ public Player getPlayer() { return player; } /** - * Method canLogin. + * Return whether the player is allowed to log in. * - * @return boolean + * @return True if the player can log in, false otherwise */ public boolean canLogin() { return canLogin; } /** - * Method setCanLogin. + * Define whether or not the player may log in. * - * @param canLogin boolean + * @param canLogin True to allow the player to log in; false to prevent him */ public void setCanLogin(boolean canLogin) { this.canLogin = canLogin; } /** - * Method getHandlers. + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. * - * @return HandlerList + * @return The list of handlers */ + public static HandlerList getHandlerList() { + return handlers; + } + @Override public HandlerList getHandlers() { return handlers; diff --git a/src/main/java/fr/xephi/authme/events/AuthMeTeleportEvent.java b/src/main/java/fr/xephi/authme/events/AuthMeTeleportEvent.java index 305efa466..ed8a08d35 100644 --- a/src/main/java/fr/xephi/authme/events/AuthMeTeleportEvent.java +++ b/src/main/java/fr/xephi/authme/events/AuthMeTeleportEvent.java @@ -2,65 +2,38 @@ package fr.xephi.authme.events; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; /** - * This event is call when AuthMe try to teleport a player - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * This event is fired before AuthMe teleports a player for general purposes. */ -public class AuthMeTeleportEvent extends CustomEvent { +public class AuthMeTeleportEvent extends AbstractTeleportEvent { - private final Player player; - private Location to; - private final Location from; + private static final HandlerList handlers = new HandlerList(); /** - * Constructor for AuthMeTeleportEvent. + * Constructor. * - * @param player Player - * @param to Location + * @param player The player + * @param to The teleport destination */ public AuthMeTeleportEvent(Player player, Location to) { - this.player = player; - this.from = player.getLocation(); - this.to = to; + super(false, player, to); } /** - * Method getPlayer. + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. * - * @return Player + * @return The list of handlers */ - public Player getPlayer() { - return player; + public static HandlerList getHandlerList() { + return handlers; } - /** - * Method getTo. - * - * @return Location - */ - public Location getTo() { - return to; - } - - /** - * Method setTo. - * - * @param to Location - */ - public void setTo(Location to) { - this.to = to; - } - - /** - * Method getFrom. - * - * @return Location - */ - public Location getFrom() { - return from; + @Override + public HandlerList getHandlers() { + return handlers; } } diff --git a/src/main/java/fr/xephi/authme/events/CustomEvent.java b/src/main/java/fr/xephi/authme/events/CustomEvent.java index 0dfd00050..f647b6d59 100644 --- a/src/main/java/fr/xephi/authme/events/CustomEvent.java +++ b/src/main/java/fr/xephi/authme/events/CustomEvent.java @@ -1,67 +1,27 @@ package fr.xephi.authme.events; -import org.bukkit.event.Cancellable; import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; /** - * @author Xephi59 - * @version $Revision: 1.0 $ + * The parent of all AuthMe events. */ -public class CustomEvent extends Event implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - private boolean isCancelled; +public abstract class CustomEvent extends Event { + /** + * Constructor. + */ public CustomEvent() { super(false); } /** - * Constructor for CustomEvent. + * Constructor, specifying whether the event is asynchronous or not. * - * @param b boolean + * @param isAsync {@code true} to fire the event asynchronously, false otherwise + * @see Event#Event(boolean) */ - public CustomEvent(boolean b) { - super(b); - } - - /** - * Method getHandlerList. - * - * @return HandlerList - */ - public static HandlerList getHandlerList() { - return handlers; - } - - /** - * Method getHandlers. - * - * @return HandlerList - */ - public HandlerList getHandlers() { - return handlers; - } - - /** - * Method isCancelled. - * - * @return boolean * @see org.bukkit.event.Cancellable#isCancelled() - */ - public boolean isCancelled() { - return this.isCancelled; - } - - /** - * Method setCancelled. - * - * @param cancelled boolean - * - * @see org.bukkit.event.Cancellable#setCancelled(boolean) - */ - public void setCancelled(boolean cancelled) { - this.isCancelled = cancelled; + public CustomEvent(boolean isAsync) { + super(isAsync); } } diff --git a/src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java b/src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java index 136a4d45d..28532b392 100644 --- a/src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java +++ b/src/main/java/fr/xephi/authme/events/FirstSpawnTeleportEvent.java @@ -2,67 +2,40 @@ package fr.xephi.authme.events; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; /** - * Called if a player is teleported to the authme first spawn - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * Event that is called if a player is teleported to the AuthMe first spawn, i.e. to the + * spawn location for players who have never played before. */ -public class FirstSpawnTeleportEvent extends CustomEvent { +public class FirstSpawnTeleportEvent extends AbstractTeleportEvent { - private final Player player; - private Location to; - private final Location from; + private static final HandlerList handlers = new HandlerList(); /** - * Constructor for FirstSpawnTeleportEvent. + * Constructor. * - * @param player Player - * @param from Location - * @param to Location + * @param player The player + * @param from The location the player is being teleported away from + * @param to The teleport destination */ public FirstSpawnTeleportEvent(Player player, Location from, Location to) { - super(true); - this.player = player; - this.from = from; - this.to = to; + super(true, player, from, to); } /** - * Method getPlayer. + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. * - * @return Player + * @return The list of handlers */ - public Player getPlayer() { - return player; + public static HandlerList getHandlerList() { + return handlers; } - /** - * Method getTo. - * - * @return Location - */ - public Location getTo() { - return to; - } - - /** - * Method setTo. - * - * @param to Location - */ - public void setTo(Location to) { - this.to = to; - } - - /** - * Method getFrom. - * - * @return Location - */ - public Location getFrom() { - return from; + @Override + public HandlerList getHandlers() { + return handlers; } } diff --git a/src/main/java/fr/xephi/authme/events/LoginEvent.java b/src/main/java/fr/xephi/authme/events/LoginEvent.java index c5149327e..6c2647fd8 100644 --- a/src/main/java/fr/xephi/authme/events/LoginEvent.java +++ b/src/main/java/fr/xephi/authme/events/LoginEvent.java @@ -5,80 +5,40 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** - * This event is called when a player login or register through AuthMe. The - * boolean 'isLogin' will be false if, and only if, login/register failed. - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * Event fired when a player has successfully logged in or registered. */ -public class LoginEvent extends Event { +public class LoginEvent extends CustomEvent { private static final HandlerList handlers = new HandlerList(); - private Player player; - private boolean isLogin; + private final Player player; /** - * Constructor for LoginEvent. + * Constructor. * - * @param player Player - * @param isLogin boolean + * @param player The player */ - public LoginEvent(Player player, boolean isLogin) { + public LoginEvent(Player player) { this.player = player; - this.isLogin = isLogin; } /** - * Method getHandlerList. + * Return the player that has successfully logged in or registered. * - * @return HandlerList + * @return The player + */ + public Player getPlayer() { + return player; + } + + /** + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. + * + * @return The list of handlers */ public static HandlerList getHandlerList() { return handlers; } - /** - * Method getPlayer. - * - * @return Player - */ - public Player getPlayer() { - return this.player; - } - - /** - * Method setPlayer. - * - * @param player Player - */ - public void setPlayer(Player player) { - this.player = player; - } - - /** - * Method isLogin. - * - * @return boolean - */ - public boolean isLogin() { - return isLogin; - } - - /** - * Method setLogin. - * - * @param isLogin boolean - */ - @Deprecated - public void setLogin(boolean isLogin) { - this.isLogin = isLogin; - } - - /** - * Method getHandlers. - * - * @return HandlerList - */ @Override public HandlerList getHandlers() { return handlers; diff --git a/src/main/java/fr/xephi/authme/events/LogoutEvent.java b/src/main/java/fr/xephi/authme/events/LogoutEvent.java index 09d2abd93..70fae0967 100644 --- a/src/main/java/fr/xephi/authme/events/LogoutEvent.java +++ b/src/main/java/fr/xephi/authme/events/LogoutEvent.java @@ -5,57 +5,42 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** - * This event is called when a player logout through AuthMe. - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * This event is called when a player logs out through AuthMe, i.e. only when the player + * has executed the {@code /logout} command. This event is not fired if a player simply + * leaves the server. */ -public class LogoutEvent extends Event { +public class LogoutEvent extends CustomEvent { private static final HandlerList handlers = new HandlerList(); - private Player player; + private final Player player; /** - * Constructor for LogoutEvent. + * Constructor. * - * @param player Player + * @param player The player */ public LogoutEvent(Player player) { this.player = player; } /** - * Method getHandlerList. + * Return the player who logged out. * - * @return HandlerList - */ - public static HandlerList getHandlerList() { - return handlers; - } - - /** - * Method getPlayer. - * - * @return Player + * @return The player */ public Player getPlayer() { return this.player; } /** - * Method setPlayer. + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. * - * @param player Player + * @return The list of handlers */ - public void setPlayer(Player player) { - this.player = player; + public static HandlerList getHandlerList() { + return handlers; } - /** - * Method getHandlers. - * - * @return HandlerList - */ @Override public HandlerList getHandlers() { return handlers; diff --git a/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java b/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java index 572d1c9a8..6e710ddce 100644 --- a/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java +++ b/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java @@ -5,24 +5,33 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; /** - * This event is called when we need to compare or hash password and allows + * This event is called when we need to compare or hash a password for a player and allows * third-party listeners to change the encryption method. This is typically * done with the {@link fr.xephi.authme.security.HashAlgorithm#CUSTOM} setting. - * - * @author Xephi59 */ -public class PasswordEncryptionEvent extends Event { +public class PasswordEncryptionEvent extends CustomEvent { private static final HandlerList handlers = new HandlerList(); private EncryptionMethod method; private String playerName; + /** + * Constructor. + * + * @param method The method used to encrypt the password + * @param playerName The name of the player + */ public PasswordEncryptionEvent(EncryptionMethod method, String playerName) { super(false); this.method = method; this.playerName = playerName; } + /** + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. + * + * @return The list of handlers + */ public static HandlerList getHandlerList() { return handlers; } @@ -32,14 +41,29 @@ public class PasswordEncryptionEvent extends Event { return handlers; } + /** + * Return the encryption method used to hash the password. + * + * @return The encryption method + */ public EncryptionMethod getMethod() { return method; } + /** + * Set the encryption method to hash the password with. + * + * @param method The encryption method to use + */ public void setMethod(EncryptionMethod method) { this.method = method; } + /** + * Return the name of the player the event has been fired for. + * + * @return The player name + */ public String getPlayerName() { return playerName; } diff --git a/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java b/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java index dea3a4609..2541c3ee8 100644 --- a/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java +++ b/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java @@ -1,98 +1,84 @@ package fr.xephi.authme.events; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; /** - * This event is call just after store inventory into cache and will empty the - * player inventory. - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * This event is called before the inventory data of a player is suppressed, + * i.e. the inventory of the player is not displayed until he has authenticated. */ -public class ProtectInventoryEvent extends CustomEvent { +public class ProtectInventoryEvent extends CustomEvent implements Cancellable { - private final ItemStack[] storedinventory; - private final ItemStack[] storedarmor; - private ItemStack[] emptyInventory = null; - private ItemStack[] emptyArmor = null; + private static final HandlerList handlers = new HandlerList(); + private final ItemStack[] storedInventory; + private final ItemStack[] storedArmor; private final Player player; + private boolean isCancelled; /** - * Constructor for ProtectInventoryEvent. + * Constructor. * - * @param player Player + * @param player The player */ public ProtectInventoryEvent(Player player) { super(true); this.player = player; - this.storedinventory = player.getInventory().getContents(); - this.storedarmor = player.getInventory().getArmorContents(); - this.emptyInventory = new ItemStack[36]; - this.emptyArmor = new ItemStack[4]; + this.storedInventory = player.getInventory().getContents(); + this.storedArmor = player.getInventory().getArmorContents(); } /** - * Method getStoredInventory. + * Return the inventory of the player. * - * @return ItemStack[] + * @return The player's inventory */ public ItemStack[] getStoredInventory() { - return this.storedinventory; + return storedInventory; } /** - * Method getStoredArmor. + * Return the armor of the player. * - * @return ItemStack[] + * @return The player's armor */ public ItemStack[] getStoredArmor() { - return this.storedarmor; + return storedArmor; } /** - * Method getPlayer. + * Return the player whose inventory will be hidden. * - * @return Player + * @return The player associated with this event */ public Player getPlayer() { - return this.player; + return player; + } + + @Override + public void setCancelled(boolean isCancelled) { + this.isCancelled = isCancelled; + } + + @Override + public boolean isCancelled() { + return isCancelled; } /** - * Method setNewInventory. + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. * - * @param emptyInventory ItemStack[] + * @return The list of handlers */ - public void setNewInventory(ItemStack[] emptyInventory) { - this.emptyInventory = emptyInventory; + public static HandlerList getHandlerList() { + return handlers; } - /** - * Method getEmptyInventory. - * - * @return ItemStack[] - */ - public ItemStack[] getEmptyInventory() { - return this.emptyInventory; - } - - /** - * Method setNewArmor. - * - * @param emptyArmor ItemStack[] - */ - public void setNewArmor(ItemStack[] emptyArmor) { - this.emptyArmor = emptyArmor; - } - - /** - * Method getEmptyArmor. - * - * @return ItemStack[] - */ - public ItemStack[] getEmptyArmor() { - return this.emptyArmor; + @Override + public HandlerList getHandlers() { + return handlers; } } diff --git a/src/main/java/fr/xephi/authme/events/RegisterTeleportEvent.java b/src/main/java/fr/xephi/authme/events/RegisterTeleportEvent.java deleted file mode 100644 index a4fef0b6d..000000000 --- a/src/main/java/fr/xephi/authme/events/RegisterTeleportEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -package fr.xephi.authme.events; - -import org.bukkit.Location; -import org.bukkit.entity.Player; - -/** - * This event is call if, and only if, a player is teleported just after a - * register. - * - * @author Xephi59 - * @version $Revision: 1.0 $ - */ -public class RegisterTeleportEvent extends CustomEvent { - - private final Player player; - private Location to; - private final Location from; - - /** - * Constructor for RegisterTeleportEvent. - * - * @param player Player - * @param to Location - */ - public RegisterTeleportEvent(Player player, Location to) { - this.player = player; - this.from = player.getLocation(); - this.to = to; - } - - /** - * Method getPlayer. - * - * @return Player - */ - public Player getPlayer() { - return player; - } - - /** - * Method getTo. - * - * @return Location - */ - public Location getTo() { - return to; - } - - /** - * Method setTo. - * - * @param to Location - */ - public void setTo(Location to) { - this.to = to; - } - - /** - * Method getFrom. - * - * @return Location - */ - public Location getFrom() { - return from; - } - -} diff --git a/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java b/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java deleted file mode 100644 index 75c486367..000000000 --- a/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -package fr.xephi.authme.events; - -import org.bukkit.entity.Player; - -/** - * This event is call when a creative inventory is reseted. - * - * @author Xephi59 - * @version $Revision: 1.0 $ - */ -public class ResetInventoryEvent extends CustomEvent { - - private Player player; - - /** - * Constructor for ResetInventoryEvent. - * - * @param player Player - */ - public ResetInventoryEvent(Player player) { - super(true); - this.player = player; - } - - /** - * Method getPlayer. - * - * @return Player - */ - public Player getPlayer() { - return this.player; - } - - /** - * Method setPlayer. - * - * @param player Player - */ - public void setPlayer(Player player) { - this.player = player; - } - -} diff --git a/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java b/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java index e34d7c972..eb9bf71d8 100644 --- a/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java +++ b/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java @@ -1,52 +1,60 @@ package fr.xephi.authme.events; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; /** - * This event restore the inventory. - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * This event is fired when the inventory of a player is restored + * (the inventory data is no longer hidden from the user). */ -public class RestoreInventoryEvent extends CustomEvent { +public class RestoreInventoryEvent extends CustomEvent implements Cancellable { - private Player player; + private static final HandlerList handlers = new HandlerList(); + private final Player player; + private boolean isCancelled; /** - * Constructor for RestoreInventoryEvent. + * Constructor. * - * @param player Player + * @param player The player */ public RestoreInventoryEvent(Player player) { this.player = player; } /** - * Constructor for RestoreInventoryEvent. - * - * @param player Player - * @param async boolean - */ - public RestoreInventoryEvent(Player player, boolean async) { - super(async); - this.player = player; - } - - /** - * Method getPlayer. + * Return the player whose inventory will be restored. * * @return Player */ public Player getPlayer() { - return this.player; + return player; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean isCancelled) { + this.isCancelled = isCancelled; } /** - * Method setPlayer. + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. * - * @param player Player + * @return The list of handlers */ - public void setPlayer(Player player) { - this.player = player; + public static HandlerList getHandlerList() { + return handlers; } + + @Override + public HandlerList getHandlers() { + return handlers; + } + } diff --git a/src/main/java/fr/xephi/authme/events/SpawnTeleportEvent.java b/src/main/java/fr/xephi/authme/events/SpawnTeleportEvent.java index c971f572b..3a429bc3d 100644 --- a/src/main/java/fr/xephi/authme/events/SpawnTeleportEvent.java +++ b/src/main/java/fr/xephi/authme/events/SpawnTeleportEvent.java @@ -2,79 +2,51 @@ package fr.xephi.authme.events; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; /** - * Called if a player is teleported to a specific spawn - * - * @author Xephi59 - * @version $Revision: 1.0 $ + * Called if a player is teleported to a specific spawn upon joining or logging in. */ -public class SpawnTeleportEvent extends CustomEvent { +public class SpawnTeleportEvent extends AbstractTeleportEvent { - private final Player player; - private Location to; - private final Location from; + private static final HandlerList handlers = new HandlerList(); private final boolean isAuthenticated; /** - * Constructor for SpawnTeleportEvent. + * Constructor. * - * @param player Player - * @param from Location - * @param to Location - * @param isAuthenticated boolean + * @param player The player + * @param from The location the player is being teleported away from + * @param to The teleport destination + * @param isAuthenticated Whether or not the player is logged in */ - public SpawnTeleportEvent(Player player, Location from, Location to, - boolean isAuthenticated) { - this.player = player; - this.from = from; - this.to = to; + public SpawnTeleportEvent(Player player, Location from, Location to, boolean isAuthenticated) { + super(false, player, from, to); this.isAuthenticated = isAuthenticated; } /** - * Method getPlayer. + * Return whether or not the player is authenticated. * - * @return Player - */ - public Player getPlayer() { - return player; - } - - /** - * Method getTo. - * - * @return Location - */ - public Location getTo() { - return to; - } - - /** - * Method setTo. - * - * @param to Location - */ - public void setTo(Location to) { - this.to = to; - } - - /** - * Method getFrom. - * - * @return Location - */ - public Location getFrom() { - return from; - } - - /** - * Method isAuthenticated. - * - * @return boolean + * @return true if the player is logged in, false otherwise */ public boolean isAuthenticated() { return isAuthenticated; } + /** + * Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link Event}. + * + * @return The list of handlers + */ + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + } diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index d1e4fb79b..21bb427bb 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -28,8 +28,7 @@ import fr.xephi.authme.util.Utils.GroupType; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; -/** - */ + public class ProcessSyncPlayerLogin implements Runnable { private final LimboPlayer limbo; @@ -63,24 +62,19 @@ public class ProcessSyncPlayerLogin implements Runnable { this.settings = settings; } - /** - * Method getLimbo. - * - * @return LimboPlayer - */ public LimboPlayer getLimbo() { return limbo; } - protected void restoreOpState() { + private void restoreOpState() { player.setOp(limbo.getOperator()); } - protected void packQuitLocation() { + private void packQuitLocation() { Utils.packCoords(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), player); } - protected void teleportBackFromSpawn() { + private void teleportBackFromSpawn() { AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limbo.getLoc()); pm.callEvent(tpEvent); if (!tpEvent.isCancelled() && tpEvent.getTo() != null) { @@ -88,7 +82,7 @@ public class ProcessSyncPlayerLogin implements Runnable { } } - protected void teleportToSpawn() { + private void teleportToSpawn() { Location spawnL = plugin.getSpawnLocation(player); SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true); pm.callEvent(tpEvent); @@ -97,14 +91,14 @@ public class ProcessSyncPlayerLogin implements Runnable { } } - protected void restoreSpeedEffects() { + private void restoreSpeedEffects() { if (Settings.isRemoveSpeedEnabled) { player.setWalkSpeed(0.2F); player.setFlySpeed(0.1F); } } - protected void restoreInventory() { + private void restoreInventory() { RestoreInventoryEvent event = new RestoreInventoryEvent(player); pm.callEvent(event); if (!event.isCancelled() && plugin.inventoryProtector != null) { @@ -112,7 +106,7 @@ public class ProcessSyncPlayerLogin implements Runnable { } } - protected void forceCommands() { + private void forceCommands() { for (String command : Settings.forceCommands) { player.performCommand(command.replace("%p", player.getName())); } @@ -121,7 +115,7 @@ public class ProcessSyncPlayerLogin implements Runnable { } } - protected void sendBungeeMessage() { + private void sendBungeeMessage() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Forward"); out.writeUTF("ALL"); @@ -130,11 +124,6 @@ public class ProcessSyncPlayerLogin implements Runnable { player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); } - /** - * Method run. - * - * @see java.lang.Runnable#run() - */ @Override public void run() { // Limbo contains the State of the Player before /login @@ -175,8 +164,9 @@ public class ProcessSyncPlayerLogin implements Runnable { if (jm != null) { if (!jm.isEmpty()) { for (Player p : Utils.getOnlinePlayers()) { - if (p.isOnline()) + if (p.isOnline()) { p.sendMessage(jm); + } } } AuthMePlayerListener.joinMessage.remove(name); @@ -188,12 +178,13 @@ public class ProcessSyncPlayerLogin implements Runnable { } // The Login event now fires (as intended) after everything is processed - Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); + Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player)); player.saveData(); - if (Settings.bungee) + if (Settings.bungee) { sendBungeeMessage(); + } // Login is finish, display welcome message if we use email registration - if (Settings.useWelcomeMessage && Settings.emailRegistration) + if (Settings.useWelcomeMessage && Settings.emailRegistration) { if (Settings.broadcastWelcomeMessage) { for (String s : settings.getWelcomeMessage()) { Bukkit.getServer().broadcastMessage(plugin.replaceAllInfo(s, player)); @@ -203,6 +194,7 @@ public class ProcessSyncPlayerLogin implements Runnable { player.sendMessage(plugin.replaceAllInfo(s, player)); } } + } // Login is now finished; we can force all commands forceCommands(); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index 5c787606c..60f5bc187 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -120,7 +120,7 @@ public class ProcessSyncPasswordRegister implements Runnable { } // The LoginEvent now fires (as intended) after everything is processed - plugin.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); + plugin.getServer().getPluginManager().callEvent(new LoginEvent(player)); player.saveData(); if (!Settings.noConsoleSpam) {