Fix setting chat meta with Vault, remove unnecessary permissible recalculations & general cleanup
This commit is contained in:
parent
bd97a7c5d2
commit
4b16be1b75
@ -30,7 +30,7 @@ import me.lucko.luckperms.api.Contexts;
|
|||||||
import me.lucko.luckperms.bukkit.calculators.AttachmentProcessor;
|
import me.lucko.luckperms.bukkit.calculators.AttachmentProcessor;
|
||||||
import me.lucko.luckperms.bukkit.calculators.ChildProcessor;
|
import me.lucko.luckperms.bukkit.calculators.ChildProcessor;
|
||||||
import me.lucko.luckperms.bukkit.calculators.DefaultsProcessor;
|
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.bukkit.model.LPPermissible;
|
||||||
import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory;
|
import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory;
|
||||||
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
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.bukkit.model.LPPermissible;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.constants.Message;
|
import me.lucko.luckperms.common.constants.Message;
|
||||||
|
@ -32,11 +32,11 @@ import me.lucko.luckperms.api.LuckPermsApi;
|
|||||||
import me.lucko.luckperms.api.PlatformType;
|
import me.lucko.luckperms.api.PlatformType;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
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.BungeeMessagingService;
|
||||||
import me.lucko.luckperms.bukkit.messaging.LilyPadMessagingService;
|
import me.lucko.luckperms.bukkit.messaging.LilyPadMessagingService;
|
||||||
import me.lucko.luckperms.bukkit.model.ChildPermissionProvider;
|
import me.lucko.luckperms.bukkit.model.ChildPermissionProvider;
|
||||||
import me.lucko.luckperms.bukkit.model.DefaultsProvider;
|
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.model.LPPermissible;
|
||||||
import me.lucko.luckperms.bukkit.vault.VaultHook;
|
import me.lucko.luckperms.bukkit.vault.VaultHook;
|
||||||
import me.lucko.luckperms.common.api.ApiHandler;
|
import me.lucko.luckperms.common.api.ApiHandler;
|
||||||
|
@ -36,6 +36,27 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class ChildPermissionProvider {
|
public class ChildPermissionProvider {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
||||||
|
|
||||||
|
public void setup() {
|
||||||
|
Map<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = new HashMap<>();
|
||||||
|
|
||||||
|
for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) {
|
||||||
|
// handle true
|
||||||
|
Map<String, Boolean> 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<String, Boolean> 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<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
|
private static void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
|
||||||
for (Map.Entry<String, Boolean> e : children.entrySet()) {
|
for (Map.Entry<String, Boolean> e : children.entrySet()) {
|
||||||
if (accumulator.containsKey(e.getKey())) {
|
if (accumulator.containsKey(e.getKey())) {
|
||||||
@ -53,25 +74,4 @@ public class ChildPermissionProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
|
||||||
|
|
||||||
public void setup() {
|
|
||||||
Map<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = new HashMap<>();
|
|
||||||
|
|
||||||
for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) {
|
|
||||||
// handle true
|
|
||||||
Map<String, Boolean> 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<String, Boolean> 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.model;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@ -30,57 +29,14 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.permissions.Permissible;
|
|
||||||
import org.bukkit.permissions.Permission;
|
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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DefaultsProvider {
|
public class DefaultsProvider {
|
||||||
|
|
||||||
private static void unregisterDefaults(Map<String, Boolean> map, DummyPermissible p) {
|
|
||||||
Set<String> 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<String, Boolean> map, DummyPermissible p, boolean op) {
|
|
||||||
Set<Permission> 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<String, Boolean> map, DummyPermissible p, Map<String, Boolean> children, boolean invert) {
|
|
||||||
for (Map.Entry<String, Boolean> 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
|
@Getter
|
||||||
private Map<String, Boolean> opDefaults = ImmutableMap.of();
|
private Map<String, Boolean> opDefaults = ImmutableMap.of();
|
||||||
private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp);
|
private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp);
|
||||||
@ -128,73 +84,41 @@ public class DefaultsProvider {
|
|||||||
return opDefaults.size() + nonOpDefaults.size();
|
return opDefaults.size() + nonOpDefaults.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllArgsConstructor
|
private static void unregisterDefaults(Map<String, Boolean> map, DummyPermissible p) {
|
||||||
private static class DummyPermissible implements Permissible {
|
Set<String> perms = map.keySet();
|
||||||
private final Runnable onRefresh;
|
|
||||||
|
|
||||||
@Override
|
for (String name : perms) {
|
||||||
public void recalculatePermissions() {
|
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, p);
|
||||||
onRefresh.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, p);
|
||||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, p);
|
||||||
return Collections.emptySet();
|
}
|
||||||
|
|
||||||
|
private static void calculateDefaults(Map<String, Boolean> map, DummyPermissible p, boolean op) {
|
||||||
|
Set<Permission> 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
|
private static void calculateChildPermissions(Map<String, Boolean> map, DummyPermissible p, Map<String, Boolean> children, boolean invert) {
|
||||||
public boolean isPermissionSet(String name) {
|
for (Map.Entry<String, Boolean> e : children.entrySet()) {
|
||||||
return false;
|
Permission perm = Bukkit.getServer().getPluginManager().getPermission(e.getKey());
|
||||||
}
|
boolean value = e.getValue() ^ invert;
|
||||||
|
String lName = e.getKey().toLowerCase();
|
||||||
|
|
||||||
@Override
|
map.put(lName, value);
|
||||||
public boolean isPermissionSet(Permission perm) {
|
Bukkit.getServer().getPluginManager().subscribeToPermission(e.getKey(), p);
|
||||||
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) {
|
|
||||||
|
|
||||||
|
if (perm != null) {
|
||||||
|
calculateChildPermissions(map, p, perm.getChildren(), !value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* 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.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<PermissionAttachmentInfo> 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.bukkit.inject;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import org.bukkit.permissions.PermissibleBase;
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
@ -20,12 +20,10 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.bukkit.inject;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissibleBase;
|
import org.bukkit.permissions.PermissibleBase;
|
@ -55,28 +55,19 @@ import java.util.stream.Collectors;
|
|||||||
/**
|
/**
|
||||||
* Modified PermissibleBase for LuckPerms
|
* Modified PermissibleBase for LuckPerms
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
public class LPPermissible extends PermissibleBase {
|
public class LPPermissible extends PermissibleBase {
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final User user;
|
private final User user;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Player parent;
|
private final Player parent;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final SubscriptionManager subscriptions;
|
private final SubscriptionManager subscriptions;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
@Setter
|
||||||
private PermissibleBase oldPermissible = null;
|
private PermissibleBase oldPermissible = null;
|
||||||
|
|
||||||
// Attachment stuff.
|
// Attachment stuff.
|
||||||
@Getter
|
|
||||||
private final Map<String, PermissionAttachmentInfo> attachmentPermissions = new ConcurrentHashMap<>();
|
private final Map<String, PermissionAttachmentInfo> attachmentPermissions = new ConcurrentHashMap<>();
|
||||||
@Getter
|
|
||||||
private final List<PermissionAttachment> attachments = Collections.synchronizedList(new LinkedList<>());
|
private final List<PermissionAttachment> attachments = Collections.synchronizedList(new LinkedList<>());
|
||||||
|
|
||||||
public LPPermissible(@NonNull Player parent, User user, LPBukkitPlugin plugin) {
|
public LPPermissible(@NonNull Player parent, User user, LPBukkitPlugin plugin) {
|
||||||
@ -86,7 +77,7 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.subscriptions = new SubscriptionManager(this);
|
this.subscriptions = new SubscriptionManager(this);
|
||||||
|
|
||||||
recalculatePermissions();
|
// recalculatePermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateSubscriptionsAsync() {
|
public void updateSubscriptionsAsync() {
|
||||||
@ -294,8 +285,8 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent);
|
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent);
|
// Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent);
|
||||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent);
|
// Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent);
|
||||||
|
|
||||||
attachmentPermissions.clear();
|
attachmentPermissions.clear();
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,20 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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
|
@RequiredArgsConstructor
|
||||||
public class SubscriptionManager {
|
public class SubscriptionManager {
|
||||||
|
|
||||||
@ -40,6 +50,8 @@ public class SubscriptionManager {
|
|||||||
public synchronized void subscribe(Set<String> perms) {
|
public synchronized void subscribe(Set<String> perms) {
|
||||||
Set<String> newPerms = ImmutableSet.copyOf(perms);
|
Set<String> 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<String>, Set<String>> changes = compareSets(newPerms, currentSubscriptions);
|
Map.Entry<Set<String>, Set<String>> changes = compareSets(newPerms, currentSubscriptions);
|
||||||
|
|
||||||
Set<String> toAdd = changes.getKey();
|
Set<String> toAdd = changes.getKey();
|
||||||
|
@ -28,7 +28,7 @@ import me.lucko.luckperms.api.Contexts;
|
|||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.caching.MetaData;
|
import me.lucko.luckperms.api.caching.MetaData;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
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.NodeFactory;
|
||||||
import me.lucko.luckperms.common.core.model.Group;
|
import me.lucko.luckperms.common.core.model.Group;
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
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;
|
import static me.lucko.luckperms.api.MetaUtils.unescapeCharacters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Vault Chat service through the use of normal permission nodes.
|
* LuckPerms Vault Chat implementation
|
||||||
*
|
* All user lookups are cached.
|
||||||
* 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)}
|
|
||||||
*/
|
*/
|
||||||
public class VaultChatHook extends Chat {
|
public class VaultChatHook extends Chat {
|
||||||
private final VaultPermissionHook perms;
|
private final VaultPermissionHook perms;
|
||||||
@ -94,22 +82,20 @@ public class VaultChatHook extends Chat {
|
|||||||
toRemove.forEach(n -> {
|
toRemove.forEach(n -> {
|
||||||
try {
|
try {
|
||||||
holder.unsetPermission(n);
|
holder.unsetPermission(n);
|
||||||
} catch (ObjectLacksException ignored) {
|
} catch (ObjectLacksException ignored) {}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Node.Builder metaNode = NodeFactory.makeMetaNode(node, value).setValue(true);
|
Node.Builder metaNode = NodeFactory.makeMetaNode(node, value).setValue(true);
|
||||||
if (!perms.getServer().equalsIgnoreCase("global")) {
|
if (!perms.getServer().equalsIgnoreCase("global")) {
|
||||||
metaNode.setServer(perms.getServer());
|
metaNode.setServer(perms.getServer());
|
||||||
}
|
}
|
||||||
if (finalWorld != null && !finalWorld.equals("")) {
|
if (finalWorld != null && !finalWorld.equals("") && !finalWorld.equals("global")) {
|
||||||
metaNode.setServer(perms.getServer()).setWorld(finalWorld);
|
metaNode.setWorld(finalWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.setPermission(metaNode.build());
|
holder.setPermission(metaNode.build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
perms.save(holder);
|
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.log("Setting " + (prefix ? "prefix" : "suffix") + " for " + holder.getObjectName() + " on world " + world + ", server " + perms.getServer());
|
||||||
|
|
||||||
perms.getScheduler().execute(() -> {
|
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("")) {
|
// remove all prefixes/suffixes directly set on the user/group
|
||||||
node.setServer(perms.getServer()).setWorld(finalWorld);
|
List<Node> 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 {
|
try {
|
||||||
holder.setPermission(node.build());
|
holder.setPermission(chatMetaNode.build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
perms.save(holder);
|
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());
|
perms.log("Getting meta: '" + node + "' for group " + group.getName() + " on world " + world + ", server " + perms.getServer());
|
||||||
|
|
||||||
for (Node n : group.getPermissions(true)) {
|
for (Node n : group.getPermissions(true)) {
|
||||||
if (!n.getValue()) {
|
if (!n.getValue()) continue;
|
||||||
continue;
|
if (!n.isMeta()) continue;
|
||||||
}
|
if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) continue;
|
||||||
|
if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) continue;
|
||||||
if (!n.isMeta()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map.Entry<String, String> meta = n.getMeta();
|
Map.Entry<String, String> meta = n.getMeta();
|
||||||
if (meta.getKey().equalsIgnoreCase(node)) {
|
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));
|
ExtractedContexts ec = ExtractedContexts.generate(new Contexts(ContextSet.fromMap(context), perms.isIncludeGlobal(), true, true, true, true, false));
|
||||||
for (Node n : group.getAllNodes(null, ec)) {
|
for (Node n : group.getAllNodes(null, ec)) {
|
||||||
if (!n.getValue()) {
|
if (!n.getValue()) continue;
|
||||||
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 (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<Integer, String> value = prefix ? n.getPrefix() : n.getSuffix();
|
Map.Entry<Integer, String> value = prefix ? n.getPrefix() : n.getSuffix();
|
||||||
if (value.getKey() > priority) {
|
if (value.getKey() > priority) {
|
||||||
@ -253,46 +231,55 @@ public class VaultChatHook extends Chat {
|
|||||||
return meta == null ? "" : unescapeCharacters(meta);
|
return meta == null ? "" : unescapeCharacters(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getPlayerPrefix(String world, @NonNull String player) {
|
public String getPlayerPrefix(String world, @NonNull String player) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
return getUserChatMeta(true, user, world);
|
return getUserChatMeta(true, user, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPlayerPrefix(String world, @NonNull String player, @NonNull String prefix) {
|
public void setPlayerPrefix(String world, @NonNull String player, @NonNull String prefix) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
setChatMeta(true, user, prefix, world);
|
setChatMeta(true, user, prefix, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getPlayerSuffix(String world, @NonNull String player) {
|
public String getPlayerSuffix(String world, @NonNull String player) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
return getUserChatMeta(false, user, world);
|
return getUserChatMeta(false, user, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPlayerSuffix(String world, @NonNull String player, @NonNull String suffix) {
|
public void setPlayerSuffix(String world, @NonNull String player, @NonNull String suffix) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
setChatMeta(false, user, suffix, world);
|
setChatMeta(false, user, suffix, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getGroupPrefix(String world, @NonNull String group) {
|
public String getGroupPrefix(String world, @NonNull String group) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
return getGroupChatMeta(true, g, world);
|
return getGroupChatMeta(true, g, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setGroupPrefix(String world, @NonNull String group, @NonNull String prefix) {
|
public void setGroupPrefix(String world, @NonNull String group, @NonNull String prefix) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
setChatMeta(true, g, prefix, world);
|
setChatMeta(true, g, prefix, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getGroupSuffix(String world, @NonNull String group) {
|
public String getGroupSuffix(String world, @NonNull String group) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
return getGroupChatMeta(false, g, world);
|
return getGroupChatMeta(false, g, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setGroupSuffix(String world, @NonNull String group, @NonNull String suffix) {
|
public void setGroupSuffix(String world, @NonNull String group, @NonNull String suffix) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
setChatMeta(false, g, suffix, world);
|
setChatMeta(false, g, suffix, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int defaultValue) {
|
public int getPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int defaultValue) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
try {
|
try {
|
||||||
@ -302,11 +289,13 @@ public class VaultChatHook extends Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int value) {
|
public void setPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int value) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
setMeta(user, world, node, String.valueOf(value));
|
setMeta(user, world, node, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int defaultValue) {
|
public int getGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int defaultValue) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
try {
|
try {
|
||||||
@ -316,11 +305,13 @@ public class VaultChatHook extends Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int value) {
|
public void setGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int value) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
setMeta(g, world, node, String.valueOf(value));
|
setMeta(g, world, node, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double defaultValue) {
|
public double getPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double defaultValue) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
try {
|
try {
|
||||||
@ -330,11 +321,13 @@ public class VaultChatHook extends Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double value) {
|
public void setPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double value) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
setMeta(user, world, node, String.valueOf(value));
|
setMeta(user, world, node, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double defaultValue) {
|
public double getGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double defaultValue) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
try {
|
try {
|
||||||
@ -344,11 +337,13 @@ public class VaultChatHook extends Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double value) {
|
public void setGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double value) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
setMeta(g, world, node, String.valueOf(value));
|
setMeta(g, world, node, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean getPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean defaultValue) {
|
public boolean getPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean defaultValue) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
String s = getUserMeta(user, world, node, String.valueOf(defaultValue));
|
String s = getUserMeta(user, world, node, String.valueOf(defaultValue));
|
||||||
@ -358,11 +353,13 @@ public class VaultChatHook extends Chat {
|
|||||||
return Boolean.parseBoolean(s);
|
return Boolean.parseBoolean(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean value) {
|
public void setPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean value) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
setMeta(user, world, node, String.valueOf(value));
|
setMeta(user, world, node, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean getGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean defaultValue) {
|
public boolean getGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean defaultValue) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
String s = getGroupMeta(g, world, node, String.valueOf(defaultValue));
|
String s = getGroupMeta(g, world, node, String.valueOf(defaultValue));
|
||||||
@ -372,26 +369,31 @@ public class VaultChatHook extends Chat {
|
|||||||
return Boolean.parseBoolean(s);
|
return Boolean.parseBoolean(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean value) {
|
public void setGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean value) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
setMeta(g, world, node, String.valueOf(value));
|
setMeta(g, world, node, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getPlayerInfoString(String world, @NonNull String player, @NonNull String node, String defaultValue) {
|
public String getPlayerInfoString(String world, @NonNull String player, @NonNull String node, String defaultValue) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
return getUserMeta(user, world, node, defaultValue);
|
return getUserMeta(user, world, node, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setPlayerInfoString(String world, @NonNull String player, @NonNull String node, String value) {
|
public void setPlayerInfoString(String world, @NonNull String player, @NonNull String node, String value) {
|
||||||
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
final User user = perms.getPlugin().getUserManager().getByUsername(player);
|
||||||
setMeta(user, world, node, value);
|
setMeta(user, world, node, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getGroupInfoString(String world, @NonNull String group, @NonNull String node, String defaultValue) {
|
public String getGroupInfoString(String world, @NonNull String group, @NonNull String node, String defaultValue) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
return getGroupMeta(g, world, node, defaultValue);
|
return getGroupMeta(g, world, node, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setGroupInfoString(String world, @NonNull String group, @NonNull String node, String value) {
|
public void setGroupInfoString(String world, @NonNull String group, @NonNull String node, String value) {
|
||||||
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
final Group g = perms.getPlugin().getGroupManager().getIfLoaded(group);
|
||||||
setMeta(g, world, node, value);
|
setMeta(g, world, node, value);
|
||||||
|
@ -47,7 +47,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The LuckPerms Vault Permission implementation
|
* LuckPerms Vault Permission implementation
|
||||||
* Most lookups are cached.
|
* Most lookups are cached.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@ -62,7 +62,6 @@ public class VaultPermissionHook extends Permission {
|
|||||||
public VaultPermissionHook(LPBukkitPlugin plugin) {
|
public VaultPermissionHook(LPBukkitPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.scheduler = new VaultScheduler(plugin);
|
this.scheduler = new VaultScheduler(plugin);
|
||||||
|
|
||||||
super.plugin = plugin;
|
super.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +141,7 @@ public class VaultPermissionHook extends Permission {
|
|||||||
|
|
||||||
public Contexts createContextForWorld(String world) {
|
public Contexts createContextForWorld(String world) {
|
||||||
Map<String, String> context = new HashMap<>();
|
Map<String, String> context = new HashMap<>();
|
||||||
if (world != null && !world.equals("")) {
|
if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) {
|
||||||
context.put("world", world);
|
context.put("world", world);
|
||||||
}
|
}
|
||||||
context.put("server", getServer());
|
context.put("server", getServer());
|
||||||
@ -322,21 +321,19 @@ public class VaultPermissionHook extends Permission {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nothing special, just return the value.
|
||||||
if (!isPgo()) {
|
if (!isPgo()) {
|
||||||
String g = user.getPrimaryGroup();
|
String g = user.getPrimaryGroup();
|
||||||
return plugin.getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(g, g);
|
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()) {
|
if (isPgoCheckInherited()) {
|
||||||
|
// we can just check the cached data
|
||||||
PermissionData data = user.getUserData().getPermissionData(createContextForWorld(world));
|
PermissionData data = user.getUserData().getPermissionData(createContextForWorld(world));
|
||||||
for (Map.Entry<String, Boolean> e : data.getImmutableBacking().entrySet()) {
|
for (Map.Entry<String, Boolean> e : data.getImmutableBacking().entrySet()) {
|
||||||
if (!e.getValue()) {
|
if (!e.getValue()) continue;
|
||||||
continue;
|
if (!e.getKey().toLowerCase().startsWith("vault.primarygroup.")) continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!e.getKey().toLowerCase().startsWith("vault.primarygroup.")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String group = e.getKey().substring("vault.primarygroup.".length());
|
String group = e.getKey().substring("vault.primarygroup.".length());
|
||||||
if (isPgoCheckExists()) {
|
if (isPgoCheckExists()) {
|
||||||
@ -354,22 +351,12 @@ public class VaultPermissionHook extends Permission {
|
|||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// we need to check the users permissions only
|
||||||
for (LocalizedNode node : user.getPermissions(true)) {
|
for (LocalizedNode node : user.getPermissions(true)) {
|
||||||
if (!node.getValue()) {
|
if (!node.getValue()) continue;
|
||||||
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.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());
|
String group = node.getPermission().substring("vault.primarygroup.".length());
|
||||||
if (isPgoCheckExists()) {
|
if (isPgoCheckExists()) {
|
||||||
@ -403,31 +390,31 @@ public class VaultPermissionHook extends Permission {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServer() {
|
String getServer() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER);
|
return plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIncludeGlobal() {
|
boolean isIncludeGlobal() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
|
return plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIgnoreWorld() {
|
boolean isIgnoreWorld() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD);
|
return plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPgo() {
|
private boolean isPgo() {
|
||||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES);
|
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);
|
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);
|
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);
|
return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_MEMBER_OF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user