Check temporary permissions separately to the sync task

This commit is contained in:
Luck
2016-08-19 19:10:36 +01:00
Unverified
parent a15a0752f4
commit 0c12eebe6f
6 changed files with 68 additions and 7 deletions
@@ -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<String> 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<String, Boolean> convertTemporaryPerms() {
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* 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);
}
}