mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-10 09:57:33 +01:00
Compile against 1.15 api, update luckperms to 5.0 (breaking change)
This commit is contained in:
parent
71cda72b8a
commit
e05c07799d
8
pom.xml
8
pom.xml
@ -64,7 +64,7 @@
|
||||
<maven.minimumVersion>3.3.9</maven.minimumVersion>
|
||||
|
||||
<!-- Dependencies versions -->
|
||||
<spigot.version>1.14.2-R0.1-SNAPSHOT</spigot.version>
|
||||
<spigot.version>1.15-R0.1-SNAPSHOT</spigot.version>
|
||||
|
||||
<!-- Versioning properties -->
|
||||
<project.outputName>AuthMe</project.outputName>
|
||||
@ -690,9 +690,9 @@
|
||||
|
||||
<!-- LuckPerms plugin -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>4.4</version>
|
||||
<groupId>net.luckperms</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>5.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -4,20 +4,21 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import me.lucko.luckperms.LuckPerms;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.caching.PermissionData;
|
||||
import me.lucko.luckperms.api.caching.UserData;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.cacheddata.CachedPermissionData;
|
||||
import net.luckperms.api.model.data.DataMutateResult;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.node.NodeEqualityPredicate;
|
||||
import net.luckperms.api.node.types.InheritanceNode;
|
||||
import net.luckperms.api.query.QueryMode;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -33,42 +34,39 @@ import java.util.stream.Collectors;
|
||||
public class LuckPermsHandler implements PermissionHandler {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(LuckPermsHandler.class);
|
||||
private LuckPermsApi luckPermsApi;
|
||||
private LuckPerms luckPerms;
|
||||
|
||||
public LuckPermsHandler() throws PermissionHandlerException {
|
||||
try {
|
||||
luckPermsApi = LuckPerms.getApi();
|
||||
luckPerms = LuckPermsProvider.get();
|
||||
} catch (IllegalStateException e) {
|
||||
throw new PermissionHandlerException("Could not get api of LuckPerms", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveUser(User user) {
|
||||
luckPermsApi.getUserManager().saveUser(user)
|
||||
.thenAcceptAsync(wasSuccessful -> user.refreshCachedData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(OfflinePlayer player, String group) {
|
||||
Group newGroup = luckPermsApi.getGroup(group);
|
||||
Group newGroup = luckPerms.getGroupManager().getGroup(group);
|
||||
if (newGroup == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
User user = luckPermsApi.getUser(player.getName());
|
||||
String playerName = player.getName();
|
||||
if (playerName == null) {
|
||||
return false;
|
||||
}
|
||||
User user = luckPerms.getUserManager().getUser(playerName);
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DataMutateResult result = user.setPermission(
|
||||
luckPermsApi.getNodeFactory().makeGroupNode(newGroup).build());
|
||||
InheritanceNode node = InheritanceNode.builder(group).build();
|
||||
DataMutateResult result = user.data().add(node);
|
||||
if (result == DataMutateResult.FAIL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
saveUser(user);
|
||||
luckPermsApi.cleanupUser(user);
|
||||
|
||||
luckPerms.getUserManager().saveUser(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -79,97 +77,102 @@ public class LuckPermsHandler implements PermissionHandler {
|
||||
|
||||
@Override
|
||||
public boolean hasPermissionOffline(String name, PermissionNode node) {
|
||||
User user = luckPermsApi.getUser(name);
|
||||
User user = luckPerms.getUserManager().getUser(name);
|
||||
if (user == null) {
|
||||
logger.warning("LuckPermsHandler: tried to check permission for offline user "
|
||||
+ name + " but it isn't loaded!");
|
||||
return false;
|
||||
}
|
||||
|
||||
UserData userData = user.getCachedData();
|
||||
PermissionData permissionData = userData.getPermissionData(Contexts.allowAll());
|
||||
boolean result = permissionData.getPermissionValue(node.getNode()).asBoolean();
|
||||
|
||||
luckPermsApi.cleanupUser(user);
|
||||
return result;
|
||||
CachedPermissionData permissionData = user.getCachedData()
|
||||
.getPermissionData(QueryOptions.builder(QueryMode.NON_CONTEXTUAL).build());
|
||||
return permissionData.checkPermission(node.getNode()).asBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(OfflinePlayer player, String group) {
|
||||
User user = luckPermsApi.getUser(player.getName());
|
||||
String playerName = player.getName();
|
||||
if (playerName == null) {
|
||||
return false;
|
||||
}
|
||||
User user = luckPerms.getUserManager().getUser(playerName);
|
||||
if (user == null) {
|
||||
logger.warning("LuckPermsHandler: tried to check group for offline user "
|
||||
+ player.getName() + " but it isn't loaded!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Group permissionGroup = luckPermsApi.getGroup(group);
|
||||
boolean result = permissionGroup != null && user.inheritsGroup(permissionGroup);
|
||||
|
||||
luckPermsApi.cleanupUser(user);
|
||||
return result;
|
||||
InheritanceNode inheritanceNode = InheritanceNode.builder(group).build();
|
||||
return user.data().contains(inheritanceNode, NodeEqualityPredicate.EXACT).asBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(OfflinePlayer player, String group) {
|
||||
User user = luckPermsApi.getUser(player.getName());
|
||||
String playerName = player.getName();
|
||||
if (playerName == null) {
|
||||
return false;
|
||||
}
|
||||
User user = luckPerms.getUserManager().getUser(playerName);
|
||||
if (user == null) {
|
||||
logger.warning("LuckPermsHandler: tried to remove group for offline user "
|
||||
+ player.getName() + " but it isn't loaded!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Group permissionGroup = luckPermsApi.getGroup(group);
|
||||
if (permissionGroup == null) {
|
||||
return false;
|
||||
}
|
||||
InheritanceNode groupNode = InheritanceNode.builder(group).build();
|
||||
boolean result = user.data().remove(groupNode) != DataMutateResult.FAIL;
|
||||
|
||||
Node groupNode = luckPermsApi.getNodeFactory().makeGroupNode(permissionGroup).build();
|
||||
boolean result = user.unsetPermission(groupNode) != DataMutateResult.FAIL;
|
||||
|
||||
luckPermsApi.cleanupUser(user);
|
||||
luckPerms.getUserManager().saveUser(user);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(OfflinePlayer player, String group) {
|
||||
User user = luckPermsApi.getUser(player.getName());
|
||||
String playerName = player.getName();
|
||||
if (playerName == null) {
|
||||
return false;
|
||||
}
|
||||
User user = luckPerms.getUserManager().getUser(playerName);
|
||||
if (user == null) {
|
||||
logger.warning("LuckPermsHandler: tried to set group for offline user "
|
||||
+ player.getName() + " but it isn't loaded!");
|
||||
return false;
|
||||
}
|
||||
Group permissionGroup = luckPermsApi.getGroup(group);
|
||||
if (permissionGroup == null) {
|
||||
return false;
|
||||
}
|
||||
Node groupNode = luckPermsApi.getNodeFactory().makeGroupNode(permissionGroup).build();
|
||||
DataMutateResult result = user.setPermission(groupNode);
|
||||
InheritanceNode groupNode = InheritanceNode.builder(group).build();
|
||||
DataMutateResult result = user.data().add(groupNode);
|
||||
if (result == DataMutateResult.FAIL) {
|
||||
return false;
|
||||
}
|
||||
user.clearMatching(node -> node.isGroupNode() && !node.getGroupName().equals(permissionGroup.getName()));
|
||||
user.data().clear(node -> {
|
||||
if (!(node instanceof InheritanceNode)) {
|
||||
return false;
|
||||
}
|
||||
InheritanceNode inheritanceNode = (InheritanceNode) node;
|
||||
return !inheritanceNode.equals(groupNode);
|
||||
});
|
||||
|
||||
saveUser(user);
|
||||
luckPermsApi.cleanupUser(user);
|
||||
luckPerms.getUserManager().saveUser(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(OfflinePlayer player) {
|
||||
User user = luckPermsApi.getUser(player.getName());
|
||||
String playerName = player.getName();
|
||||
if (playerName == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
User user = luckPerms.getUserManager().getUser(playerName);
|
||||
if (user == null) {
|
||||
logger.warning("LuckPermsHandler: tried to get groups for offline user "
|
||||
+ player.getName() + " but it isn't loaded!");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> result = user.getOwnNodes().stream()
|
||||
.filter(Node::isGroupNode)
|
||||
.map(n -> luckPermsApi.getGroupSafe(n.getGroupName()))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.distinct()
|
||||
return user.getDistinctNodes().stream()
|
||||
.filter(node -> node instanceof InheritanceNode)
|
||||
.map(node -> (InheritanceNode) node)
|
||||
.map(node -> luckPerms.getGroupManager().getGroup(node.getGroupName()))
|
||||
.filter(Objects::nonNull)
|
||||
.sorted((o1, o2) -> {
|
||||
if (o1.getName().equals(user.getPrimaryGroup()) || o2.getName().equals(user.getPrimaryGroup())) {
|
||||
return o1.getName().equals(user.getPrimaryGroup()) ? 1 : -1;
|
||||
@ -180,9 +183,6 @@ public class LuckPermsHandler implements PermissionHandler {
|
||||
})
|
||||
.map(Group::getName)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
luckPermsApi.cleanupUser(user);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,7 +193,7 @@ public class LuckPermsHandler implements PermissionHandler {
|
||||
@Override
|
||||
public void loadUserData(UUID uuid) throws PermissionLoadUserException {
|
||||
try {
|
||||
luckPermsApi.getUserManager().loadUser(uuid).get(5, TimeUnit.SECONDS);
|
||||
luckPerms.getUserManager().loadUser(uuid).get(5, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
throw new PermissionLoadUserException("Unable to load the permission data of the user " + uuid, e);
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import fr.xephi.authme.permission.handlers.VaultHandler;
|
||||
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import me.lucko.luckperms.LuckPerms;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
@ -162,8 +162,8 @@ public class PermissionsManagerInitializationTest {
|
||||
|
||||
private void setUpForPermissionSystemTest() {
|
||||
if (permissionsSystemType == LUCK_PERMS) {
|
||||
LuckPermsApi api = mock(LuckPermsApi.class);
|
||||
ReflectionTestUtils.setField(LuckPerms.class, null, "instance", api);
|
||||
LuckPerms api = mock(LuckPerms.class);
|
||||
ReflectionTestUtils.setField(LuckPermsProvider.class, null, "instance", api);
|
||||
} else if (permissionsSystemType == PERMISSIONS_EX) {
|
||||
throw new AssumptionViolatedException(
|
||||
"PermissionsEx instance cannot be mocked because of missing dependencies -- skipping");
|
||||
|
Loading…
Reference in New Issue
Block a user