Some progress

This commit is contained in:
Gabriele C 2018-03-22 12:25:20 +01:00
parent 55fe319449
commit 185e5b7270
15 changed files with 413 additions and 197 deletions

View File

@ -68,7 +68,7 @@ class HasPermissionChecker implements DebugSection {
performPermissionCheck(offlinePlayer, permissionNode, permissionsManager::hasPermissionOffline, sender); performPermissionCheck(offlinePlayer, permissionNode, permissionsManager::hasPermissionOffline, sender);
} }
} else { } else {
performPermissionCheck(player, permissionNode, permissionsManager::hasPermission, sender); performPermissionCheck(player, permissionNode, permissionsManager.hasPermission(player, permissionNode), sender);
} }
} }

View File

@ -1,6 +1,5 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import fr.xephi.authme.OfflinePlayerInfo;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,4 +1,7 @@
package fr.xephi.authme; package fr.xephi.authme.listener;
import fr.xephi.authme.util.Utils;
import org.bukkit.OfflinePlayer;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -21,4 +24,10 @@ public class OfflinePlayerInfo {
return uniqueId; return uniqueId;
} }
public static OfflinePlayerInfo fromPlayer(OfflinePlayer player) {
return new OfflinePlayerInfo(player.getName(),
Utils.hasUniqueIdSupport() ? Optional.of(player.getUniqueId()) : Optional.empty()
);
}
} }

View File

