diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java index 9de3884e..66bc55bc 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.bukkit.calculators.AttachmentProcessor; import me.lucko.luckperms.bukkit.calculators.ChildProcessor; import me.lucko.luckperms.bukkit.calculators.DefaultsProcessor; -import me.lucko.luckperms.bukkit.inject.Injector; +import me.lucko.luckperms.bukkit.model.Injector; import me.lucko.luckperms.bukkit.model.LPPermissible; import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory; import me.lucko.luckperms.common.calculators.PermissionCalculator; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java index c44b7910..6ff66de2 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java @@ -22,7 +22,7 @@ package me.lucko.luckperms.bukkit; -import me.lucko.luckperms.bukkit.inject.Injector; +import me.lucko.luckperms.bukkit.model.Injector; import me.lucko.luckperms.bukkit.model.LPPermissible; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.constants.Message; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 13607263..dba085af 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -32,11 +32,11 @@ import me.lucko.luckperms.api.LuckPermsApi; import me.lucko.luckperms.api.PlatformType; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.MutableContextSet; -import me.lucko.luckperms.bukkit.inject.Injector; import me.lucko.luckperms.bukkit.messaging.BungeeMessagingService; import me.lucko.luckperms.bukkit.messaging.LilyPadMessagingService; import me.lucko.luckperms.bukkit.model.ChildPermissionProvider; import me.lucko.luckperms.bukkit.model.DefaultsProvider; +import me.lucko.luckperms.bukkit.model.Injector; import me.lucko.luckperms.bukkit.model.LPPermissible; import me.lucko.luckperms.bukkit.vault.VaultHook; import me.lucko.luckperms.common.api.ApiHandler; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java index 139b34f6..6dc0287d 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java @@ -36,6 +36,27 @@ import java.util.Map; public class ChildPermissionProvider { + @Getter + private ImmutableMap, ImmutableMap> permissions = ImmutableMap.of(); + + public void setup() { + Map, ImmutableMap> permissions = new HashMap<>(); + + for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) { + // handle true + Map trueChildren = new HashMap<>(); + resolveChildren(trueChildren, Collections.singletonMap(permission.getName(), true), false); + permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(trueChildren)); + + // handle false + Map falseChildren = new HashMap<>(); + resolveChildren(falseChildren, Collections.singletonMap(permission.getName(), false), false); + permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false), ImmutableMap.copyOf(falseChildren)); + } + + this.permissions = ImmutableMap.copyOf(permissions); + } + private static void resolveChildren(Map accumulator, Map children, boolean invert) { for (Map.Entry e : children.entrySet()) { if (accumulator.containsKey(e.getKey())) { @@ -53,25 +74,4 @@ public class ChildPermissionProvider { } } } - - @Getter - private ImmutableMap, ImmutableMap> permissions = ImmutableMap.of(); - - public void setup() { - Map, ImmutableMap> permissions = new HashMap<>(); - - for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) { - // handle true - Map children = new HashMap<>(); - resolveChildren(children, Collections.singletonMap(permission.getName(), true), false); - permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(children)); - - // handle false - Map nChildren = new HashMap<>(); - resolveChildren(nChildren, Collections.singletonMap(permission.getName(), false), false); - permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false), ImmutableMap.copyOf(nChildren)); - } - - this.permissions = ImmutableMap.copyOf(permissions); - } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java index f562e0de..b42df489 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java @@ -22,7 +22,6 @@ package me.lucko.luckperms.bukkit.model; -import lombok.AllArgsConstructor; import lombok.Getter; import com.google.common.collect.ImmutableMap; @@ -30,57 +29,14 @@ import com.google.common.collect.ImmutableMap; import me.lucko.luckperms.api.Tristate; import org.bukkit.Bukkit; -import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.permissions.PermissionAttachmentInfo; -import org.bukkit.plugin.Plugin; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; public class DefaultsProvider { - private static void unregisterDefaults(Map map, DummyPermissible p) { - Set perms = map.keySet(); - - for (String name : perms) { - Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, p); - } - - Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, p); - Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, p); - } - - private static void calculateDefaults(Map map, DummyPermissible p, boolean op) { - Set defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(op); - Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(op, p); - - for (Permission perm : defaults) { - String name = perm.getName().toLowerCase(); - map.put(name, true); - Bukkit.getServer().getPluginManager().subscribeToPermission(name, p); - calculateChildPermissions(map, p, perm.getChildren(), false); - } - } - - private static void calculateChildPermissions(Map map, DummyPermissible p, Map children, boolean invert) { - for (Map.Entry e : children.entrySet()) { - Permission perm = Bukkit.getServer().getPluginManager().getPermission(e.getKey()); - boolean value = e.getValue() ^ invert; - String lName = e.getKey().toLowerCase(); - - map.put(lName, value); - Bukkit.getServer().getPluginManager().subscribeToPermission(e.getKey(), p); - - if (perm != null) { - calculateChildPermissions(map, p, perm.getChildren(), !value); - } - } - } - @Getter private Map opDefaults = ImmutableMap.of(); private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp); @@ -128,73 +84,41 @@ public class DefaultsProvider { return opDefaults.size() + nonOpDefaults.size(); } - @AllArgsConstructor - private static class DummyPermissible implements Permissible { - private final Runnable onRefresh; + private static void unregisterDefaults(Map map, DummyPermissible p) { + Set perms = map.keySet(); - @Override - public void recalculatePermissions() { - onRefresh.run(); + for (String name : perms) { + Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, p); } - @Override - public Set getEffectivePermissions() { - return Collections.emptySet(); + Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, p); + Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, p); + } + + private static void calculateDefaults(Map map, DummyPermissible p, boolean op) { + Set defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(op); + Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(op, p); + + for (Permission perm : defaults) { + String name = perm.getName().toLowerCase(); + map.put(name, true); + Bukkit.getServer().getPluginManager().subscribeToPermission(name, p); + calculateChildPermissions(map, p, perm.getChildren(), false); } + } - @Override - public boolean isPermissionSet(String name) { - return false; - } + private static void calculateChildPermissions(Map map, DummyPermissible p, Map children, boolean invert) { + for (Map.Entry e : children.entrySet()) { + Permission perm = Bukkit.getServer().getPluginManager().getPermission(e.getKey()); + boolean value = e.getValue() ^ invert; + String lName = e.getKey().toLowerCase(); - @Override - public boolean isPermissionSet(Permission perm) { - return false; - } - - @Override - public boolean hasPermission(String name) { - return false; - } - - @Override - public boolean hasPermission(Permission perm) { - return false; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { - return null; - } - - @Override - public PermissionAttachment addAttachment(Plugin plugin, int ticks) { - return null; - } - - @Override - public void removeAttachment(PermissionAttachment attachment) { - - } - - @Override - public boolean isOp() { - return false; - } - - @Override - public void setOp(boolean value) { + map.put(lName, value); + Bukkit.getServer().getPluginManager().subscribeToPermission(e.getKey(), p); + if (perm != null) { + calculateChildPermissions(map, p, perm.getChildren(), !value); + } } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DummyPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DummyPermissible.java new file mode 100644 index 00000000..531222ed --- /dev/null +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DummyPermissible.java @@ -0,0 +1,104 @@ +/* + * 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.bukkit.model; + +import lombok.AllArgsConstructor; + +import org.bukkit.permissions.Permissible; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.Plugin; + +import java.util.Collections; +import java.util.Set; + +@AllArgsConstructor +public class DummyPermissible implements Permissible { + private final Runnable onRefresh; + + @Override + public void recalculatePermissions() { + onRefresh.run(); + } + + @Override + public Set getEffectivePermissions() { + return Collections.emptySet(); + } + + @Override + public boolean isPermissionSet(String name) { + return false; + } + + @Override + public boolean isPermissionSet(Permission perm) { + return false; + } + + @Override + public boolean hasPermission(String name) { + return false; + } + + @Override + public boolean hasPermission(Permission perm) { + return false; + } + + @Override + public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { + return null; + } + + @Override + public PermissionAttachment addAttachment(Plugin plugin) { + return null; + } + + @Override + public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { + return null; + } + + @Override + public PermissionAttachment addAttachment(Plugin plugin, int ticks) { + return null; + } + + @Override + public void removeAttachment(PermissionAttachment attachment) { + + } + + @Override + public boolean isOp() { + return false; + } + + @Override + public void setOp(boolean value) { + + } +} diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/DummyPermissibleBase.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DummyPermissibleBase.java similarity index 98% rename from bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/DummyPermissibleBase.java rename to bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DummyPermissibleBase.java index d97ff549..64452808 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/DummyPermissibleBase.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DummyPermissibleBase.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.bukkit.inject; +package me.lucko.luckperms.bukkit.model; import org.bukkit.permissions.PermissibleBase; import org.bukkit.permissions.Permission; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/Injector.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/Injector.java similarity index 98% rename from bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/Injector.java rename to bukkit/src/main/java/me/lucko/luckperms/bukkit/model/Injector.java index bf0c4389..a78e473e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/Injector.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/Injector.java @@ -20,12 +20,10 @@ * SOFTWARE. */ -package me.lucko.luckperms.bukkit.inject; +package me.lucko.luckperms.bukkit.model; import lombok.experimental.UtilityClass; -import me.lucko.luckperms.bukkit.model.LPPermissible; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.permissions.PermissibleBase; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java index c3429067..508ccc1f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java @@ -55,28 +55,19 @@ import java.util.stream.Collectors; /** * Modified PermissibleBase for LuckPerms */ +@Getter public class LPPermissible extends PermissibleBase { - @Getter private final User user; - - @Getter private final Player parent; - - @Getter private final LPBukkitPlugin plugin; - - @Getter private final SubscriptionManager subscriptions; - @Getter @Setter private PermissibleBase oldPermissible = null; // Attachment stuff. - @Getter private final Map attachmentPermissions = new ConcurrentHashMap<>(); - @Getter private final List attachments = Collections.synchronizedList(new LinkedList<>()); public LPPermissible(@NonNull Player parent, User user, LPBukkitPlugin plugin) { @@ -86,7 +77,7 @@ public class LPPermissible extends PermissibleBase { this.plugin = plugin; this.subscriptions = new SubscriptionManager(this); - recalculatePermissions(); + // recalculatePermissions(); } public void updateSubscriptionsAsync() { @@ -294,8 +285,8 @@ public class LPPermissible extends PermissibleBase { Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent); } - Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent); - Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent); + // Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent); + // Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent); attachmentPermissions.clear(); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java index 85cbd0e9..156e5eeb 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java @@ -27,10 +27,20 @@ import lombok.RequiredArgsConstructor; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import org.bukkit.permissions.Permission; + import java.util.HashSet; import java.util.Map; import java.util.Set; +/** + * Handles permission subscriptions with Bukkits plugin manager, for a given LPPermissible. + * + * Bukkit for some reason sometimes uses subscription status to determine whether a permissible has a given node, instead + * of checking directly with {@link org.bukkit.permissions.Permissible#hasPermission(Permission)}. + * + * {@link org.bukkit.Bukkit#broadcast(String, String)} is a good example of this. + */ @RequiredArgsConstructor public class SubscriptionManager { @@ -40,6 +50,8 @@ public class SubscriptionManager { public synchronized void subscribe(Set perms) { Set newPerms = ImmutableSet.copyOf(perms); + // we compare changes to avoid unnecessary time wasted on the main thread mutating this data. + // the changes can be calculated here async, and then only the needed changes can be applied. Map.Entry, Set> changes = compareSets(newPerms, currentSubscriptions); Set toAdd = changes.getKey(); 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 7f2df757..771a7b2c 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 @@ -28,7 +28,7 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.caching.MetaData; import me.lucko.luckperms.api.context.ContextSet; -import me.lucko.luckperms.common.core.NodeBuilder; +import me.lucko.luckperms.common.caching.MetaHolder; import me.lucko.luckperms.common.core.NodeFactory; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.PermissionHolder; @@ -48,20 +48,8 @@ import static me.lucko.luckperms.api.MetaUtils.escapeCharacters; import static me.lucko.luckperms.api.MetaUtils.unescapeCharacters; /** - * Provides the Vault Chat service through the use of normal permission nodes. - * - * Prefixes / Suffixes: - * Normal inheritance rules apply. - * Permission Nodes = prefix.priority.value OR suffix.priority.value - * If a user/group has / inherits multiple prefixes and suffixes, the one with the highest priority is the one that - * will apply. - * - * Meta: - * Normal inheritance rules DO NOT apply. - * Permission Nodes = meta.node.value - * - * Note that special characters used within LuckPerms are escaped: - * See {@link me.lucko.luckperms.api.MetaUtils#unescapeCharacters(String)} + * LuckPerms Vault Chat implementation + * All user lookups are cached. */ public class VaultChatHook extends Chat { private final VaultPermissionHook perms; @@ -94,22 +82,20 @@ public class VaultChatHook extends Chat { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) { - } + } catch (ObjectLacksException ignored) {} }); Node.Builder metaNode = NodeFactory.makeMetaNode(node, value).setValue(true); if (!perms.getServer().equalsIgnoreCase("global")) { metaNode.setServer(perms.getServer()); } - if (finalWorld != null && !finalWorld.equals("")) { - metaNode.setServer(perms.getServer()).setWorld(finalWorld); + if (finalWorld != null && !finalWorld.equals("") && !finalWorld.equals("global")) { + metaNode.setWorld(finalWorld); } try { holder.setPermission(metaNode.build()); - } catch (ObjectAlreadyHasException ignored) { - } + } catch (ObjectAlreadyHasException ignored) {} perms.save(holder); }); @@ -123,20 +109,34 @@ public class VaultChatHook extends Chat { perms.log("Setting " + (prefix ? "prefix" : "suffix") + " for " + holder.getObjectName() + " on world " + world + ", server " + perms.getServer()); perms.getScheduler().execute(() -> { - Node.Builder node = new NodeBuilder((prefix ? "prefix" : "suffix") + ".1000." + escapeCharacters(value)); - node.setValue(true); - if (!perms.getServer().equalsIgnoreCase("global")) { - node.setServer(perms.getServer()); - } - if (finalWorld != null && !finalWorld.equals("")) { - node.setServer(perms.getServer()).setWorld(finalWorld); + // 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) {} + }); + + // find the max inherited priority & add 10 + MetaHolder metaHolder = holder.accumulateMeta(null, null, ExtractedContexts.generate(perms.createContextForWorld(finalWorld))); + int priority = (prefix ? metaHolder.getPrefixes() : metaHolder.getSuffixes()).keySet().stream() + .mapToInt(e -> e).max().orElse(0) + 10; + + Node.Builder chatMetaNode = NodeFactory.makeChatMetaNode(prefix, priority, value); + if (!perms.getServer().equalsIgnoreCase("global")) { + chatMetaNode.setServer(perms.getServer()); + } + if (finalWorld != null && !finalWorld.equals("") && !finalWorld.equals("global")) { + chatMetaNode.setWorld(finalWorld); } try { - holder.setPermission(node.build()); - } catch (ObjectAlreadyHasException ignored) { - } + holder.setPermission(chatMetaNode.build()); + } catch (ObjectAlreadyHasException ignored) {} perms.save(holder); }); @@ -185,21 +185,10 @@ public class VaultChatHook extends Chat { perms.log("Getting meta: '" + node + "' for group " + group.getName() + " on world " + world + ", server " + perms.getServer()); for (Node n : group.getPermissions(true)) { - if (!n.getValue()) { - continue; - } - - if (!n.isMeta()) { - continue; - } - - if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) { - continue; - } - - if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) { - continue; - } + if (!n.getValue()) continue; + if (!n.isMeta()) continue; + if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) continue; + if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) continue; Map.Entry meta = n.getMeta(); if (meta.getKey().equalsIgnoreCase(node)) { @@ -227,21 +216,10 @@ public class VaultChatHook extends Chat { ExtractedContexts ec = ExtractedContexts.generate(new Contexts(ContextSet.fromMap(context), perms.isIncludeGlobal(), true, true, true, true, false)); for (Node n : group.getAllNodes(null, ec)) { - if (!n.getValue()) { - continue; - } - - if (prefix ? !n.isPrefix() : !n.isSuffix()) { - continue; - } - - if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) { - continue; - } - - if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) { - continue; - } + if (!n.getValue()) continue; + if (prefix ? !n.isPrefix() : !n.isSuffix()) continue; + if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) continue; + if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) continue; Map.Entry value = prefix ? n.getPrefix() : n.getSuffix(); if (value.getKey() > priority) { @@ -253,46 +231,55 @@ public class VaultChatHook extends Chat { return meta == null ? "" : unescapeCharacters(meta); } + @Override public String getPlayerPrefix(String world, @NonNull String player) { final User user = perms.getPlugin().getUserManager().getByUsername(player); return getUserChatMeta(true, user, world); } + @Override public void setPlayerPrefix(String world, @NonNull String player, @NonNull String prefix) { final User user = perms.getPlugin().getUserManager().getByUsername(player); setChatMeta(true, user, prefix, world); } + @Override public String getPlayerSuffix(String world, @NonNull String player) { final User user = perms.getPlugin().getUserManager().getByUsername(player); return getUserChatMeta(false, user, world); } + @Override public void setPlayerSuffix(String world, @NonNull String player, @NonNull String suffix) { final User user = perms.getPlugin().getUserManager().getByUsername(player); setChatMeta(false, user, suffix, world); } + @Override public String getGroupPrefix(String world, @NonNull String group) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); return getGroupChatMeta(true, g, world); } + @Override public void setGroupPrefix(String world, @NonNull String group, @NonNull String prefix) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); setChatMeta(true, g, prefix, world); } + @Override public String getGroupSuffix(String world, @NonNull String group) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); return getGroupChatMeta(false, g, world); } + @Override public void setGroupSuffix(String world, @NonNull String group, @NonNull String suffix) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); setChatMeta(false, g, suffix, world); } + @Override public int getPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int defaultValue) { final User user = perms.getPlugin().getUserManager().getByUsername(player); try { @@ -302,11 +289,13 @@ public class VaultChatHook extends Chat { } } + @Override public void setPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int value) { final User user = perms.getPlugin().getUserManager().getByUsername(player); setMeta(user, world, node, String.valueOf(value)); } + @Override public int getGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int defaultValue) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); try { @@ -316,11 +305,13 @@ public class VaultChatHook extends Chat { } } + @Override public void setGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int value) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); setMeta(g, world, node, String.valueOf(value)); } + @Override public double getPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double defaultValue) { final User user = perms.getPlugin().getUserManager().getByUsername(player); try { @@ -330,11 +321,13 @@ public class VaultChatHook extends Chat { } } + @Override public void setPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double value) { final User user = perms.getPlugin().getUserManager().getByUsername(player); setMeta(user, world, node, String.valueOf(value)); } + @Override public double getGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double defaultValue) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); try { @@ -344,11 +337,13 @@ public class VaultChatHook extends Chat { } } + @Override public void setGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double value) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); setMeta(g, world, node, String.valueOf(value)); } + @Override public boolean getPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean defaultValue) { final User user = perms.getPlugin().getUserManager().getByUsername(player); String s = getUserMeta(user, world, node, String.valueOf(defaultValue)); @@ -358,11 +353,13 @@ public class VaultChatHook extends Chat { return Boolean.parseBoolean(s); } + @Override public void setPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean value) { final User user = perms.getPlugin().getUserManager().getByUsername(player); setMeta(user, world, node, String.valueOf(value)); } + @Override public boolean getGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean defaultValue) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); String s = getGroupMeta(g, world, node, String.valueOf(defaultValue)); @@ -372,26 +369,31 @@ public class VaultChatHook extends Chat { return Boolean.parseBoolean(s); } + @Override public void setGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean value) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); setMeta(g, world, node, String.valueOf(value)); } + @Override public String getPlayerInfoString(String world, @NonNull String player, @NonNull String node, String defaultValue) { final User user = perms.getPlugin().getUserManager().getByUsername(player); return getUserMeta(user, world, node, defaultValue); } + @Override public void setPlayerInfoString(String world, @NonNull String player, @NonNull String node, String value) { final User user = perms.getPlugin().getUserManager().getByUsername(player); setMeta(user, world, node, value); } + @Override public String getGroupInfoString(String world, @NonNull String group, @NonNull String node, String defaultValue) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); return getGroupMeta(g, world, node, defaultValue); } + @Override public void setGroupInfoString(String world, @NonNull String group, @NonNull String node, String value) { final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group); setMeta(g, world, node, value); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index a017a6a1..64bde9a4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -47,7 +47,7 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function; /** - * The LuckPerms Vault Permission implementation + * LuckPerms Vault Permission implementation * Most lookups are cached. */ @Getter @@ -62,7 +62,6 @@ public class VaultPermissionHook extends Permission { public VaultPermissionHook(LPBukkitPlugin plugin) { this.plugin = plugin; this.scheduler = new VaultScheduler(plugin); - super.plugin = plugin; } @@ -142,7 +141,7 @@ public class VaultPermissionHook extends Permission { public Contexts createContextForWorld(String world) { Map context = new HashMap<>(); - if (world != null && !world.equals("")) { + if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) { context.put("world", world); } context.put("server", getServer()); @@ -322,21 +321,19 @@ public class VaultPermissionHook extends Permission { return null; } + // nothing special, just return the value. if (!isPgo()) { String g = user.getPrimaryGroup(); return plugin.getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(g, g); } + // we need to do the complex PGO checking. (it's been enabled in the config.) if (isPgoCheckInherited()) { + // we can just check the cached data PermissionData data = user.getUserData().getPermissionData(createContextForWorld(world)); for (Map.Entry e : data.getImmutableBacking().entrySet()) { - if (!e.getValue()) { - continue; - } - - if (!e.getKey().toLowerCase().startsWith("vault.primarygroup.")) { - continue; - } + if (!e.getValue()) continue; + if (!e.getKey().toLowerCase().startsWith("vault.primarygroup.")) continue; String group = e.getKey().substring("vault.primarygroup.".length()); if (isPgoCheckExists()) { @@ -354,22 +351,12 @@ public class VaultPermissionHook extends Permission { return group; } } else { + // we need to check the users permissions only for (LocalizedNode node : user.getPermissions(true)) { - if (!node.getValue()) { - continue; - } - - if (!node.getPermission().toLowerCase().startsWith("vault.primarygroup.")) { - continue; - } - - if (!node.shouldApplyOnServer(getServer(), isIncludeGlobal(), false)) { - continue; - } - - if (!node.shouldApplyOnWorld(world, true, false)) { - continue; - } + if (!node.getValue()) continue; + if (!node.getPermission().toLowerCase().startsWith("vault.primarygroup.")) continue; + if (!node.shouldApplyOnServer(getServer(), isIncludeGlobal(), false)) continue; + if (!node.shouldApplyOnWorld(world, true, false)) continue; String group = node.getPermission().substring("vault.primarygroup.".length()); if (isPgoCheckExists()) { @@ -403,31 +390,31 @@ public class VaultPermissionHook extends Permission { return true; } - public String getServer() { + String getServer() { return plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER); } - public boolean isIncludeGlobal() { + boolean isIncludeGlobal() { return plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL); } - public boolean isIgnoreWorld() { + boolean isIgnoreWorld() { return plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD); } - public boolean isPgo() { + private boolean isPgo() { return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES); } - public boolean isPgoCheckInherited() { + private boolean isPgoCheckInherited() { return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_INHERITED); } - public boolean isPgoCheckExists() { + private boolean isPgoCheckExists() { return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_EXISTS); } - public boolean isPgoCheckMemberOf() { + private boolean isPgoCheckMemberOf() { return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_MEMBER_OF); } }