From 9dc2278083ece2ad79f1e0c7dfd394a0e1aee970 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 11 Mar 2017 21:10:27 +0000 Subject: [PATCH] Cleanup a bit --- .../me/lucko/luckperms/api/MetaUtils.java | 3 +- .../luckperms/bukkit/vault/VaultChatHook.java | 34 +++---------------- .../generic/meta/MetaRemovePrefix.java | 7 +--- .../generic/meta/MetaRemoveSuffix.java | 7 +--- .../generic/meta/MetaRemoveTempPrefix.java | 6 +--- .../generic/meta/MetaRemoveTempSuffix.java | 7 +--- .../common/core/model/PermissionHolder.java | 14 ++++++++ 7 files changed, 23 insertions(+), 55 deletions(-) diff --git a/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java b/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java index 75caf463..481d68fb 100644 --- a/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java +++ b/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java @@ -135,8 +135,7 @@ public class MetaUtils { for (Node n : toRemove) { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) { - } + } catch (ObjectLacksException ignored) {} } Node.Builder metaNode = LuckPerms.getApi().buildNode("meta." + node + "." + value).setValue(true); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java index 771a7b2c..57e692f5 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java @@ -34,15 +34,11 @@ import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.ExtractedContexts; -import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import me.lucko.luckperms.exceptions.ObjectLacksException; import net.milkbowl.vault.chat.Chat; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static me.lucko.luckperms.api.MetaUtils.escapeCharacters; import static me.lucko.luckperms.api.MetaUtils.unescapeCharacters; @@ -75,15 +71,7 @@ public class VaultChatHook extends Chat { perms.log("Setting meta: '" + node + "' for " + holder.getObjectName() + " on world " + world + ", server " + perms.getServer()); perms.getScheduler().execute(() -> { - List toRemove = holder.getNodes().stream() - .filter(n -> n.isMeta() && n.getMeta().getKey().equals(node)) - .collect(Collectors.toList()); - - toRemove.forEach(n -> { - try { - holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} - }); + holder.removeIf(n -> n.isMeta() && n.getMeta().getKey().equals(node)); Node.Builder metaNode = NodeFactory.makeMetaNode(node, value).setValue(true); if (!perms.getServer().equalsIgnoreCase("global")) { @@ -93,10 +81,7 @@ public class VaultChatHook extends Chat { metaNode.setWorld(finalWorld); } - try { - holder.setPermission(metaNode.build()); - } catch (ObjectAlreadyHasException ignored) {} - + holder.setPermissionUnchecked(metaNode.build()); perms.save(holder); }); } @@ -111,15 +96,7 @@ public class VaultChatHook extends Chat { perms.getScheduler().execute(() -> { // remove all prefixes/suffixes directly set on the user/group - List toRemove = holder.getNodes().stream() - .filter(n -> prefix ? n.isPrefix() : n.isSuffix()) - .collect(Collectors.toList()); - - toRemove.forEach(n -> { - try { - holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} - }); + holder.removeIf(n -> prefix ? n.isPrefix() : n.isSuffix()); // find the max inherited priority & add 10 MetaHolder metaHolder = holder.accumulateMeta(null, null, ExtractedContexts.generate(perms.createContextForWorld(finalWorld))); @@ -134,10 +111,7 @@ public class VaultChatHook extends Chat { chatMetaNode.setWorld(finalWorld); } - try { - holder.setPermission(chatMetaNode.build()); - } catch (ObjectAlreadyHasException ignored) {} - + holder.setPermissionUnchecked(chatMetaNode.build()); perms.save(holder); }); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java index b04fd106..0d56f160 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java @@ -88,12 +88,7 @@ public class MetaRemovePrefix extends SharedSubCommand { toRemove.add(node); } - toRemove.forEach(n -> { - try { - holder.unsetPermission(n); - } catch (ObjectLacksException ignored) { - } - }); + toRemove.forEach(holder::unsetPermissionUnchecked); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); save(holder, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java index fb0b8a34..28229a35 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java @@ -88,12 +88,7 @@ public class MetaRemoveSuffix extends SharedSubCommand { toRemove.add(node); } - toRemove.forEach(n -> { - try { - holder.unsetPermission(n); - } catch (ObjectLacksException ignored) { - } - }); + toRemove.forEach(holder::unsetPermissionUnchecked); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); save(holder, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java index ab14a3bc..ae5139d1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java @@ -88,11 +88,7 @@ public class MetaRemoveTempPrefix extends SharedSubCommand { toRemove.add(node); } - toRemove.forEach(n -> { - try { - holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} - }); + toRemove.forEach(holder::unsetPermissionUnchecked); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); save(holder, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java index cc4004c9..dbfded0b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java @@ -88,12 +88,7 @@ public class MetaRemoveTempSuffix extends SharedSubCommand { toRemove.add(node); } - toRemove.forEach(n -> { - try { - holder.unsetPermission(n); - } catch (ObjectLacksException ignored) { - } - }); + toRemove.forEach(holder::unsetPermissionUnchecked); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); save(holder, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index 3af11358..1cfc3803 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -438,6 +438,20 @@ public abstract class PermissionHolder { invalidateCache(false); } + public boolean removeIfTransient(Predicate predicate) { + boolean result; + + synchronized (nodes) { + result = transientNodes.removeIf(predicate); + } + + if (result) { + invalidateCache(false); + } + + return result; + } + /** * Combines and returns this holders nodes in a priority order. *