Use the latest LuckPerms api methods

This commit is contained in:
Gabriele C 2018-03-20 10:42:17 +01:00
parent a1a909c01d
commit 6251a69d3e

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.permission.handlers; package fr.xephi.authme.permission.handlers;
import fr.xephi.authme.ConsoleLogger;
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 me.lucko.luckperms.LuckPerms; import me.lucko.luckperms.LuckPerms;
@ -41,13 +42,8 @@ public class LuckPermsHandler implements PermissionHandler {
} }
private void saveUser(User user) { private void saveUser(User user) {
luckPermsApi.getStorage().saveUser(user) luckPermsApi.getUserManager().saveUser(user)
.thenAcceptAsync(wasSuccessful -> { .thenAcceptAsync(wasSuccessful -> user.refreshCachedData());
if (!wasSuccessful) {
return;
}
user.refreshPermissions();
}, luckPermsApi.getStorage().getAsyncExecutor());
} }
@Override @Override
@ -62,7 +58,7 @@ public class LuckPermsHandler implements PermissionHandler {
return false; return false;
} }
DataMutateResult result = user.setPermissionUnchecked( DataMutateResult result = user.setPermission(
luckPermsApi.getNodeFactory().makeGroupNode(newGroup).build()); luckPermsApi.getNodeFactory().makeGroupNode(newGroup).build());
if (result == DataMutateResult.FAIL) { if (result == DataMutateResult.FAIL) {
return false; return false;
@ -83,6 +79,8 @@ public class LuckPermsHandler implements PermissionHandler {
public boolean hasPermissionOffline(String name, PermissionNode node) { public boolean hasPermissionOffline(String name, PermissionNode node) {
User user = luckPermsApi.getUser(name); User user = luckPermsApi.getUser(name);
if (user == null) { if (user == null) {
ConsoleLogger.warning("LuckPermsHandler: tried to check permission for offline user "
+ name + " but it isn't loaded!");
return false; return false;
} }
@ -98,6 +96,8 @@ public class LuckPermsHandler implements PermissionHandler {
public boolean isInGroup(OfflinePlayer player, String group) { public boolean isInGroup(OfflinePlayer player, String group) {
User user = luckPermsApi.getUser(player.getName()); User user = luckPermsApi.getUser(player.getName());
if (user == null) { if (user == null) {
ConsoleLogger.warning("LuckPermsHandler: tried to check group for offline user "
+ player.getName() + " but it isn't loaded!");
return false; return false;
} }
@ -112,6 +112,8 @@ public class LuckPermsHandler implements PermissionHandler {
public boolean removeFromGroup(OfflinePlayer player, String group) { public boolean removeFromGroup(OfflinePlayer player, String group) {
User user = luckPermsApi.getUser(player.getName()); User user = luckPermsApi.getUser(player.getName());
if (user == null) { if (user == null) {
ConsoleLogger.warning("LuckPermsHandler: tried to remove group for offline user "
+ player.getName() + " but it isn't loaded!");
return false; return false;
} }
@ -121,7 +123,7 @@ public class LuckPermsHandler implements PermissionHandler {
} }
Node groupNode = luckPermsApi.getNodeFactory().makeGroupNode(permissionGroup).build(); Node groupNode = luckPermsApi.getNodeFactory().makeGroupNode(permissionGroup).build();
boolean result = user.unsetPermissionUnchecked(groupNode) != DataMutateResult.FAIL; boolean result = user.unsetPermission(groupNode) != DataMutateResult.FAIL;
luckPermsApi.cleanupUser(user); luckPermsApi.cleanupUser(user);
return result; return result;
@ -131,6 +133,8 @@ public class LuckPermsHandler implements PermissionHandler {
public boolean setGroup(OfflinePlayer player, String group) { public boolean setGroup(OfflinePlayer player, String group) {
User user = luckPermsApi.getUser(player.getName()); User user = luckPermsApi.getUser(player.getName());
if (user == null) { if (user == null) {
ConsoleLogger.warning("LuckPermsHandler: tried to set group for offline user "
+ player.getName() + " but it isn't loaded!");
return false; return false;
} }
Group permissionGroup = luckPermsApi.getGroup(group); Group permissionGroup = luckPermsApi.getGroup(group);
@ -138,7 +142,7 @@ public class LuckPermsHandler implements PermissionHandler {
return false; return false;
} }
Node groupNode = luckPermsApi.getNodeFactory().makeGroupNode(permissionGroup).build(); Node groupNode = luckPermsApi.getNodeFactory().makeGroupNode(permissionGroup).build();
DataMutateResult result = user.setPermissionUnchecked(groupNode); DataMutateResult result = user.setPermission(groupNode);
if (result == DataMutateResult.FAIL) { if (result == DataMutateResult.FAIL) {
return false; return false;
} }
@ -153,6 +157,8 @@ public class LuckPermsHandler implements PermissionHandler {
public List<String> getGroups(OfflinePlayer player) { public List<String> getGroups(OfflinePlayer player) {
User user = luckPermsApi.getUser(player.getName()); User user = luckPermsApi.getUser(player.getName());
if (user == null) { if (user == null) {
ConsoleLogger.warning("LuckPermsHandler: tried to get groups for offline user "
+ player.getName() + " but it isn't loaded!");
return Collections.emptyList(); return Collections.emptyList();
} }
@ -185,7 +191,7 @@ public class LuckPermsHandler implements PermissionHandler {
@Override @Override
public void loadUserData(UUID uuid) { public void loadUserData(UUID uuid) {
try { try {
luckPermsApi.getStorage().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(); e.printStackTrace();
} }