mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-19 07:07:55 +01:00
Don't purge users if unable to load permission data
This commit is contained in:
parent
ba4ed7bdd9
commit
6e16abc34e
@ -1,11 +1,13 @@
|
|||||||
package fr.xephi.authme.listener;
|
package fr.xephi.authme.listener;
|
||||||
|
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.QuickCommandsProtectionManager;
|
import fr.xephi.authme.data.QuickCommandsProtectionManager;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.message.Messages;
|
import fr.xephi.authme.message.Messages;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
|
import fr.xephi.authme.permission.handlers.PermissionLoadUserException;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
import fr.xephi.authme.service.AntiBotService;
|
import fr.xephi.authme.service.AntiBotService;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
@ -260,9 +262,13 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
// Keep pre-UUID compatibility
|
// Keep pre-UUID compatibility
|
||||||
try {
|
try {
|
||||||
permissionsManager.loadUserData(event.getUniqueId());
|
try {
|
||||||
} catch (NoSuchMethodError e) {
|
permissionsManager.loadUserData(event.getUniqueId());
|
||||||
permissionsManager.loadUserData(name);
|
} catch (NoSuchMethodError e) {
|
||||||
|
permissionsManager.loadUserData(name);
|
||||||
|
}
|
||||||
|
} catch (PermissionLoadUserException e) {
|
||||||
|
ConsoleLogger.logException("Unable to load the permission data of user " + name, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -8,6 +8,7 @@ import fr.xephi.authme.permission.handlers.BPermissionsHandler;
|
|||||||
import fr.xephi.authme.permission.handlers.LuckPermsHandler;
|
import fr.xephi.authme.permission.handlers.LuckPermsHandler;
|
||||||
import fr.xephi.authme.permission.handlers.PermissionHandler;
|
import fr.xephi.authme.permission.handlers.PermissionHandler;
|
||||||
import fr.xephi.authme.permission.handlers.PermissionHandlerException;
|
import fr.xephi.authme.permission.handlers.PermissionHandlerException;
|
||||||
|
import fr.xephi.authme.permission.handlers.PermissionLoadUserException;
|
||||||
import fr.xephi.authme.permission.handlers.PermissionsExHandler;
|
import fr.xephi.authme.permission.handlers.PermissionsExHandler;
|
||||||
import fr.xephi.authme.permission.handlers.VaultHandler;
|
import fr.xephi.authme.permission.handlers.VaultHandler;
|
||||||
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
|
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
|
||||||
@ -110,7 +111,9 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* Creates a permission handler for the provided permission systems if possible.
|
* Creates a permission handler for the provided permission systems if possible.
|
||||||
*
|
*
|
||||||
* @param type the permission systems type for which to create a corresponding permission handler
|
* @param type the permission systems type for which to create a corresponding permission handler
|
||||||
|
*
|
||||||
* @return the permission handler, or {@code null} if not possible
|
* @return the permission handler, or {@code null} if not possible
|
||||||
|
*
|
||||||
* @throws PermissionHandlerException during initialization of the permission handler
|
* @throws PermissionHandlerException during initialization of the permission handler
|
||||||
*/
|
*/
|
||||||
private PermissionHandler createPermissionHandler(PermissionsSystemType type) throws PermissionHandlerException {
|
private PermissionHandler createPermissionHandler(PermissionsSystemType type) throws PermissionHandlerException {
|
||||||
@ -228,8 +231,9 @@ public class PermissionsManager implements Reloadable {
|
|||||||
/**
|
/**
|
||||||
* Check if the given player has permission for the given permission node.
|
* Check if the given player has permission for the given permission node.
|
||||||
*
|
*
|
||||||
* @param joiningPlayer The player to check
|
* @param joiningPlayer The player to check
|
||||||
* @param permissionNode The permission node to verify
|
* @param permissionNode The permission node to verify
|
||||||
|
*
|
||||||
* @return true if the player has permission, false otherwise
|
* @return true if the player has permission, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(JoiningPlayer joiningPlayer, PermissionNode permissionNode) {
|
public boolean hasPermission(JoiningPlayer joiningPlayer, PermissionNode permissionNode) {
|
||||||
@ -262,7 +266,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* Check whether the offline player with the given name has permission for the given permission node.
|
* Check whether the offline player with the given name has permission for the given permission node.
|
||||||
* This method is used as a last resort when nothing besides the name is known.
|
* This method is used as a last resort when nothing besides the name is known.
|
||||||
*
|
*
|
||||||
* @param name The name of the player
|
* @param name The name of the player
|
||||||
* @param permissionNode The permission node to verify
|
* @param permissionNode The permission node to verify
|
||||||
*
|
*
|
||||||
* @return true if the player has permission, false otherwise
|
* @return true if the player has permission, false otherwise
|
||||||
@ -317,7 +321,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param groupName The group name.
|
* @param groupName The group name.
|
||||||
*
|
*
|
||||||
* @return True if the player is in the specified group, false otherwise.
|
* @return True if the player is in the specified group, false otherwise.
|
||||||
* False is also returned if groups aren't supported by the used permissions system.
|
* False is also returned if groups aren't supported by the used permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean isInGroup(OfflinePlayer player, String groupName) {
|
public boolean isInGroup(OfflinePlayer player, String groupName) {
|
||||||
return isEnabled() && handler.isInGroup(player, groupName);
|
return isEnabled() && handler.isInGroup(player, groupName);
|
||||||
@ -330,7 +334,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param groupName The name of the group.
|
* @param groupName The name of the group.
|
||||||
*
|
*
|
||||||
* @return True if succeed, false otherwise.
|
* @return True if succeed, false otherwise.
|
||||||
* False is also returned if this feature isn't supported for the current permissions system.
|
* False is also returned if this feature isn't supported for the current permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean addGroup(OfflinePlayer player, String groupName) {
|
public boolean addGroup(OfflinePlayer player, String groupName) {
|
||||||
if (!isEnabled() || StringUtils.isEmpty(groupName)) {
|
if (!isEnabled() || StringUtils.isEmpty(groupName)) {
|
||||||
@ -346,7 +350,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param groupNames The name of the groups to add.
|
* @param groupNames The name of the groups to add.
|
||||||
*
|
*
|
||||||
* @return True if at least one group was added, false otherwise.
|
* @return True if at least one group was added, false otherwise.
|
||||||
* False is also returned if this feature isn't supported for the current permissions system.
|
* False is also returned if this feature isn't supported for the current permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean addGroups(OfflinePlayer player, Collection<String> groupNames) {
|
public boolean addGroups(OfflinePlayer player, Collection<String> groupNames) {
|
||||||
// If no permissions system is used, return false
|
// If no permissions system is used, return false
|
||||||
@ -373,7 +377,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param groupName The name of the group.
|
* @param groupName The name of the group.
|
||||||
*
|
*
|
||||||
* @return True if succeed, false otherwise.
|
* @return True if succeed, false otherwise.
|
||||||
* False is also returned if this feature isn't supported for the current permissions system.
|
* False is also returned if this feature isn't supported for the current permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean removeGroup(OfflinePlayer player, String groupName) {
|
public boolean removeGroup(OfflinePlayer player, String groupName) {
|
||||||
return isEnabled() && handler.removeFromGroup(player, groupName);
|
return isEnabled() && handler.removeFromGroup(player, groupName);
|
||||||
@ -386,7 +390,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param groupNames The name of the groups to remove.
|
* @param groupNames The name of the groups to remove.
|
||||||
*
|
*
|
||||||
* @return True if at least one group was removed, false otherwise.
|
* @return True if at least one group was removed, false otherwise.
|
||||||
* False is also returned if this feature isn't supported for the current permissions system.
|
* False is also returned if this feature isn't supported for the current permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean removeGroups(OfflinePlayer player, Collection<String> groupNames) {
|
public boolean removeGroups(OfflinePlayer player, Collection<String> groupNames) {
|
||||||
// If no permissions system is used, return false
|
// If no permissions system is used, return false
|
||||||
@ -414,7 +418,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param groupName The name of the group.
|
* @param groupName The name of the group.
|
||||||
*
|
*
|
||||||
* @return True if succeed, false otherwise.
|
* @return True if succeed, false otherwise.
|
||||||
* False is also returned if this feature isn't supported for the current permissions system.
|
* False is also returned if this feature isn't supported for the current permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean setGroup(OfflinePlayer player, String groupName) {
|
public boolean setGroup(OfflinePlayer player, String groupName) {
|
||||||
return isEnabled() && handler.setGroup(player, groupName);
|
return isEnabled() && handler.setGroup(player, groupName);
|
||||||
@ -428,7 +432,7 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param player The player to remove all groups from.
|
* @param player The player to remove all groups from.
|
||||||
*
|
*
|
||||||
* @return True if succeed, false otherwise.
|
* @return True if succeed, false otherwise.
|
||||||
* False will also be returned if this feature isn't supported for the used permissions system.
|
* False will also be returned if this feature isn't supported for the used permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean removeAllGroups(OfflinePlayer player) {
|
public boolean removeAllGroups(OfflinePlayer player) {
|
||||||
// If no permissions system is used, return false
|
// If no permissions system is used, return false
|
||||||
@ -443,15 +447,47 @@ public class PermissionsManager implements Reloadable {
|
|||||||
return removeGroups(player, groupNames);
|
return removeGroups(player, groupNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadUserData(UUID uuid) {
|
/**
|
||||||
if(!isEnabled()) {
|
* Loads the permission data of the given player.
|
||||||
|
*
|
||||||
|
* @param offlinePlayer the offline player.
|
||||||
|
* @return true if the load was successful.
|
||||||
|
*/
|
||||||
|
public boolean loadUserData(OfflinePlayer offlinePlayer) {
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
loadUserData(offlinePlayer.getUniqueId());
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
loadUserData(offlinePlayer.getName());
|
||||||
|
}
|
||||||
|
} catch (PermissionLoadUserException e) {
|
||||||
|
ConsoleLogger.logException("Unable to load the permission data of user " + offlinePlayer.getName(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the permission data of the given player unique identifier.
|
||||||
|
*
|
||||||
|
* @param uuid the {@link UUID} of the player.
|
||||||
|
* @throws PermissionLoadUserException if the action failed.
|
||||||
|
*/
|
||||||
|
public void loadUserData(UUID uuid) throws PermissionLoadUserException {
|
||||||
|
if (!isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handler.loadUserData(uuid);
|
handler.loadUserData(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadUserData(String name) {
|
/**
|
||||||
if(!isEnabled()) {
|
* Loads the permission data of the given player name.
|
||||||
|
*
|
||||||
|
* @param name the name of the player.
|
||||||
|
* @throws PermissionLoadUserException if the action failed.
|
||||||
|
*/
|
||||||
|
public void loadUserData(String name) throws PermissionLoadUserException {
|
||||||
|
if (!isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handler.loadUserData(name);
|
handler.loadUserData(name);
|
||||||
|
@ -189,22 +189,21 @@ public class LuckPermsHandler implements PermissionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadUserData(UUID uuid) {
|
public void loadUserData(UUID uuid) throws PermissionLoadUserException {
|
||||||
try {
|
try {
|
||||||
luckPermsApi.getUserManager().loadUser(uuid).get(5, TimeUnit.SECONDS);
|
luckPermsApi.getUserManager().loadUser(uuid).get(5, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||||
e.printStackTrace();
|
throw new PermissionLoadUserException("Unable to load the permission data of the user " + uuid, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadUserData(String name) {
|
public void loadUserData(String name) throws PermissionLoadUserException {
|
||||||
try {
|
try {
|
||||||
UUID uuid = luckPermsApi.getStorage().getUUID(name).get(5, TimeUnit.SECONDS);
|
UUID uuid = luckPermsApi.getStorage().getUUID(name).get(5, TimeUnit.SECONDS);
|
||||||
loadUserData(uuid);
|
loadUserData(uuid);
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||||
e.printStackTrace();
|
throw new PermissionLoadUserException("Unable to load the permission data of the user " + name, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -107,10 +107,9 @@ public interface PermissionHandler {
|
|||||||
*/
|
*/
|
||||||
PermissionsSystemType getPermissionSystem();
|
PermissionsSystemType getPermissionSystem();
|
||||||
|
|
||||||
default void loadUserData(UUID uuid) {
|
default void loadUserData(UUID uuid) throws PermissionLoadUserException {
|
||||||
}
|
}
|
||||||
|
|
||||||
default void loadUserData(String name) {
|
default void loadUserData(String name) throws PermissionLoadUserException {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package fr.xephi.authme.permission.handlers;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown when a {@link PermissionHandler#loadUserData(UUID uuid)} request fails.
|
||||||
|
*/
|
||||||
|
public class PermissionLoadUserException extends Exception {
|
||||||
|
|
||||||
|
public PermissionLoadUserException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
@ -49,7 +49,7 @@ public class PurgeExecutor {
|
|||||||
* players and names.
|
* players and names.
|
||||||
*
|
*
|
||||||
* @param players the players to purge
|
* @param players the players to purge
|
||||||
* @param names names to purge
|
* @param names names to purge
|
||||||
*/
|
*/
|
||||||
public void executePurge(Collection<OfflinePlayer> players, Collection<String> names) {
|
public void executePurge(Collection<OfflinePlayer> players, Collection<String> names) {
|
||||||
// Purge other data
|
// Purge other data
|
||||||
@ -212,15 +212,13 @@ public class PurgeExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (OfflinePlayer offlinePlayer : cleared) {
|
for (OfflinePlayer offlinePlayer : cleared) {
|
||||||
try {
|
if (!permissionsManager.loadUserData(offlinePlayer)) {
|
||||||
permissionsManager.loadUserData(offlinePlayer.getUniqueId());
|
ConsoleLogger.warning("Unable to purge the permissions of user " + offlinePlayer + "!");
|
||||||
} catch (NoSuchMethodError e) {
|
continue;
|
||||||
permissionsManager.loadUserData(offlinePlayer.getName());
|
|
||||||
}
|
}
|
||||||
permissionsManager.removeAllGroups(offlinePlayer);
|
permissionsManager.removeAllGroups(offlinePlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleLogger.info("AutoPurge: Removed permissions from " + cleared.size() + " player(s).");
|
ConsoleLogger.info("AutoPurge: Removed permissions from " + cleared.size() + " player(s).");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package fr.xephi.authme.task.purge;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||||
|
import fr.xephi.authme.permission.handlers.PermissionLoadUserException;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -73,10 +74,9 @@ class PurgeTask extends BukkitRunnable {
|
|||||||
|
|
||||||
OfflinePlayer offlinePlayer = offlinePlayers[nextPosition];
|
OfflinePlayer offlinePlayer = offlinePlayers[nextPosition];
|
||||||
if (offlinePlayer.getName() != null && toPurge.remove(offlinePlayer.getName().toLowerCase())) {
|
if (offlinePlayer.getName() != null && toPurge.remove(offlinePlayer.getName().toLowerCase())) {
|
||||||
try {
|
if(!permissionsManager.loadUserData(offlinePlayer)) {
|
||||||
permissionsManager.loadUserData(offlinePlayer.getUniqueId());
|
ConsoleLogger.warning("Unable to check if the user " + offlinePlayer.getName() + " can be purged!");
|
||||||
} catch (NoSuchMethodError e) {
|
continue;
|
||||||
permissionsManager.loadUserData(offlinePlayer.getName());
|
|
||||||
}
|
}
|
||||||
if (!permissionsManager.hasPermissionOffline(offlinePlayer, PlayerStatePermission.BYPASS_PURGE)) {
|
if (!permissionsManager.hasPermissionOffline(offlinePlayer, PlayerStatePermission.BYPASS_PURGE)) {
|
||||||
playerPortion.add(offlinePlayer);
|
playerPortion.add(offlinePlayer);
|
||||||
|
Loading…
Reference in New Issue
Block a user