#1169 Create UnregisterEvent
This commit is contained in:
@@ -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 –
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.data.limbo.LimboService;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.UnregisterByAdminEvent;
|
||||
import fr.xephi.authme.events.UnregisterByPlayerEvent;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
||||
import fr.xephi.authme.permission.AuthGroupType;
|
||||
@@ -66,6 +68,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
if (dataSource.removeAuth(name)) {
|
||||
performUnregister(name, player);
|
||||
ConsoleLogger.info(name + " unregistered himself");
|
||||
bukkitService.createAndCallEvent(isAsync -> new UnregisterByPlayerEvent(player, isAsync));
|
||||
} else {
|
||||
service.send(player, MessageKey.ERROR);
|
||||
}
|
||||
@@ -86,6 +89,8 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
||||
public void adminUnregister(CommandSender initiator, String name, Player player) {
|
||||
if (dataSource.removeAuth(name)) {
|
||||
performUnregister(name, player);
|
||||
bukkitService.createAndCallEvent(isAsync -> new UnregisterByAdminEvent(player, name, isAsync, initiator));
|
||||
|
||||
if (initiator == null) {
|
||||
ConsoleLogger.info(name + " was unregistered");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user