@ -1,6 +1,5 @@
package fr.xephi.authme.listener; package fr.xephi.authme.listener;
import fr.xephi.authme.OfflinePlayerWrapper;
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;
@ -21,7 +20,7 @@ import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.Bukkit; import fr.xephi.authme.util.Utils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
@ -54,7 +53,7 @@ import org.bukkit.event.player.PlayerShearEntityEvent;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.UUID; import java.util.Optional;
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_MOVEMENT_RADIUS; import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_MOVEMENT_RADIUS;
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT; import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT;
@ -256,17 +255,21 @@ public class PlayerListener implements Listener {
return; return;
} }
final UUID uuid = event.getUniqueId();
final String name = event.getName(); final String name = event.getName();
if (validationService.isUnrestricted(name)) { if (validationService.isUnrestricted(name)) {
return; return;
} }
final OfflinePlayerWrapper player = new OfflinePlayerWrapper(uuid, name); OfflinePlayerInfo offlineInfo;
if(Utils.hasUniqueIdSupport()) {
offlineInfo = new OfflinePlayerInfo(name, Optional.of(event.getUniqueId()));
} else {
offlineInfo = new OfflinePlayerInfo(name, Optional.empty());
}
try { try {
runOnJoinChecks(JoiningPlayer.fromOfflinePlayer(player), event.getAddress().getHostAddress()); runOnJoinChecks(JoiningPlayer.fromOfflinePlayerInfo(offlineInfo), event.getAddress().getHostAddress());
} catch (FailedVerificationException e) { } catch (FailedVerificationException e) {
event.setKickMessage(m.retrieveSingle(name, e.getReason(), e.getArgs())); event.setKickMessage(m.retrieveSingle(name, e.getReason(), e.getArgs()));
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);

View File

@ -2,7 +2,7 @@ package fr.xephi.authme.permission;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.OfflinePlayerWrapper; import fr.xephi.authme.listener.OfflinePlayerInfo;
import fr.xephi.authme.initialization.Reloadable; import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.listener.JoiningPlayer; import fr.xephi.authme.listener.JoiningPlayer;
import fr.xephi.authme.permission.handlers.BPermissionsHandler; import fr.xephi.authme.permission.handlers.BPermissionsHandler;
@ -14,7 +14,6 @@ import fr.xephi.authme.permission.handlers.VaultHandler;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -114,7 +113,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 {
@ -230,11 +231,12 @@ 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 CompletableFuture<Boolean> hasPermission(JoiningPlayer joiningPlayer, PermissionNode permissionNode) {
return joiningPlayer.getPermissionLookupFunction().apply(this, permissionNode); return joiningPlayer.getPermissionLookupFunction().apply(this, permissionNode);
} }
@ -242,22 +244,22 @@ public class PermissionsManager implements Reloadable {
* Check if a player has permission for the given permission node. This is for offline player checks. * Check if a player has permission for the given permission node. This is for offline player checks.
* If no permissions system is used, then the player will not have permission. * If no permissions system is used, then the player will not have permission.
* *
* @param player The offline player * @param offlineInfo The offline 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
*/ */
public CompletableFuture<Boolean> hasPermissionOffline(OfflinePlayerWrapper player, PermissionNode permissionNode) { public CompletableFuture<Boolean> hasPermissionOffline(OfflinePlayerInfo offlineInfo, PermissionNode permissionNode) {
// Check if the permission node is null // Check if the permission node is null
if (permissionNode == null) { if (permissionNode == null) {
return completedFuture(true); return completedFuture(true);
} }
if (!isEnabled()) { if (!isEnabled()) {
return completedFuture(permissionNode.getDefaultPermission().evaluate(player)); //FIXME: find a way to use the bukkitService to access Bukkit.getOperators and check the uuid return completedFuture(permissionNode.getDefaultPermission().evaluate(offlineInfo)); //FIXME: find a way to use the bukkitService to access Bukkit.getOperators and check the uuid
} }
return handler.hasPermissionOffline(player, permissionNode); return handler.hasPermissionOffline(offlineInfo, permissionNode);
} }
/** /**
@ -277,8 +279,19 @@ public class PermissionsManager implements Reloadable {
* *
* @return Permission groups, or an empty collection if this feature is not supported. * @return Permission groups, or an empty collection if this feature is not supported.
*/ */
public CompletableFuture<List<String>> getGroups(OfflinePlayer player) { public List<String> getGroups(Player player) {
return isEnabled() ? handler.getGroups(player) : completedFuture(Collections.emptyList()); return isEnabled() ? handler.getGroups(player) : Collections.emptyList();
}
/**
* Get the permission groups of an offline player, if available.
*
* @param offlineInfo The offline player info.
*
* @return Permission groups, or an empty collection if this feature is not supported.
*/
public CompletableFuture<List<String>> getGroupsOffline(OfflinePlayerInfo offlineInfo) {
return isEnabled() ? handler.getGroupsOffline(offlineInfo) : completedFuture(Collections.emptyList());
} }
/** /**
@ -288,8 +301,19 @@ public class PermissionsManager implements Reloadable {
* *
* @return The name of the primary permission group. * @return The name of the primary permission group.
*/ */
public CompletableFuture<Optional<String>> getPrimaryGroup(OfflinePlayer player) { public Optional<String> getPrimaryGroup(Player player) {
return isEnabled() ? handler.getPrimaryGroup(player) : completedFuture(Optional.empty()); return isEnabled() ? handler.getPrimaryGroup(player) : Optional.empty();
}
/**
* Get the primary group of an offline player, if available.
*
* @param offlineInfo The offline player info.
*
* @return The name of the primary permission group.
*/
public CompletableFuture<Optional<String>> getPrimaryGroupOffline(OfflinePlayerInfo offlineInfo) {
return isEnabled() ? handler.getPrimaryGroupOffline(offlineInfo) : completedFuture(Optional.empty());
} }
/** /**
@ -299,29 +323,55 @@ 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 CompletableFuture<Boolean> isInGroup(OfflinePlayer player, String groupName) { public boolean isInGroup(Player player, String groupName) {
if(!isEnabled()) { return isEnabled() && handler.isInGroup(player, groupName);
}
/**
* Check whether the offline player is in the specified group.
*
* @param offlineInfo The offline player info.
* @param groupName The group name.
*
* @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.
*/
public CompletableFuture<Boolean> isInGroup(OfflinePlayerInfo offlineInfo, String groupName) {
if (!isEnabled()) {
return completedFuture(false); return completedFuture(false);
} }
return handler.isInGroup(player, groupName); return handler.isInGroupOffline(offlineInfo, groupName);
} }
/** /**
* Add the permission group of a player, if supported. * Add the permission group of a player, if supported.
* *
* @param player The player * @param player The player.
* @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 CompletableFuture<Boolean> addGroup(OfflinePlayer player, String groupName) { public boolean addGroup(Player player, String groupName) {
return isEnabled() && !StringUtils.isEmpty(groupName) && handler.addToGroup(player, groupName);
}
/**
* Add the permission group of an offline player, if supported.
*
* @param offlineInfo The offline player info.
* @param groupName The name of the group.
*
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public CompletableFuture<Boolean> addGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
if (!isEnabled() || StringUtils.isEmpty(groupName)) { if (!isEnabled() || StringUtils.isEmpty(groupName)) {
return completedFuture(false); return completedFuture(false);
} }
return handler.addToGroup(player, groupName); return handler.addToGroupOffline(offlineInfo, groupName);
} }
/** /**
@ -331,12 +381,12 @@ 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 CompletableFuture<Boolean> addGroups(OfflinePlayer player, Collection<String> groupNames) { public boolean addGroups(Player player, Collection<String> groupNames) {
// If no permissions system is used, return false // If no permissions system is used, return false
if (!isEnabled()) { if (!isEnabled()) {
return completedFuture(false); return false;
} }
// Add each group to the user // Add each group to the user
@ -352,35 +402,74 @@ public class PermissionsManager implements Reloadable {
} }
/** /**
* Add the permission groups of an offline player, if supported.
* *
* @param offlineInfo The offline player info.
* @param groupNames The name of the groups to add.
*
* @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.
*/
public CompletableFuture<Boolean> addGroupsOffline(OfflinePlayerInfo offlineInfo, Collection<String> groupNames) {
// If no permissions system is used, return false
if (!isEnabled()) {
return completedFuture(false);
}
// Add each group to the user
boolean result = false;
for (String groupName : groupNames) {
if (!groupName.isEmpty()) {
result |= handler.addToGroupOffline(offlineInfo, groupName).join();
}
}
// Return the result
return completedFuture(result);
}
/**
* Remove the permission group of a player, if supported. * Remove the permission group of a player, if supported.
* *
* @param player The player * @param player The player
* @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 CompletableFuture<Boolean> removeGroup(OfflinePlayer player, String groupName) { public boolean removeGroup(Player player, String groupName) {
if(!isEnabled()) { return isEnabled() && handler.removeFromGroup(player, groupName);
}
/**
* Remove the permission group of an offline player, if supported.
*
* @param offlineInfo The offline player info.
* @param groupName The name of the group.
*
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public CompletableFuture<Boolean> removeGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
if (!isEnabled()) {
return completedFuture(false); return completedFuture(false);
} }
return handler.removeFromGroup(player, groupName); return handler.removeFromGroupOffline(offlineInfo, groupName);
} }
/** /**
* Remove the permission groups of a player, if supported. * Remove the permission groups of a player, if supported.
* *
* @param player The player * @param player The player.
* @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 CompletableFuture<Boolean> removeGroups(OfflinePlayer player, Collection<String> groupNames) { public boolean removeGroups(Player player, Collection<String> groupNames) {
// If no permissions system is used, return false // If no permissions system is used, return false
if (!isEnabled()) { if (!isEnabled()) {
return completedFuture(false); return false;
} }
// Add each group to the user // Add each group to the user
@ -395,6 +484,33 @@ public class PermissionsManager implements Reloadable {
return result; return result;
} }
/**
* Remove the permission groups of an offline player, if supported.
*
* @param offlineInfo The offline player info.
* @param groups The name of the groups to remove.
*
* @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.
*/
public CompletableFuture<Boolean> removeGroupsOffline(OfflinePlayerInfo offlineInfo, Collection<String> groups) {
// If no permissions system is used, return false
if (!isEnabled()) {
return completedFuture(false);
}
// Add each group to the user
boolean result = false;
for (String groupName : groups) {
if (!groupName.isEmpty()) {
result |= handler.removeFromGroupOffline(offlineInfo, groupName).join();
}
}
// Return the result
return completedFuture(result);
}
/** /**
* Set the permission group of a player, if supported. * Set the permission group of a player, if supported.
* This clears the current groups of the player. * This clears the current groups of the player.
@ -403,13 +519,27 @@ 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 CompletableFuture<Boolean> setGroup(OfflinePlayer player, String groupName) { public boolean setGroup(Player player, String groupName) {
if(!isEnabled()) { return isEnabled() && handler.setGroup(player, groupName);
}
/**
* Set the permission group of an offline player, if supported.
* This clears the current groups of the player.
*
* @param offlineInfo The offline player info.
* @param groupName The name of the group.
*
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
*/
public CompletableFuture<Boolean> setGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
if (!isEnabled()) {
return completedFuture(false); return completedFuture(false);
} }
return handler.setGroup(player, groupName); return handler.setGroupOffline(offlineInfo, groupName);
} }
/** /**
@ -420,16 +550,30 @@ 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 CompletableFuture<Boolean> removeAllGroups(OfflinePlayer player) { public boolean removeAllGroups(Player player) {
return isEnabled() && removeGroups(player, getGroups(player));
}
/**
* Remove all groups of the specified offline player, if supported.
* Systems like Essentials GroupManager don't allow all groups to be removed from a player, thus the user will stay
* in its primary group. All the subgroups are removed just fine.
*
* @param offlineInfo The offline player info to remove all groups from.
*
* @return True if succeed, false otherwise.
* False will also be returned if this feature isn't supported for the used permissions system.
*/
public CompletableFuture<Boolean> removeAllGroupsOffline(OfflinePlayerInfo offlineInfo) {
// If no permissions system is used, return false // If no permissions system is used, return false
if (!isEnabled()) { if (!isEnabled()) {
return completedFuture(false); return completedFuture(false);
} }
// Get a list of current groups and remove them // Get a list of current groups and remove them
return getGroups(player).thenApply(groups -> removeGroups(player, groups).join()); return getGroupsOffline(offlineInfo).thenApply(groups -> removeGroupsOffline(offlineInfo, groups).join());
} }
} }

