Throw exception earlier if an invalid permission is added/removed via Vault (#526)

This commit is contained in:
Luck 2017-11-07 15:22:31 +00:00
parent 76bfde4d77
commit f1a50f433f
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -28,8 +28,9 @@ package me.lucko.luckperms.bukkit.vault;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import com.google.common.base.Preconditions;
import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.DataMutateResult;
import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet;
@ -419,36 +420,26 @@ public class VaultPermissionHook extends Permission {
// utility methods for modifying the state of PermissionHolders // utility methods for modifying the state of PermissionHolders
private void holderAddPermission(PermissionHolder holder, String permission, String world) { private void holderAddPermission(PermissionHolder holder, String permission, String world) {
Preconditions.checkNotNull(permission, "permission is null");
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
executor.execute(() -> { executor.execute(() -> {
DataMutateResult result; if (holder.setPermission(NodeFactory.make(permission, true, getServer(), world)).asBoolean()) {
if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) {
result = holder.setPermission(NodeFactory.make(permission, true, getServer(), world));
} else {
result = holder.setPermission(NodeFactory.make(permission, true, getServer()));
}
if (result.asBoolean()) {
holderSave(holder); holderSave(holder);
} }
}); });
} }
private void holderRemovePermission(PermissionHolder holder, String permission, String world) { private void holderRemovePermission(PermissionHolder holder, String permission, String world) {
Preconditions.checkNotNull(permission, "permission is null");
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
executor.execute(() -> { executor.execute(() -> {
DataMutateResult result; if (holder.unsetPermission(NodeFactory.make(permission, getServer(), world)).asBoolean()) {
if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) {
result = holder.unsetPermission(NodeFactory.make(permission, getServer(), world));
} else {
result = holder.unsetPermission(NodeFactory.make(permission, getServer()));
}
if (result.asBoolean()) {
holderSave(holder); holderSave(holder);
} }
}); });
} }
public void holderSave(PermissionHolder holder) { void holderSave(PermissionHolder holder) {
if (holder instanceof User) { if (holder instanceof User) {
User u = (User) holder; User u = (User) holder;
plugin.getStorage().saveUser(u).thenRunAsync(() -> u.getRefreshBuffer().request(), plugin.getScheduler().async()); plugin.getStorage().saveUser(u).thenRunAsync(() -> u.getRefreshBuffer().request(), plugin.getScheduler().async());