diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/AbstractVaultPermission.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/AbstractVaultPermission.java index e22b3a1b5..fdce348aa 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/AbstractVaultPermission.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/AbstractVaultPermission.java @@ -79,6 +79,8 @@ public abstract class AbstractVaultPermission extends Permission { public abstract boolean userHasPermission(String world, UUID uuid, String permission); public abstract boolean userAddPermission(String world, UUID uuid, String permission); public abstract boolean userRemovePermission(String world, UUID uuid, String permission); + public abstract boolean userAddTransient(String world, UUID uuid, String permission); + public abstract boolean userRemoveTransient(String world, UUID uuid, String permission); public abstract boolean userInGroup(String world, UUID uuid, String group); public abstract boolean userAddGroup(String world, UUID uuid, String group); public abstract boolean userRemoveGroup(String world, UUID uuid, String group); @@ -181,7 +183,7 @@ public abstract class AbstractVaultPermission extends Permission { public final boolean playerAdd(Player player, String permission) { Objects.requireNonNull(player, "player"); Objects.requireNonNull(permission, "permission"); - return userAddPermission(convertWorld(player), ((OfflinePlayer) player).getUniqueId(), permission); + return userAddPermission(convertWorld(player), player.getUniqueId(), permission); } @Override @@ -209,7 +211,63 @@ public abstract class AbstractVaultPermission extends Permission { public final boolean playerRemove(Player player, String permission) { Objects.requireNonNull(player, "player"); Objects.requireNonNull(permission, "permission"); - return userRemovePermission(convertWorld(player), ((OfflinePlayer) player).getUniqueId(), permission); + return userRemovePermission(convertWorld(player), player.getUniqueId(), permission); + } + + @Override + public boolean playerAddTransient(OfflinePlayer player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userAddTransient(null, player.getUniqueId(), permission); + } + + @Override + public final boolean playerAddTransient(Player player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userAddTransient(convertWorld(player), player.getUniqueId(), permission); + } + + @Override + public final boolean playerAddTransient(String world, OfflinePlayer player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userAddTransient(convertWorld(world), player.getUniqueId(), permission); + } + + @Override + public final boolean playerAddTransient(String world, Player player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userAddTransient(convertWorld(world), player.getUniqueId(), permission); + } + + @Override + public boolean playerRemoveTransient(OfflinePlayer player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userRemoveTransient(null, player.getUniqueId(), permission); + } + + @Override + public final boolean playerRemoveTransient(Player player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userRemoveTransient(convertWorld(player), player.getUniqueId(), permission); + } + + @Override + public final boolean playerRemoveTransient(String world, OfflinePlayer player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userRemoveTransient(convertWorld(world), player.getUniqueId(), permission); + } + + @Override + public final boolean playerRemoveTransient(String world, Player player, String permission) { + Objects.requireNonNull(player, "player"); + Objects.requireNonNull(permission, "permission"); + return userRemoveTransient(convertWorld(world), player.getUniqueId(), permission); } @Override @@ -279,7 +337,7 @@ public abstract class AbstractVaultPermission extends Permission { public final boolean playerInGroup(Player player, String group) { Objects.requireNonNull(player, "player"); Objects.requireNonNull(group, "group"); - return userInGroup(convertWorld(player), ((OfflinePlayer) player).getUniqueId(), group); + return userInGroup(convertWorld(player), player.getUniqueId(), group); } @Override @@ -307,7 +365,7 @@ public abstract class AbstractVaultPermission extends Permission { public final boolean playerAddGroup(Player player, String group) { Objects.requireNonNull(player, "player"); Objects.requireNonNull(group, "group"); - return userAddGroup(convertWorld(player), ((OfflinePlayer) player).getUniqueId(), group); + return userAddGroup(convertWorld(player), player.getUniqueId(), group); } @Override @@ -334,7 +392,7 @@ public abstract class AbstractVaultPermission extends Permission { @Override public final boolean playerRemoveGroup(Player player, String group) { Objects.requireNonNull(player, "player"); - return userRemoveGroup(convertWorld(player), ((OfflinePlayer) player).getUniqueId(), group); + return userRemoveGroup(convertWorld(player), player.getUniqueId(), group); } @Override @@ -358,7 +416,7 @@ public abstract class AbstractVaultPermission extends Permission { @Override public final String[] getPlayerGroups(Player player) { Objects.requireNonNull(player, "player"); - return userGetGroups(convertWorld(player), ((OfflinePlayer) player).getUniqueId()); + return userGetGroups(convertWorld(player), player.getUniqueId()); } @Override @@ -382,7 +440,7 @@ public abstract class AbstractVaultPermission extends Permission { @Override public final String getPrimaryGroup(Player player) { Objects.requireNonNull(player, "player"); - return userGetPrimaryGroup(convertWorld(player), ((OfflinePlayer) player).getUniqueId()); + return userGetPrimaryGroup(convertWorld(player), player.getUniqueId()); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java index 8c189c5ac..5776a182a 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java @@ -186,7 +186,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { if (user instanceof Group) { throw new UnsupportedOperationException("Unable to modify the permissions of NPC players"); } - return holderAddPermission(user, permission, world); + return holderAddPermission(user, permission, world, DataType.NORMAL); } @Override @@ -198,7 +198,31 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { if (user instanceof Group) { throw new UnsupportedOperationException("Unable to modify the permissions of NPC players"); } - return holderRemovePermission(user, permission, world); + return holderRemovePermission(user, permission, world, DataType.NORMAL); + } + + @Override + public boolean userAddTransient(String world, UUID uuid, String permission) { + Objects.requireNonNull(uuid, "uuid"); + Objects.requireNonNull(permission, "permission"); + + PermissionHolder user = lookupUser(uuid); + if (user instanceof Group) { + throw new UnsupportedOperationException("Unable to modify the permissions of NPC players"); + } + return holderAddPermission(user, permission, world, DataType.TRANSIENT); + } + + @Override + public boolean userRemoveTransient(String world, UUID uuid, String permission) { + Objects.requireNonNull(uuid, "uuid"); + Objects.requireNonNull(permission, "permission"); + + PermissionHolder user = lookupUser(uuid); + if (user instanceof Group) { + throw new UnsupportedOperationException("Unable to modify the permissions of NPC players"); + } + return holderRemovePermission(user, permission, world, DataType.TRANSIENT); } @Override @@ -288,7 +312,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { return false; } - return holderAddPermission(group, permission, world); + return holderAddPermission(group, permission, world, DataType.NORMAL); } @Override @@ -301,7 +325,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { return false; } - return holderRemovePermission(group, permission, world); + return holderRemovePermission(group, permission, world, DataType.NORMAL); } // utility methods for getting user and group instances @@ -387,7 +411,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { // utility methods for modifying the state of PermissionHolders - private boolean holderAddPermission(PermissionHolder holder, String permission, String world) { + private boolean holderAddPermission(PermissionHolder holder, String permission, String world, DataType type) { Objects.requireNonNull(permission, "permission is null"); Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string"); @@ -396,13 +420,13 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { .withContext(DefaultContextKeys.WORLD_KEY, world == null ? "global" : world) .build(); - if (holder.setNode(DataType.NORMAL, node, true).wasSuccessful()) { + if (holder.setNode(type, node, true).wasSuccessful()) { return holderSave(holder); } return false; } - private boolean holderRemovePermission(PermissionHolder holder, String permission, String world) { + private boolean holderRemovePermission(PermissionHolder holder, String permission, String world, DataType type) { Objects.requireNonNull(permission, "permission is null"); Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string"); @@ -411,7 +435,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { .withContext(DefaultContextKeys.WORLD_KEY, world == null ? "global" : world) .build(); - if (holder.unsetNode(DataType.NORMAL, node).wasSuccessful()) { + if (holder.unsetNode(type, node).wasSuccessful()) { return holderSave(holder); } return false; @@ -460,4 +484,5 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { private boolean useVaultServer() { return this.plugin.getConfiguration().get(ConfigKeys.USE_VAULT_SERVER); } + }