View File

@ -2,10 +2,9 @@ package fr.xephi.authme.permission.handlers;
import de.bananaco.bpermissions.api.ApiLayer; import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.CalculableType; import de.bananaco.bpermissions.api.CalculableType;
import fr.xephi.authme.OfflinePlayerInfo; import fr.xephi.authme.listener.OfflinePlayerInfo;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.permission.PermissionsSystemType;
import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -19,7 +18,7 @@ import static java.util.concurrent.CompletableFuture.completedFuture;
* @see <a href="https://dev.bukkit.org/projects/bpermissions">bPermissions Bukkit page</a> * @see <a href="https://dev.bukkit.org/projects/bpermissions">bPermissions Bukkit page</a>
* @see <a href="https://github.com/rymate1234/bPermissions/">bPermissions on Github</a> * @see <a href="https://github.com/rymate1234/bPermissions/">bPermissions on Github</a>
*/ */
public class BPermissionsHandler implements PermissionHandler { public class BPermissionsHandler implements SimplePermissionHandler {
@Override @Override
public PermissionsSystemType getPermissionSystem() { public PermissionsSystemType getPermissionSystem() {
@ -36,56 +35,28 @@ public class BPermissionsHandler implements PermissionHandler {
return completedFuture(ApiLayer.hasPermission(null, CalculableType.USER, offlineInfo.getName(), node.getNode())); return completedFuture(ApiLayer.hasPermission(null, CalculableType.USER, offlineInfo.getName(), node.getNode()));
} }
@Override
public List<String> getGroups(Player player) {
return Arrays.asList(ApiLayer.getGroups(null, CalculableType.USER, player.getName()));
}
@Override @Override
public CompletableFuture<List<String>> getGroupsOffline(OfflinePlayerInfo offlineInfo) { public CompletableFuture<List<String>> getGroupsOffline(OfflinePlayerInfo offlineInfo) {
return completedFuture(Arrays.asList(ApiLayer.getGroups(null, CalculableType.USER, offlineInfo.getName()))); return completedFuture(Arrays.asList(ApiLayer.getGroups(null, CalculableType.USER, offlineInfo.getName())));
} }
@Override
public boolean isInGroup(Player player, String groupName) {
return ApiLayer.hasGroup(null, CalculableType.USER, player.getName(), groupName);
}
@Override @Override
public CompletableFuture<Boolean> isInGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) { public CompletableFuture<Boolean> isInGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return completedFuture(ApiLayer.hasGroup(null, CalculableType.USER, offlineInfo.getName(), groupName)); return completedFuture(ApiLayer.hasGroup(null, CalculableType.USER, offlineInfo.getName(), groupName));
} }
@Override
public boolean addToGroup(Player player, String groupName) {
ApiLayer.addGroup(null, CalculableType.USER, player.getName(), groupName);
return true;
}
@Override @Override
public CompletableFuture<Boolean> addToGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) { public CompletableFuture<Boolean> addToGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
ApiLayer.addGroup(null, CalculableType.USER, offlineInfo.getName(), groupName); ApiLayer.addGroup(null, CalculableType.USER, offlineInfo.getName(), groupName);
return completedFuture(true); return completedFuture(true);
} }
@Override
public boolean removeFromGroup(Player player, String groupName) {
ApiLayer.removeGroup(null, CalculableType.USER, player.getName(), groupName);
return true;
}
@Override @Override
public CompletableFuture<Boolean> removeFromGroupOffline(OfflinePlayerInfo playerInfo, String groupName) { public CompletableFuture<Boolean> removeFromGroupOffline(OfflinePlayerInfo playerInfo, String groupName) {
ApiLayer.removeGroup(null, CalculableType.USER, playerInfo.getName(), groupName); ApiLayer.removeGroup(null, CalculableType.USER, playerInfo.getName(), groupName);
return completedFuture(true); return completedFuture(true);
} }
@Override
public boolean setGroup(Player player, String group) {
ApiLayer.setGroup(null, CalculableType.USER, player.getName(), group);
return true;
}
@Override @Override
public CompletableFuture<Boolean> setGroupOffline(OfflinePlayerInfo offlineInfo, String group) { public CompletableFuture<Boolean> setGroupOffline(OfflinePlayerInfo offlineInfo, String group) {
ApiLayer.setGroup(null, CalculableType.USER, offlineInfo.getName(), group); ApiLayer.setGroup(null, CalculableType.USER, offlineInfo.getName(), group);

View File

@ -1,9 +1,10 @@
package fr.xephi.authme.permission.handlers; package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.OfflinePlayerInfo; import fr.xephi.authme.listener.OfflinePlayerInfo;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.permission.PermissionsSystemType;
import fr.xephi.authme.util.OptionalUtils; import fr.xephi.authme.util.OptionalUtils;
import fr.xephi.authme.util.Utils;
import me.lucko.luckperms.LuckPerms; import me.lucko.luckperms.LuckPerms;
import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.DataMutateResult; import me.lucko.luckperms.api.DataMutateResult;
@ -37,6 +38,9 @@ public class LuckPermsHandler implements PermissionHandler {
private LuckPermsApi luckPermsApi; private LuckPermsApi luckPermsApi;
public LuckPermsHandler() throws PermissionHandlerException { public LuckPermsHandler() throws PermissionHandlerException {
if(!Utils.hasUniqueIdSupport()) {
throw new PermissionHandlerException("LuckPerms handler can't be used on server instances that doesn't support UUIDs.");
}
try { try {
luckPermsApi = LuckPerms.getApi(); luckPermsApi = LuckPerms.getApi();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
@ -59,11 +63,10 @@ public class LuckPermsHandler implements PermissionHandler {
} }
private CompletableFuture<User> getUserOffline(OfflinePlayerInfo offlineInfo) { private CompletableFuture<User> getUserOffline(OfflinePlayerInfo offlineInfo) {
if (!offlineInfo.getUniqueId().isPresent()) { return luckPermsApi.getUserManager().loadUser(
throw new IllegalStateException("Tried to obtain an offline LuckPerms User but the" + offlineInfo.getUniqueId().orElseThrow(() -> new IllegalStateException("OfflinePlayerInfo UUID was empty")),
"server doesn't support UUIDs!"); offlineInfo.getName()
} );
return luckPermsApi.getUserManager().loadUser(offlineInfo.getUniqueId().get(), offlineInfo.getName());
} }
private Optional<Group> getGroup(String groupName) { private Optional<Group> getGroup(String groupName) {
@ -74,23 +77,20 @@ public class LuckPermsHandler implements PermissionHandler {
return luckPermsApi.getNodeFactory().makeGroupNode(group).build(); return luckPermsApi.getNodeFactory().makeGroupNode(group).build();
} }
private <T> T processUser(Player player, String groupName, BiFunction<User, Group, T> action, T failed) { private boolean processUser(Player player, String groupName, BiFunction<User, Group, Boolean> action) {
return handleOptional(getGroup(groupName), return handleOptional(getGroup(groupName),
group -> OptionalUtils.handleOptional(getUser(player), group -> OptionalUtils.handleOptional(getUser(player),
user -> action.apply(user, group), user -> action.apply(user, group),
() -> failed false
), ),
() -> failed false
); );
} }
private <T> CompletableFuture<T> processUser(OfflinePlayerInfo offlineInfo, String groupName, BiFunction<User, Group, T> action, T failed) { private CompletableFuture<Boolean> processUserOffline(OfflinePlayerInfo offlineInfo, String groupName, BiFunction<User, Group, Boolean> action) {
return handleOptional(getGroup(groupName), return handleOptional(getGroup(groupName),
group -> OptionalUtils.handleOptional(getUser(player), group -> getUserOffline(offlineInfo).thenApply(user -> action.apply(user, group)),
user -> action.apply(user, group), completedFuture(false)
() -> failed
),
() -> failed
); );
} }
@ -134,34 +134,28 @@ public class LuckPermsHandler implements PermissionHandler {
} }
saveUser(user); saveUser(user);
return true; return true;
}), false); }));
} }
@Override @Override
public CompletableFuture<Boolean> addToGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) { public CompletableFuture<Boolean> addToGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return handleOptional(getGroup(groupName), return processUserOffline(offlineInfo, groupName, (user, group) -> {
group -> getUserOffline(offlineInfo).thenApply(user -> { if (user.setPermission(getGroupNode(group)).wasFailure()) {
if (user.setPermission(getGroupNode(group)).wasFailure()) { return false;
return false; }
} saveUser(user);
saveUser(user); return true;
return true; });
}),
() -> completedFuture(false)
);
} }
@Override @Override
public boolean isInGroup(Player player, String groupName) { public boolean isInGroup(Player player, String groupName) {
return processUser(player, groupName, (PermissionHolder::inheritsGroup), false); return processUser(player, groupName, (PermissionHolder::inheritsGroup));
} }
@Override @Override
public CompletableFuture<Boolean> isInGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) { public CompletableFuture<Boolean> isInGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return handleOptional(luckPermsApi.getGroupSafe(groupName), return processUserOffline(offlineInfo, groupName, PermissionHolder::inheritsGroup);
group -> getUserOffline(offlineInfo).thenApply(user -> user.inheritsGroup(group)),
() -> completedFuture(false)
);
} }
@Override @Override
@ -172,21 +166,18 @@ public class LuckPermsHandler implements PermissionHandler {
} }
saveUser(user); saveUser(user);
return true; return true;
}), false); }));
} }
@Override @Override
public CompletableFuture<Boolean> removeFromGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) { public CompletableFuture<Boolean> removeFromGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return handleOptional(getGroup(groupName), return processUserOffline(offlineInfo, groupName, (user, group) -> {
group -> getUserOffline(offlineInfo).thenApply(user -> { if (user.unsetPermission(getGroupNode(group)).wasFailure()) {
if (user.unsetPermission(getGroupNode(group)).wasFailure()) { return false;
return false; }
} saveUser(user);
saveUser(user); return true;
return true; });
}),
() -> completedFuture(false)
);
} }
@Override @Override
@ -198,27 +189,24 @@ public class LuckPermsHandler implements PermissionHandler {
user.clearMatching(node -> node.isGroupNode() && !node.getGroupName().equals(group.getName())); user.clearMatching(node -> node.isGroupNode() && !node.getGroupName().equals(group.getName()));
saveUser(user); saveUser(user);
return true; return true;
}, false); });
} }
@Override @Override
public CompletableFuture<Boolean> setGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) { public CompletableFuture<Boolean> setGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return handleOptional(getGroup(groupName), return processUserOffline(offlineInfo, groupName, (user, group) -> {
group -> getUserOffline(offlineInfo).thenApply(user -> { if (user.setPermission(getGroupNode(group)) == DataMutateResult.FAIL) {
if (user.setPermission(getGroupNode(group)) == DataMutateResult.FAIL) { return false;
return false; }
} user.clearMatching(node -> node.isGroupNode() && !node.getGroupName().equals(group.getName()));
user.clearMatching(node -> node.isGroupNode() && !node.getGroupName().equals(group.getName())); saveUser(user);
saveUser(user); return true;
return true; });
}),
() -> completedFuture(false)
);
} }
@Override @Override
public List<String> getGroups(Player player) { public List<String> getGroups(Player player) {
return handleOptional(getUser(player), this::getGroupsOrdered, Collections::emptyList); return handleOptional(getUser(player), this::getGroupsOrdered, Collections.emptyList());
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package fr.xephi.authme.permission.handlers; package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.OfflinePlayerInfo; import fr.xephi.authme.listener.OfflinePlayerInfo;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.permission.PermissionsSystemType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,9 +1,8 @@
package fr.xephi.authme.permission.handlers; package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.OfflinePlayerWrapper; import fr.xephi.authme.listener.OfflinePlayerInfo;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.permission.PermissionsSystemType;
import org.bukkit.OfflinePlayer;
import ru.tehkode.permissions.PermissionManager; import ru.tehkode.permissions.PermissionManager;
import ru.tehkode.permissions.PermissionUser; import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx; import ru.tehkode.permissions.bukkit.PermissionsEx;
@ -12,6 +11,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import static fr.xephi.authme.util.OptionalUtils.handleOptional;
import static java.util.concurrent.CompletableFuture.completedFuture; import static java.util.concurrent.CompletableFuture.completedFuture;
/** /**
@ -20,7 +20,7 @@ import static java.util.concurrent.CompletableFuture.completedFuture;
* @see <a href="https://dev.bukkit.org/projects/permissionsex">PermissionsEx Bukkit page</a> * @see <a href="https://dev.bukkit.org/projects/permissionsex">PermissionsEx Bukkit page</a>
* @see <a href="https://github.com/PEXPlugins/PermissionsEx">PermissionsEx on Github</a> * @see <a href="https://github.com/PEXPlugins/PermissionsEx">PermissionsEx on Github</a>
*/ */
public class PermissionsExHandler implements PermissionHandler { public class PermissionsExHandler implements SimplePermissionHandler {
private PermissionManager permissionManager; private PermissionManager permissionManager;
@ -31,20 +31,25 @@ public class PermissionsExHandler implements PermissionHandler {
} }
} }
private PermissionUser getUser(OfflinePlayerWrapper player) { private boolean isGroupValid(String groupName) {
try { return permissionManager.getGroupNames().contains(groupName);
return permissionManager.getUser(player.getUniqueId()); }
} catch (NoSuchMethodError e) {
return permissionManager.getUser(player.getName()); private PermissionUser getUserOffline(OfflinePlayerInfo player) {
} return handleOptional(player.getUniqueId(), uuid -> permissionManager.getUser(uuid), permissionManager.getUser(player.getName()));
} }
@Override @Override
public CompletableFuture<Boolean> addToGroup(OfflinePlayerWrapper player, String groupName) { public CompletableFuture<Boolean> hasPermissionOffline(OfflinePlayerInfo offlinePlayerInfo, PermissionNode node) {
if (!permissionManager.getGroupNames().contains(groupName)) { return completedFuture(getUserOffline(offlinePlayerInfo).has(node.getNode()));
}
@Override
public CompletableFuture<Boolean> addToGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
if (!isGroupValid(groupName)) {
return completedFuture(false); return completedFuture(false);
} }
permissionManager.getUser(player.getName()).addGroup(groupName); getUserOffline(offlineInfo).addGroup(groupName);
return completedFuture(true); return completedFuture(true);
} }
@ -54,37 +59,38 @@ public class PermissionsExHandler implements PermissionHandler {
} }
@Override @Override
public CompletableFuture<Boolean> hasPermissionOffline(OfflinePlayerWrapper player, PermissionNode node) { public CompletableFuture<Boolean> isInGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return completedFuture(getUser(player).has(node.getNode())); return completedFuture(getUserOffline(offlineInfo).inGroup(groupName));
} }
@Override @Override
public CompletableFuture<Boolean> isInGroup(OfflinePlayerWrapper player, String groupName) { public CompletableFuture<Boolean> removeFromGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return completedFuture(getUser(player).inGroup(groupName)); if (!isGroupValid(groupName)) {
} return completedFuture(false);
}
@Override getUserOffline(offlineInfo).removeGroup(groupName);
public CompletableFuture<Boolean> removeFromGroup(OfflinePlayerWrapper player, String groupName) {
getUser(player).removeGroup(groupName);
return completedFuture(true); return completedFuture(true);
} }
@Override @Override
public CompletableFuture<Boolean> setGroup(OfflinePlayerWrapper player, String group) { public CompletableFuture<Boolean> setGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
if (!isGroupValid(groupName)) {
return completedFuture(false);
}
List<String> groups = new ArrayList<>(); List<String> groups = new ArrayList<>();
groups.add(group); groups.add(groupName);
getUserOffline(offlineInfo).setParentsIdentifier(groups);
getUser(player).setParentsIdentifier(groups);
return completedFuture(true); return completedFuture(true);
} }
@Override @Override
public CompletableFuture<List<String>> getGroups(OfflinePlayerWrapper player) { public CompletableFuture<List<String>> getGroupsOffline(OfflinePlayerInfo offlineInfo) {
return completedFuture(getUser(player).getParentIdentifiers(null)); return completedFuture(getUserOffline(offlineInfo).getParentIdentifiers(null));
} }
@Override @Override
public PermissionsSystemType getPermissionSystem() { public PermissionsSystemType getPermissionSystem() {
return PermissionsSystemType.PERMISSIONS_EX; return PermissionsSystemType.PERMISSIONS_EX;
} }
} }

