diff --git a/README.md b/README.md index 3a09d94e..ded805bb 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,7 @@ Example: if a user has a global "fly.use" permission, and then has a negated "fl Example: A user is a member of the default group, which grants "some.thing.perm", but the users own permissions has "some.thing.perm" set to false. The inherited permission will be overridden by the users own permissions, and the user will be granted the negative node. ### Temporary Permissions -Temporary permissions are checked each time a user/group is loaded, and when the sync task runs. This means if you set a temporary permission to expire after 30 seconds, it won't actually be removed until the sync task runs. - -The only way around this is to decrease the sync interval. +Temporary permissions are audited once every 3 seconds, to check if they have expired. This check happens regardless of the sync interval setting. This means that you can safely set temporary permissions to expire after a matter of seconds, and they will be removed on-time. ### Shorthand Permissions LuckPerms has it's own system (although it's quite similar to PermissionsEx :P) that allows you to set permissions in a shorthand format. diff --git a/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java index b3171051..b3a464a4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/LPBukkitPlugin.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.core.LPConfiguration; import me.lucko.luckperms.core.UuidCache; import me.lucko.luckperms.data.Importer; import me.lucko.luckperms.groups.GroupManager; +import me.lucko.luckperms.runnables.ExpireTemporaryTask; import me.lucko.luckperms.runnables.UpdateTask; import me.lucko.luckperms.storage.Datastore; import me.lucko.luckperms.storage.StorageFactory; @@ -81,7 +82,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { main.setTabCompleter(commandManager); main.setAliases(Arrays.asList("perms", "lp", "permissions", "p", "perm")); - datastore = StorageFactory.getDatastore(this, "sqlite"); + datastore = StorageFactory.getDatastore(this, "h2"); getLog().info("Loading internal permission managers..."); uuidCache = new UuidCache(getConfiguration().getOnlineMode()); @@ -105,6 +106,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } getServer().getScheduler().runTaskTimer(this, BukkitSenderFactory.get(), 1L, 1L); + getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L); // Provide vault support getLog().info("Attempting to hook into Vault..."); diff --git a/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java index 3671b615..c7dc87ca 100644 --- a/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/LPBungeePlugin.java @@ -32,6 +32,7 @@ import me.lucko.luckperms.core.LPConfiguration; import me.lucko.luckperms.core.UuidCache; import me.lucko.luckperms.data.Importer; import me.lucko.luckperms.groups.GroupManager; +import me.lucko.luckperms.runnables.ExpireTemporaryTask; import me.lucko.luckperms.runnables.UpdateTask; import me.lucko.luckperms.storage.Datastore; import me.lucko.luckperms.storage.StorageFactory; @@ -101,6 +102,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { // 20 times per second (once per "tick") getProxy().getScheduler().schedule(this, BungeeSenderFactory.get(), 50L, 50L, TimeUnit.MILLISECONDS); + getProxy().getScheduler().schedule(this, new ExpireTemporaryTask(this), 3L, 3L, TimeUnit.SECONDS); getLog().info("Registering API..."); LuckPerms.registerProvider(new ApiProvider(this)); diff --git a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java index 4888b6b3..1a35f583 100644 --- a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java @@ -468,12 +468,16 @@ public abstract class PermissionHolder { /** * Removes temporary permissions that have expired + * @return true if permissions had expired and were removed */ - public void auditTemporaryPermissions() { - this.nodes.keySet().stream() + public boolean auditTemporaryPermissions() { + List toExpire = this.nodes.keySet().stream() .filter(s -> s.contains("$")) .filter(s -> DateUtil.shouldExpire(Long.parseLong(Patterns.TEMP_DELIMITER.split(s)[1]))) - .forEach(s -> this.nodes.remove(s)); + .collect(Collectors.toList()); + + toExpire.forEach(s -> this.nodes.remove(s)); + return !toExpire.isEmpty(); } private Map convertTemporaryPerms() { diff --git a/common/src/main/java/me/lucko/luckperms/runnables/ExpireTemporaryTask.java b/common/src/main/java/me/lucko/luckperms/runnables/ExpireTemporaryTask.java new file mode 100644 index 00000000..e8f5def6 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/runnables/ExpireTemporaryTask.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.runnables; + +import lombok.AllArgsConstructor; +import me.lucko.luckperms.LuckPermsPlugin; +import me.lucko.luckperms.core.PermissionHolder; +import me.lucko.luckperms.groups.Group; +import me.lucko.luckperms.users.User; + +@AllArgsConstructor +public class ExpireTemporaryTask implements Runnable { + private final LuckPermsPlugin plugin; + + @Override + public void run() { + boolean changes = false; + for (Group group : plugin.getGroupManager().getAll().values()) { + if (group.auditTemporaryPermissions()) { + changes = true; + } + } + + if (changes) { + plugin.runUpdateTask(); + return; + } + + plugin.getUserManager().getAll().values().stream() + .filter(PermissionHolder::auditTemporaryPermissions) + .forEach(User::refreshPermissions); + } +} \ No newline at end of file diff --git a/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java index bbad99be..0e77c9ab 100644 --- a/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/LPSpongePlugin.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.core.LPConfiguration; import me.lucko.luckperms.core.UuidCache; import me.lucko.luckperms.data.Importer; import me.lucko.luckperms.groups.GroupManager; +import me.lucko.luckperms.runnables.ExpireTemporaryTask; import me.lucko.luckperms.runnables.UpdateTask; import me.lucko.luckperms.storage.Datastore; import me.lucko.luckperms.storage.StorageFactory; @@ -128,6 +129,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { } scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get()).submit(this); + scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this); getLog().info("Registering API..."); final ApiProvider provider = new ApiProvider(this);