Remove vault-debug option

This is now covered pretty much entirely by verbose data.
This commit is contained in:
Luck 2019-12-29 17:37:08 +00:00
parent b84518e1f1
commit 242993763c
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
6 changed files with 50 additions and 116 deletions

View File

@ -30,14 +30,12 @@ import com.google.common.base.Strings;
import me.lucko.luckperms.bukkit.LPBukkitPlugin; import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator; import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator;
import me.lucko.luckperms.common.cacheddata.type.MetaCache; import me.lucko.luckperms.common.cacheddata.type.MetaCache;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl; import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Meta; import me.lucko.luckperms.common.node.types.Meta;
import me.lucko.luckperms.common.node.types.Prefix; import me.lucko.luckperms.common.node.types.Prefix;
import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.node.types.Suffix;
import me.lucko.luckperms.common.util.TextUtils;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent; import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
import net.luckperms.api.context.DefaultContextKeys; import net.luckperms.api.context.DefaultContextKeys;
@ -93,11 +91,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
PermissionHolder user = this.vaultPermission.lookupUser(uuid); PermissionHolder user = this.vaultPermission.lookupUser(uuid);
QueryOptions queryOptions = this.vaultPermission.getQueryOptions(uuid, world); QueryOptions queryOptions = this.vaultPermission.getQueryOptions(uuid, world);
MetaCache metaData = user.getCachedData().getMetaData(queryOptions); MetaCache metaData = user.getCachedData().getMetaData(queryOptions);
String prefix = metaData.getPrefix(MetaCheckEvent.Origin.THIRD_PARTY_API); return Strings.nullToEmpty(metaData.getPrefix(MetaCheckEvent.Origin.THIRD_PARTY_API));
if (log()) {
logMsg("#getUserChatPrefix: %s - %s - %s", user.getPlainDisplayName(), queryOptions.context(), prefix);
}
return Strings.nullToEmpty(prefix);
} }
@Override @Override
@ -107,11 +101,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
PermissionHolder user = this.vaultPermission.lookupUser(uuid); PermissionHolder user = this.vaultPermission.lookupUser(uuid);
QueryOptions queryOptions = this.vaultPermission.getQueryOptions(uuid, world); QueryOptions queryOptions = this.vaultPermission.getQueryOptions(uuid, world);
MetaCache metaData = user.getCachedData().getMetaData(queryOptions); MetaCache metaData = user.getCachedData().getMetaData(queryOptions);
String suffix = metaData.getSuffix(MetaCheckEvent.Origin.THIRD_PARTY_API); return Strings.nullToEmpty(metaData.getSuffix(MetaCheckEvent.Origin.THIRD_PARTY_API));
if (log()) {
logMsg("#getUserChatSuffix: %s - %s - %s", user.getPlainDisplayName(), queryOptions.context(), suffix);
}
return Strings.nullToEmpty(suffix);
} }
@Override @Override
@ -144,11 +134,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
PermissionHolder user = this.vaultPermission.lookupUser(uuid); PermissionHolder user = this.vaultPermission.lookupUser(uuid);
QueryOptions queryOptions = this.vaultPermission.getQueryOptions(uuid, world); QueryOptions queryOptions = this.vaultPermission.getQueryOptions(uuid, world);
MetaCache metaData = user.getCachedData().getMetaData(queryOptions); MetaCache metaData = user.getCachedData().getMetaData(queryOptions);
String value = metaData.getMetaValue(key, MetaCheckEvent.Origin.THIRD_PARTY_API); return metaData.getMetaValue(key, MetaCheckEvent.Origin.THIRD_PARTY_API);
if (log()) {
logMsg("#getUserMeta: %s - %s - %s - %s", user.getPlainDisplayName(), queryOptions.context(), key, value);
}
return value;
} }
@Override @Override
@ -172,11 +158,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
} }
QueryOptions queryOptions = this.vaultPermission.getQueryOptions(null, world); QueryOptions queryOptions = this.vaultPermission.getQueryOptions(null, world);
MetaCache metaData = group.getCachedData().getMetaData(queryOptions); MetaCache metaData = group.getCachedData().getMetaData(queryOptions);
String prefix = metaData.getPrefix(MetaCheckEvent.Origin.THIRD_PARTY_API); return Strings.nullToEmpty(metaData.getPrefix(MetaCheckEvent.Origin.THIRD_PARTY_API));
if (log()) {
logMsg("#getGroupPrefix: %s - %s - %s", group.getName(), queryOptions.context(), prefix);
}
return Strings.nullToEmpty(prefix);
} }
@Override @Override
@ -188,11 +170,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
} }
QueryOptions queryOptions = this.vaultPermission.getQueryOptions(null, world); QueryOptions queryOptions = this.vaultPermission.getQueryOptions(null, world);
MetaCache metaData = group.getCachedData().getMetaData(queryOptions); MetaCache metaData = group.getCachedData().getMetaData(queryOptions);
String suffix = metaData.getSuffix(MetaCheckEvent.Origin.THIRD_PARTY_API); return Strings.nullToEmpty(metaData.getSuffix(MetaCheckEvent.Origin.THIRD_PARTY_API));
if (log()) {
logMsg("#getGroupSuffix: %s - %s - %s", group.getName(), queryOptions.context(), suffix);
}
return Strings.nullToEmpty(suffix);
} }
@Override @Override
@ -225,11 +203,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
} }
QueryOptions queryOptions = this.vaultPermission.getQueryOptions(null, world); QueryOptions queryOptions = this.vaultPermission.getQueryOptions(null, world);
MetaCache metaData = group.getCachedData().getMetaData(queryOptions); MetaCache metaData = group.getCachedData().getMetaData(queryOptions);
String value = metaData.getMetaValue(key, MetaCheckEvent.Origin.THIRD_PARTY_API); return metaData.getMetaValue(key, MetaCheckEvent.Origin.THIRD_PARTY_API);
if (log()) {
logMsg("#getGroupMeta: %s - %s - %s - %s", group.getName(), queryOptions.context(), key, value);
}
return value;
} }
@Override @Override
@ -249,22 +223,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
return this.plugin.getGroupManager().getByDisplayName(name); return this.plugin.getGroupManager().getByDisplayName(name);
} }
// logging
private boolean log() {
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG);
}
private void logMsg(String format, Object... args) {
this.plugin.getLogger().info("[VAULT-CHAT] " + String.format(format, args)
.replace(TextUtils.SECTION_CHAR, '$')
.replace(TextUtils.AMPERSAND_CHAR, '$')
);
}
private void setChatMeta(PermissionHolder holder, ChatMetaType type, String value, String world) { private void setChatMeta(PermissionHolder holder, ChatMetaType type, String value, String world) {
if (log()) {
logMsg("#setChatMeta: %s - %s - %s - %s", holder.getPlainDisplayName(), type, value, world);
}
// remove all prefixes/suffixes directly set on the user/group // remove all prefixes/suffixes directly set on the user/group
holder.removeIf(DataType.NORMAL, null, type.nodeType()::matches, false); holder.removeIf(DataType.NORMAL, null, type.nodeType()::matches, false);
@ -288,10 +247,6 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
} }
private void setMeta(PermissionHolder holder, String key, Object value, String world) { private void setMeta(PermissionHolder holder, String key, Object value, String world) {
if (log()) {
logMsg("#setMeta: %s - %s - %s - %s", holder.getPlainDisplayName(), key, value, world);
}
holder.removeIf(DataType.NORMAL, null, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false); holder.removeIf(DataType.NORMAL, null, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false);
if (value == null) { if (value == null) {

View File

@ -40,7 +40,6 @@ import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.manager.group.GroupManager; import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.node.factory.NodeBuilders; import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.node.types.Inheritance; import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.util.TextUtils;
import me.lucko.luckperms.common.util.Uuids; import me.lucko.luckperms.common.util.Uuids;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent; import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent; import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
@ -58,7 +57,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -195,9 +193,6 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
PermissionCache permissionData = user.getCachedData().getPermissionData(queryOptions); PermissionCache permissionData = user.getCachedData().getPermissionData(queryOptions);
Tristate result = permissionData.checkPermission(permission, PermissionCheckEvent.Origin.THIRD_PARTY_API).result(); Tristate result = permissionData.checkPermission(permission, PermissionCheckEvent.Origin.THIRD_PARTY_API).result();
if (log()) {
logMsg("#userHasPermission: %s - %s - %s - %s", user.getPlainDisplayName(), queryOptions.context(), permission, result);
}
return result != Tristate.UNDEFINED ? result.asBoolean() : org.bukkit.permissions.Permission.DEFAULT_PERMISSION.getValue(queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false)); return result != Tristate.UNDEFINED ? result.asBoolean() : org.bukkit.permissions.Permission.DEFAULT_PERMISSION.getValue(queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false));
} }
@ -235,9 +230,6 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
PermissionCache permissionData = user.getCachedData().getPermissionData(queryOptions); PermissionCache permissionData = user.getCachedData().getPermissionData(queryOptions);
TristateResult result = permissionData.checkPermission(Inheritance.key(rewriteGroupName(group)), PermissionCheckEvent.Origin.THIRD_PARTY_API); TristateResult result = permissionData.checkPermission(Inheritance.key(rewriteGroupName(group)), PermissionCheckEvent.Origin.THIRD_PARTY_API);
if (log()) {
logMsg("#userInGroup: %s - %s - %s - %s", user.getPlainDisplayName(), queryOptions.context(), group, result);
}
return result.processorClass() == MapProcessor.class && result.result().asBoolean(); return result.processorClass() == MapProcessor.class && result.result().asBoolean();
} }
@ -262,7 +254,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
PermissionHolder user = lookupUser(uuid); PermissionHolder user = lookupUser(uuid);
ContextSet contexts = getQueryOptions(uuid, world).context(); ContextSet contexts = getQueryOptions(uuid, world).context();
String[] groups = user.normalData().immutableInheritance().values().stream() return user.normalData().immutableInheritance().values().stream()
.filter(n -> n.getContexts().isSatisfiedBy(contexts)) .filter(n -> n.getContexts().isSatisfiedBy(contexts))
.map(n -> { .map(n -> {
Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName()); Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
@ -272,12 +264,6 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
return n.getGroupName(); return n.getGroupName();
}) })
.toArray(String[]::new); .toArray(String[]::new);
if (log()) {
logMsg("#userGetGroups: %s - %s - %s", user.getPlainDisplayName(), contexts, Arrays.toString(groups));
}
return groups;
} }
@Override @Override
@ -295,11 +281,6 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
} }
this.plugin.getVerboseHandler().offerMetaCheckEvent(MetaCheckEvent.Origin.THIRD_PARTY_API, user.getPlainDisplayName(), QueryOptions.defaultContextualOptions(), "primarygroup", value); this.plugin.getVerboseHandler().offerMetaCheckEvent(MetaCheckEvent.Origin.THIRD_PARTY_API, user.getPlainDisplayName(), QueryOptions.defaultContextualOptions(), "primarygroup", value);
if (log()) {
logMsg("#userGetPrimaryGroup: %s - %s - %s", user.getPlainDisplayName(), world, value);
}
return value; return value;
} }
@ -315,12 +296,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
QueryOptions queryOptions = getQueryOptions(null, world); QueryOptions queryOptions = getQueryOptions(null, world);
PermissionCache permissionData = group.getCachedData().getPermissionData(queryOptions); PermissionCache permissionData = group.getCachedData().getPermissionData(queryOptions);
return permissionData.checkPermission(permission, PermissionCheckEvent.Origin.THIRD_PARTY_API).result().asBoolean();
Tristate result = permissionData.checkPermission(permission, PermissionCheckEvent.Origin.THIRD_PARTY_API).result();
if (log()) {
logMsg("#groupHasPermission: %s - %s - %s - %s", group.getName(), queryOptions.context(), permission, result);
}
return result.asBoolean();
} }
@Override @Override
@ -367,17 +343,6 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
return name; return name;
} }
// logging
private boolean log() {
return this.plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG);
}
private void logMsg(String format, Object... args) {
this.plugin.getLogger().info("[VAULT-PERMS] " + String.format(format, args)
.replace(TextUtils.SECTION_CHAR, '$')
.replace(TextUtils.AMPERSAND_CHAR, '$')
);
}
// utility method for getting a contexts instance for a given vault lookup. // utility method for getting a contexts instance for a given vault lookup.
QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) { QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) {
MutableContextSet context; MutableContextSet context;
@ -433,10 +398,6 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
Objects.requireNonNull(permission, "permission is null"); Objects.requireNonNull(permission, "permission is null");
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string"); Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
if (log()) {
logMsg("#holderAddPermission: %s - %s - %s", holder.getPlainDisplayName(), permission, world);
}
if (world == null) { if (world == null) {
world = "global"; world = "global";
} }
@ -451,10 +412,6 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
Objects.requireNonNull(permission, "permission is null"); Objects.requireNonNull(permission, "permission is null");
Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string"); Preconditions.checkArgument(!permission.isEmpty(), "permission is an empty string");
if (log()) {
logMsg("#holderRemovePermission: %s - %s - %s", holder.getPlainDisplayName(), permission, world);
}
if (world == null) { if (world == null) {
world = "global"; world = "global";
} }

View File

@ -544,9 +544,6 @@ vault-include-global: true
# If Vault operations should ignore any world arguments if supplied. # If Vault operations should ignore any world arguments if supplied.
vault-ignore-world: false vault-ignore-world: false
# If LuckPerms should print debugging info to console when a plugin uses a Vault function
vault-debug: false
# +----------------------------------------------------------------------------------------------+ # # +----------------------------------------------------------------------------------------------+ #
# | Miscellaneous (and rarely used) settings | # # | Miscellaneous (and rarely used) settings | #
# +----------------------------------------------------------------------------------------------+ # # +----------------------------------------------------------------------------------------------+ #

View File

@ -25,10 +25,10 @@
package me.lucko.luckperms.common.cacheddata.type; package me.lucko.luckperms.common.cacheddata.type;
import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import me.lucko.luckperms.common.cacheddata.CacheMetadata; import me.lucko.luckperms.common.cacheddata.CacheMetadata;
@ -64,7 +64,7 @@ public class MetaCache implements CachedMetaData {
*/ */
private final CacheMetadata metadata; private final CacheMetadata metadata;
private ListMultimap<String, String> meta = ImmutableListMultimap.of(); private Map<String, List<String>> meta = ImmutableMap.of();
private Map<String, String> flattenedMeta = ImmutableMap.of(); private Map<String, String> flattenedMeta = ImmutableMap.of();
private SortedMap<Integer, String> prefixes = ImmutableSortedMap.of(); private SortedMap<Integer, String> prefixes = ImmutableSortedMap.of();
private SortedMap<Integer, String> suffixes = ImmutableSortedMap.of(); private SortedMap<Integer, String> suffixes = ImmutableSortedMap.of();
@ -79,21 +79,18 @@ public class MetaCache implements CachedMetaData {
public void loadMeta(MetaAccumulator meta) { public void loadMeta(MetaAccumulator meta) {
meta.complete(); meta.complete();
this.meta = ImmutableListMultimap.copyOf(meta.getMeta()); this.meta = Multimaps.asMap(ImmutableListMultimap.copyOf(meta.getMeta()));
//noinspection unchecked ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
Map<String, List<String>> metaMap = (Map) this.meta.asMap(); for (Map.Entry<String, List<String>> e : this.meta.entrySet()) {
ImmutableMap.Builder<String, String> metaMapBuilder = ImmutableMap.builder();
for (Map.Entry<String, List<String>> e : metaMap.entrySet()) {
if (e.getValue().isEmpty()) { if (e.getValue().isEmpty()) {
continue; continue;
} }
// take the value which was accumulated first // take the value which was accumulated first
metaMapBuilder.put(e.getKey(), e.getValue().get(0)); builder.put(e.getKey(), e.getValue().get(0));
} }
this.flattenedMeta = metaMapBuilder.build(); this.flattenedMeta = builder.build();
this.prefixes = ImmutableSortedMap.copyOfSorted(meta.getPrefixes()); this.prefixes = ImmutableSortedMap.copyOfSorted(meta.getPrefixes());
this.suffixes = ImmutableSortedMap.copyOfSorted(meta.getSuffixes()); this.suffixes = ImmutableSortedMap.copyOfSorted(meta.getSuffixes());
@ -149,9 +146,13 @@ public class MetaCache implements CachedMetaData {
return getSuffix(MetaCheckEvent.Origin.LUCKPERMS_API); return getSuffix(MetaCheckEvent.Origin.LUCKPERMS_API);
} }
public Map<String, List<String>> getMeta(MetaCheckEvent.Origin origin) {
return new MonitoredMetaMap(origin);
}
@Override @Override
public @NonNull Map<String, List<String>> getMeta() { public @NonNull Map<String, List<String>> getMeta() {
return Multimaps.asMap(this.meta); return getMeta(MetaCheckEvent.Origin.LUCKPERMS_API);
} }
@Override @Override
@ -179,4 +180,33 @@ public class MetaCache implements CachedMetaData {
return this.queryOptions; return this.queryOptions;
} }
private final class MonitoredMetaMap extends ForwardingMap<String, List<String>> {
private final MetaCheckEvent.Origin origin;
MonitoredMetaMap(MetaCheckEvent.Origin origin) {
this.origin = origin;
}
@Override
protected Map<String, List<String>> delegate() {
return MetaCache.this.meta;
}
@Override
public List<String> get(Object k) {
if (k == null) {
return null;
}
String key = (String) k;
List<String> values = super.get(key);
// log this meta lookup to the verbose handler
VerboseHandler verboseHandler = MetaCache.this.metadata.getParentContainer().getPlugin().getVerboseHandler();
verboseHandler.offerMetaCheckEvent(this.origin, MetaCache.this.metadata.getObjectName(), MetaCache.this.metadata.getQueryOptions(), key, String.valueOf(values));
return values;
}
}
} }

View File

@ -122,7 +122,7 @@ public class UserInfo extends SubCommand<User> {
suffix = "&f\"" + sussexValue + "&f\""; suffix = "&f\"" + sussexValue + "&f\"";
} }
Map<String, List<String>> metaMap = data.getMeta(); Map<String, List<String>> metaMap = data.getMeta(MetaCheckEvent.Origin.INTERNAL);
if (!metaMap.isEmpty()) { if (!metaMap.isEmpty()) {
meta = metaMap.entrySet().stream() meta = metaMap.entrySet().stream()
.flatMap(entry -> entry.getValue().stream().map(value -> Maps.immutableEntry(entry.getKey(), value))) .flatMap(entry -> entry.getValue().stream().map(value -> Maps.immutableEntry(entry.getKey(), value)))

View File

@ -397,11 +397,6 @@ public final class ConfigKeys {
*/ */
public static final ConfigKey<Boolean> VAULT_IGNORE_WORLD = booleanKey("vault-ignore-world", false); public static final ConfigKey<Boolean> VAULT_IGNORE_WORLD = booleanKey("vault-ignore-world", false);
/**
* If Vault debug mode is enabled
*/
public static final ConfigKey<Boolean> VAULT_DEBUG = booleanKey("vault-debug", false);
/** /**
* The world rewrites map * The world rewrites map
*/ */