View File

@ -0,0 +1,41 @@
package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.listener.OfflinePlayerInfo;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Optional;
public interface SimplePermissionHandler extends PermissionHandler {
@Override
default List<String> getGroups(Player player) {
return getGroupsOffline(OfflinePlayerInfo.fromPlayer(player)).join();
}
@Override
default Optional<String> getPrimaryGroup(Player player) {
return getPrimaryGroupOffline(OfflinePlayerInfo.fromPlayer(player)).join();
}
@Override
default boolean isInGroup(Player player, String groupName) {
return isInGroupOffline(OfflinePlayerInfo.fromPlayer(player), groupName).join();
}
@Override
default boolean addToGroup(Player player, String groupName) {
return addToGroupOffline(OfflinePlayerInfo.fromPlayer(player), groupName).join();
}
@Override
default boolean removeFromGroup(Player player, String groupName) {
return removeFromGroupOffline(OfflinePlayerInfo.fromPlayer(player), groupName).join();
}
@Override
default boolean setGroup(Player player, String groupName) {
return setGroupOffline(OfflinePlayerInfo.fromPlayer(player), groupName).join();
}
}

View File

@ -1,11 +1,11 @@
package fr.xephi.authme.permission.handlers; package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.OfflinePlayerWrapper; import fr.xephi.authme.listener.OfflinePlayerInfo;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.permission.PermissionsSystemType;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.Arrays; import java.util.Arrays;
@ -45,48 +45,78 @@ public class VaultHandler implements PermissionHandler {
return vaultPerms; return vaultPerms;
} }
@Override
@SuppressWarnings("deprecated")
public CompletableFuture<Boolean> addToGroup(OfflinePlayerWrapper player, String groupName) {
return completedFuture(vaultProvider.playerAddGroup((String)null, player.getName(), groupName));
}
@Override @Override
public boolean hasGroupSupport() { public boolean hasGroupSupport() {
return vaultProvider.hasGroupSupport(); return vaultProvider.hasGroupSupport();
} }
@Override @Override
public CompletableFuture<Boolean> hasPermissionOffline(OfflinePlayerWrapper player, PermissionNode node) { public CompletableFuture<Boolean> hasPermissionOffline(OfflinePlayerInfo offlineInfo, PermissionNode node) {
return completedFuture(vaultProvider.playerHas((String)null, player.getName(), node.getNode())); return completedFuture(vaultProvider.playerHas((String) null, offlineInfo.getName(), node.getNode()));
} }
@Override @Override
public CompletableFuture<Boolean> isInGroup(OfflinePlayerWrapper player, String groupName) { public boolean isInGroup(Player player, String groupName) {
return completedFuture(vaultProvider.playerInGroup(null, player, groupName)); return vaultProvider.playerInGroup(null, player, groupName);
} }
@Override @Override
public CompletableFuture<Boolean> removeFromGroup(OfflinePlayerWrapper player, String groupName) { public CompletableFuture<Boolean> isInGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return completedFuture(vaultProvider.playerRemoveGroup(null, player, groupName)); return completedFuture(vaultProvider.playerInGroup((String) null, offlineInfo.getName(), groupName));
} }
@Override @Override
public CompletableFuture<Boolean> setGroup(OfflinePlayerWrapper player, String groupName) { public boolean removeFromGroup(Player player, String groupName) {
return getGroups(player).thenApply(groups -> { return vaultProvider.playerRemoveGroup(null, player, groupName);
groups.forEach(group -> removeFromGroup(player, group)); }
return vaultProvider.playerAddGroup(null, player, groupName);
@Override
public CompletableFuture<Boolean> removeFromGroupOffline(OfflinePlayerInfo offlinePlayerInfo, String groupName) {
return completedFuture(vaultProvider.playerRemoveGroup((String) null, offlinePlayerInfo.getName(), groupName));
}
@Override
public boolean setGroup(Player player, String groupName) {
getGroups(player).forEach(group -> removeFromGroup(player, group));
return addToGroup(player, groupName);
}
@Override
public CompletableFuture<Boolean> setGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return getGroupsOffline(offlineInfo).thenApply(groups -> {
groups.forEach(group -> removeFromGroupOffline(offlineInfo, group));
return addToGroupOffline(offlineInfo, groupName).join();
}); });
} }
@Override @Override
public CompletableFuture<List<String>> getGroups(OfflinePlayerWrapper player) { public List<String> getGroups(Player player) {
return completedFuture(Arrays.asList(vaultProvider.getPlayerGroups(null, player))); return Arrays.asList(vaultProvider.getPlayerGroups((String) null, player));
} }
@Override @Override
public CompletableFuture<Optional<String>> getPrimaryGroup(OfflinePlayerWrapper player) { public CompletableFuture<List<String>> getGroupsOffline(OfflinePlayerInfo offlineInfo) {
return completedFuture(Optional.ofNullable(vaultProvider.getPrimaryGroup(null, player))); return completedFuture(Arrays.asList(vaultProvider.getPlayerGroups((String) null, offlineInfo.getName())));
}
@Override
public Optional<String> getPrimaryGroup(Player player) {
return Optional.ofNullable(vaultProvider.getPrimaryGroup(null, player));
}
@Override
public CompletableFuture<Optional<String>> getPrimaryGroupOffline(OfflinePlayerInfo offlineInfo) {
return completedFuture(Optional.ofNullable(vaultProvider.getPrimaryGroup((String) null, offlineInfo.getName())));
}
@Override
public boolean addToGroup(Player player, String groupName) {
return vaultProvider.playerAddGroup(null, player, groupName);
}
@Override
public CompletableFuture<Boolean> addToGroupOffline(OfflinePlayerInfo offlineInfo, String groupName) {
return completedFuture(vaultProvider.playerAddGroup((String) null, offlineInfo.getName(), groupName));
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package fr.xephi.authme.task.purge; package fr.xephi.authme.task.purge;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.listener.OfflinePlayerInfo;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.BukkitService;
@ -211,16 +212,10 @@ public class PurgeExecutor {
return; return;
} }
for (OfflinePlayer offlinePlayer : cleared) { cleared.stream().map(OfflinePlayerInfo::fromPlayer)
try { .forEach(offlineInfo -> permissionsManager.removeAllGroupsOffline(offlineInfo));
permissionsManager.loadUserData(offlinePlayer.getUniqueId());
} catch (NoSuchMethodError e) {
permissionsManager.loadUserData(offlinePlayer.getName());
}
permissionsManager.removeAllGroups(offlinePlayer);
}
ConsoleLogger.info("AutoPurge: Removed permissions from " + cleared.size() + " player(s)."); ConsoleLogger.info("AutoPurge: Removing permissions from " + cleared.size() + " player(s).");
} }
} }

