#1169 Create UnregisterEvent

This commit is contained in:
ljacqu
2017-04-29 15:22:27 +02:00
parent d65556d893
commit b652d89088
5 changed files with 162 additions and 2 deletions
@@ -0,0 +1,32 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
/**
* Event fired when a player has been unregistered.
*/
public abstract class AbstractUnregisterEvent extends CustomEvent {
private final Player player;
/**
* Constructor for a player that has unregistered himself.
*
* @param player the player
*/
public AbstractUnregisterEvent(Player player, boolean isAsync) {
super(isAsync);
this.player = player;
}
/**
* Returns the player that has been unregistered.
* <p>
* This may be {@code null}! Please refer to the implementations of this class for details.
*
* @return the unregistered player, or null
*/
public Player getPlayer() {
return player;
}
}
@@ -0,0 +1,67 @@
package fr.xephi.authme.events;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
/**
* Event fired after a player has been unregistered from an external source (by an admin or via the API).
* <p>
* Note that only the {@code playerName} is guaranteed to be not {@code null} in any case.
* <p>
* The {@code player} may be null if a name is supplied which has never been online on the server &ndash;
* due to migrations, data removal, etc. it is possible that a user exists in the database for which the
* server knows no {@link Player} object.
* <p>
* If a player is unregistered via an API call, the {@code initiator} is null as the action has not been
* started by any {@link CommandSender}. Otherwise, the {@code initiator} is the user who performed the
* command to unregister the player name.
*/
public class UnregisterByAdminEvent extends AbstractUnregisterEvent {
private static final HandlerList handlers = new HandlerList();
private final String playerName;
private final CommandSender initiator;
/**
* Constructor.
*
* @param player the player (may be null - see class JavaDoc)
* @param playerName the name of the player that was unregistered
* @param isAsync whether or not the event is async
* @param initiator the initiator of the unregister process (may be null - see class JavaDoc)
*/
public UnregisterByAdminEvent(Player player, String playerName, boolean isAsync, CommandSender initiator) {
super(player, isAsync);
this.playerName = playerName;
this.initiator = initiator;
}
/**
* @return the name of the player that was unregistered
*/
public String getPlayerName() {
return playerName;
}
/**
* @return the user who requested to unregister the name, or null if not applicable
*/
public CommandSender getInitiator() {
return initiator;
}
/**
* Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link org.bukkit.event.Event}.
*
* @return The list of handlers
*/
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}
@@ -0,0 +1,35 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
/**
* Event fired after a player has unregistered himself.
*/
public class UnregisterByPlayerEvent extends AbstractUnregisterEvent {
private static final HandlerList handlers = new HandlerList();
/**
* Constructor.
*
* @param player the player (never null)
*/
public UnregisterByPlayerEvent(Player player, boolean isAsync) {
super(player, isAsync);
}
/**
* Return the list of handlers, equivalent to {@link #getHandlers()} and required by {@link org.bukkit.event.Event}.
*
* @return The list of handlers
*/
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}