Sync repo files to b22

This commit is contained in:
HaHaWTH
2023-09-20 02:15:22 +08:00
parent ed320196fe
commit 3f6a7ce48f
478 changed files with 94676 additions and 0 deletions
@@ -0,0 +1,78 @@
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 to The teleport destination
*/
public AbstractTeleportEvent(boolean isAsync, Player player, Location to) {
super(isAsync);
this.player = player;
this.from = player.getLocation();
this.to = 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;
}
}
@@ -0,0 +1,33 @@
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
* @param isAsync if the event is called asynchronously
*/
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,70 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* This event is called when a player uses the login command,
* it's fired even when a user does a /login with invalid password.
* {@link #setCanLogin(boolean) event.setCanLogin(false)} prevents the player from logging in.
*/
public class AuthMeAsyncPreLoginEvent extends CustomEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean canLogin = true;
/**
* Constructor.
*
* @param player The player
* @param isAsync True if the event is async, false otherwise
*/
public AuthMeAsyncPreLoginEvent(Player player, boolean isAsync) {
super(isAsync);
this.player = player;
}
/**
* Return the player concerned by this event.
*
* @return The player who executed a valid {@code /login} command
*/
public Player getPlayer() {
return player;
}
/**
* Return whether the player is allowed to log in.
*
* @return True if the player can log in, false otherwise
*/
public boolean canLogin() {
return canLogin;
}
/**
* Define whether or not the player may log in.
*
* @param canLogin True to allow the player to log in; false to prevent him
*/
public void setCanLogin(boolean canLogin) {
this.canLogin = canLogin;
}
/**
* 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;
}
}
@@ -0,0 +1,70 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* This event is called when a player uses the register command,
* it's fired even when a user does a /register with invalid arguments.
* {@link #setCanRegister(boolean) event.setCanRegister(false)} prevents the player from registering.
*/
public class AuthMeAsyncPreRegisterEvent extends CustomEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean canRegister = true;
/**
* Constructor.
*
* @param player The player
* @param isAsync True if the event is async, false otherwise
*/
public AuthMeAsyncPreRegisterEvent(Player player, boolean isAsync) {
super(isAsync);
this.player = player;
}
/**
* Return the player concerned by this event.
*
* @return The player who executed a valid {@code /login} command
*/
public Player getPlayer() {
return player;
}
/**
* Return whether the player is allowed to register.
*
* @return True if the player can log in, false otherwise
*/
public boolean canRegister() {
return canRegister;
}
/**
* Define whether or not the player may register.
*
* @param canRegister True to allow the player to log in; false to prevent him
*/
public void setCanRegister(boolean canRegister) {
this.canRegister = canRegister;
}
/**
* 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;
}
}
@@ -0,0 +1,39 @@
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 fired before AuthMe teleports a player for general purposes.
*/
public class AuthMeTeleportEvent extends AbstractTeleportEvent {
private static final HandlerList handlers = new HandlerList();
/**
* Constructor.
*
* @param player The player
* @param to The teleport destination
*/
public AuthMeTeleportEvent(Player player, Location to) {
super(false, player, to);
}
/**
* 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;
}
}
@@ -0,0 +1,27 @@
package fr.xephi.authme.events;
import org.bukkit.event.Event;
/**
* The parent of all AuthMe events.
*/
public abstract class CustomEvent extends Event {
/**
* Constructor.
*/
public CustomEvent() {
super(false);
}
/**
* Constructor, specifying whether the event is asynchronous or not.
*
* @param isAsync {@code true} to fire the event asynchronously, false otherwise
* @see Event#Event(boolean)
*/
public CustomEvent(boolean isAsync) {
super(isAsync);
}
}
@@ -0,0 +1,85 @@
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 is called when a player adds or changes his email address.
*/
public class EmailChangedEvent extends CustomEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private final String oldEmail;
private final String newEmail;
private boolean isCancelled;
/**
* Constructor
*
* @param player The player that changed email
* @param oldEmail Old email player had on file. Can be null when user adds an email
* @param newEmail New email that player tries to set. In case of adding email, this will contain
* the email is trying to set.
* @param isAsync should this event be called asynchronously?
*/
public EmailChangedEvent(Player player, String oldEmail, String newEmail, boolean isAsync) {
super(isAsync);
this.player = player;
this.oldEmail = oldEmail;
this.newEmail = newEmail;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
/**
* Gets the player who changes the email
*
* @return The player who changed the email
*/
public Player getPlayer() {
return player;
}
/**
* Gets the old email in case user tries to change existing email.
*
* @return old email stored on file. Can be null when user never had an email and adds a new one.
*/
public String getOldEmail() {
return this.oldEmail;
}
/**
* Gets the new email.
*
* @return the email user is trying to set. If user adds email and never had one before,
* this is where such email can be found.
*/
public String getNewEmail() {
return this.newEmail;
}
@Override
public void setCancelled(boolean cancelled) {
this.isCancelled = cancelled;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
/**
* 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;
}
}
@@ -0,0 +1,46 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Event fired when a player enters a wrong password.
*/
public class FailedLoginEvent extends CustomEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
/**
* Constructor.
*
* @param player The player
* @param isAsync if the event is called asynchronously
*/
public FailedLoginEvent(Player player, boolean isAsync) {
super(isAsync);
this.player = player;
}
/**
* @return The player entering a wrong password
*/
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;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}
@@ -0,0 +1,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;
/**
* 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 AbstractTeleportEvent {
private static final HandlerList handlers = new HandlerList();
/**
* Constructor.
*
* @param player The player
* @param to The teleport destination
*/
public FirstSpawnTeleportEvent(Player player, Location to) {
super(false, player, to);
}
/**
* 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;
}
}
@@ -0,0 +1,58 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Event fired when a player has successfully logged in or registered.
*/
public class LoginEvent extends CustomEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
/**
* Constructor.
*
* @param player The player
*/
public LoginEvent(Player player) {
this.player = player;
}
/**
* Return the player that has successfully logged in or registered.
*
* @return The player
*/
public Player getPlayer() {
return player;
}
/**
* Ensures compatibility with plugins like GuiRules.
*
* @return true
* @deprecated this will always return true because this event is only called if it was successful
*/
@Deprecated
public boolean isLogin() {
return true;
}
/**
* 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;
}
}
@@ -0,0 +1,49 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* 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 CustomEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
/**
* Constructor.
*
* @param player The player
*/
public LogoutEvent(Player player) {
this.player = player;
}
/**
* Return the player who logged out.
*
* @return The player
*/
public Player getPlayer() {
return this.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;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}
@@ -0,0 +1,57 @@
package fr.xephi.authme.events;
import fr.xephi.authme.security.crypts.EncryptionMethod;
import org.bukkit.event.HandlerList;
/**
* 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.
*/
public class PasswordEncryptionEvent extends CustomEvent {
private static final HandlerList handlers = new HandlerList();
private EncryptionMethod method;
/**
* Constructor.
*
* @param method The method used to encrypt the password
*/
public PasswordEncryptionEvent(EncryptionMethod method) {
super(false);
this.method = method;
}
/**
* 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;
}
/**
* 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;
}
}
@@ -0,0 +1,85 @@
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 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 implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final ItemStack[] storedInventory;
private final ItemStack[] storedArmor;
private final Player player;
private boolean isCancelled;
/**
* Constructor.
*
* @param player The player
* @param isAsync True if the event is async, false otherwise
*/
public ProtectInventoryEvent(Player player, boolean isAsync) {
super(isAsync);
this.player = player;
this.storedInventory = player.getInventory().getContents();
this.storedArmor = player.getInventory().getArmorContents();
}
/**
* Return the inventory of the player.
*
* @return The player's inventory
*/
public ItemStack[] getStoredInventory() {
return storedInventory;
}
/**
* Return the armor of the player.
*
* @return The player's armor
*/
public ItemStack[] getStoredArmor() {
return storedArmor;
}
/**
* Return the player whose inventory will be hidden.
*
* @return The player associated with this event
*/
public Player getPlayer() {
return player;
}
@Override
public void setCancelled(boolean isCancelled) {
this.isCancelled = isCancelled;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
/**
* 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;
}
}
@@ -0,0 +1,47 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Event fired when a player has successfully registered.
*/
public class RegisterEvent extends CustomEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
/**
* Constructor.
*
* @param player The player
*/
public RegisterEvent(Player player) {
this.player = player;
}
/**
* Return the player that has successfully logged in or registered.
*
* @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;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}
@@ -0,0 +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 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 implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean isCancelled;
/**
* Constructor.
*
* @param player The player
*/
public RestoreInventoryEvent(Player player) {
this.player = player;
}
/**
* Return the player whose inventory will be restored.
*
* @return Player
*/
public Player getPlayer() {
return player;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean isCancelled) {
this.isCancelled = isCancelled;
}
/**
* 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;
}
}
@@ -0,0 +1,51 @@
package fr.xephi.authme.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* Event fired before a session is restored.
*/
public class RestoreSessionEvent extends CustomEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Player player;
private boolean isCancelled;
public RestoreSessionEvent(Player player, boolean isAsync) {
super(isAsync);
this.player = player;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean isCancelled) {
this.isCancelled = isCancelled;
}
/**
* @return the player for which the session will be enabled
*/
public Player getPlayer() {
return player;
}
/**
* 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,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 upon joining or logging in.
*/
public class SpawnTeleportEvent extends AbstractTeleportEvent {
private static final HandlerList handlers = new HandlerList();
private final boolean isAuthenticated;
/**
* Constructor.
*
* @param player The player
* @param to The teleport destination
* @param isAuthenticated Whether or not the player is logged in
*/
public SpawnTeleportEvent(Player player, Location to, boolean isAuthenticated) {
super(false, player, to);
this.isAuthenticated = isAuthenticated;
}
/**
* Return whether or not the player is authenticated.
*
* @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;
}
}
@@ -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,36 @@
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)
* @param isAsync if the event is called asynchronously
*/
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;
}
}