View File

@ -73,11 +73,6 @@ 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 {
permissionsManager.loadUserData(offlinePlayer.getUniqueId());
} catch (NoSuchMethodError e) {
permissionsManager.loadUserData(offlinePlayer.getName());
}
if (!permissionsManager.hasPermissionOffline(offlinePlayer, PlayerStatePermission.BYPASS_PURGE)) { if (!permissionsManager.hasPermissionOffline(offlinePlayer, PlayerStatePermission.BYPASS_PURGE)) {
playerPortion.add(offlinePlayer); playerPortion.add(offlinePlayer);
namePortion.add(offlinePlayer.getName()); namePortion.add(offlinePlayer.getName());

View File

@ -32,4 +32,23 @@ public final class OptionalUtils {
} }
} }
/**
* Handles the value of an Optional object.
*
* @param optional the optional object
* @param ifPresent the Function invoked when the Optional is filled
* @param ifAbsent the result when the Optional is empty
* @param <T> the Optional object type
* @param <R> the return type
*
* @return the object returned by the Function or Supplier
*/
public static <T, R> R handleOptional(Optional<T> optional, Function<T, R> ifPresent, R ifAbsent) {
if (optional.isPresent()) {
return ifPresent.apply(optional.get());
} else {
return ifAbsent;
}
}
} }

View File

@ -4,6 +4,7 @@ import fr.xephi.authme.ConsoleLogger;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import java.util.Collection; import java.util.Collection;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -106,4 +107,19 @@ public final class Utils {
public static boolean isEmailEmpty(String email) { public static boolean isEmailEmpty(String email) {
return StringUtils.isEmpty(email) || "your@email.com".equalsIgnoreCase(email); return StringUtils.isEmpty(email) || "your@email.com".equalsIgnoreCase(email);
} }
/**
* Returns whether the running server instance supports player UUIDs.
*
* @return true if the server supports player UUIDs
*/
public static boolean hasUniqueIdSupport() {
try {
Player.class.getMethod("getUniqueId");
return true;
} catch (NoSuchMethodException ignored) {
}
return false;
}
} }