diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/MonitoredPermissibleBase.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/MonitoredPermissibleBase.java index 598bd9810..e3c4f57c5 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/MonitoredPermissibleBase.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/MonitoredPermissibleBase.java @@ -28,6 +28,7 @@ package me.lucko.luckperms.bukkit.inject.permissible; import me.lucko.luckperms.common.calculator.result.TristateResult; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.query.QueryOptionsImpl; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import me.lucko.luckperms.common.verbose.VerboseHandler; import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent; @@ -51,7 +52,7 @@ import java.util.Set; public class MonitoredPermissibleBase extends PermissibleBase { final LuckPermsPlugin plugin; private final PermissibleBase delegate; - private final String name; + private final VerboseCheckTarget verboseCheckTarget; // remains false until the object has been constructed // necessary to catch the superclass call to #recalculatePermissions on init @@ -64,12 +65,12 @@ public class MonitoredPermissibleBase extends PermissibleBase { this.plugin = plugin; this.delegate = delegate; - this.name = name; + this.verboseCheckTarget = VerboseCheckTarget.internal(name); this.initialised = true; } private void logCheck(PermissionCheckEvent.Origin origin, String permission, boolean result) { - this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(Tristate.of(result))); + this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.verboseCheckTarget, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(Tristate.of(result))); this.plugin.getPermissionRegistry().offer(permission); } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java index a5acf496f..18ddad379 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java @@ -31,6 +31,8 @@ import me.lucko.luckperms.common.calculator.result.TristateResult; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.query.QueryOptionsImpl; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; +import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin; import net.luckperms.api.query.QueryOptions; import net.luckperms.api.util.Tristate; @@ -70,7 +72,7 @@ public class BungeePermissionCheckListener implements Listener { } QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player); - Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result(); + Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), Origin.PLATFORM_PERMISSION_CHECK).result(); if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { return; // just use the result provided by the proxy when the event was created } @@ -99,7 +101,7 @@ public class BungeePermissionCheckListener implements Listener { } QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player); - Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK).result(); + Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), Origin.PLATFORM_LOOKUP_CHECK).result(); if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { return; // just use the result provided by the proxy when the event was created } @@ -118,9 +120,9 @@ public class BungeePermissionCheckListener implements Listener { String permission = e.getPermission(); Tristate result = Tristate.of(e.hasPermission()); - String name = "internal/" + e.getSender().getName(); + VerboseCheckTarget target = VerboseCheckTarget.internal(e.getSender().getName()); - this.plugin.getVerboseHandler().offerPermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK, name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result)); + this.plugin.getVerboseHandler().offerPermissionCheckEvent(Origin.PLATFORM_PERMISSION_CHECK, target, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result)); this.plugin.getPermissionRegistry().offer(permission); } @@ -135,9 +137,9 @@ public class BungeePermissionCheckListener implements Listener { String permission = e.getPermission(); Tristate result = e.getResult(); - String name = "internal/" + e.getSender().getName(); + VerboseCheckTarget target = VerboseCheckTarget.internal(e.getSender().getName()); - this.plugin.getVerboseHandler().offerPermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result)); + this.plugin.getVerboseHandler().offerPermissionCheckEvent(Origin.PLATFORM_LOOKUP_CHECK, target, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result)); this.plugin.getPermissionRegistry().offer(permission); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/CacheMetadata.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/CacheMetadata.java index 29ed022a3..84c9095ac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/CacheMetadata.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/CacheMetadata.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.cacheddata; import me.lucko.luckperms.common.model.HolderType; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import net.luckperms.api.cacheddata.CachedData; import net.luckperms.api.query.QueryOptions; @@ -41,18 +42,18 @@ public class CacheMetadata { private final HolderType holderType; /** - * The name of the object which owns the cache + * The information about the holder for verbose checks */ - private final String objectName; + private final VerboseCheckTarget verboseCheckInfo; /** * The query options */ private final QueryOptions queryOptions; - public CacheMetadata(HolderType holderType, String objectName, QueryOptions queryOptions) { + public CacheMetadata(HolderType holderType, VerboseCheckTarget verboseCheckInfo, QueryOptions queryOptions) { this.holderType = holderType; - this.objectName = objectName; + this.verboseCheckInfo = verboseCheckInfo; this.queryOptions = queryOptions; } @@ -60,8 +61,8 @@ public class CacheMetadata { return this.holderType; } - public String getObjectName() { - return this.objectName; + public VerboseCheckTarget getVerboseCheckInfo() { + return this.verboseCheckInfo; } public QueryOptions getQueryOptions() { diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java index dfe527993..eae5955ad 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.cacheddata; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.HolderType; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import net.luckperms.api.cacheddata.CachedDataManager; import net.luckperms.api.query.QueryOptions; @@ -42,7 +43,7 @@ public class GroupCachedDataManager extends HolderCachedDataManager imple @Override protected CacheMetadata getMetadataForQueryOptions(QueryOptions queryOptions) { - return new CacheMetadata(HolderType.GROUP, this.holder.getPlainDisplayName(), queryOptions); + return new CacheMetadata(HolderType.GROUP, VerboseCheckTarget.group(this.holder), queryOptions); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java index 672dc5d1d..36b132d1c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.cacheddata; import me.lucko.luckperms.common.model.HolderType; import me.lucko.luckperms.common.model.User; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import net.luckperms.api.cacheddata.CachedDataManager; import net.luckperms.api.query.QueryOptions; @@ -42,7 +43,7 @@ public class UserCachedDataManager extends HolderCachedDataManager impleme @Override protected CacheMetadata getMetadataForQueryOptions(QueryOptions queryOptions) { - return new CacheMetadata(HolderType.USER, this.holder.getPlainDisplayName(), queryOptions); + return new CacheMetadata(HolderType.USER, VerboseCheckTarget.user(this.holder), queryOptions); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java index 22af9e28c..f65b7678a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java @@ -28,7 +28,6 @@ package me.lucko.luckperms.common.cacheddata.type; import com.google.common.collect.ForwardingMap; import me.lucko.luckperms.common.cacheddata.CacheMetadata; -import me.lucko.luckperms.common.model.HolderType; import me.lucko.luckperms.common.node.types.Prefix; import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -53,39 +52,30 @@ public class MetaCache extends SimpleMetaCache implements CachedMetaData { /** The metadata for this cache */ private final CacheMetadata metadata; - /** The object name passed to the verbose handler when checks are made */ - private final String verboseCheckTarget; - public MetaCache(LuckPermsPlugin plugin, QueryOptions queryOptions, CacheMetadata metadata, MetaAccumulator sourceMeta) { super(plugin, queryOptions, sourceMeta); this.plugin = plugin; this.metadata = metadata; - - if (this.metadata.getHolderType() == HolderType.GROUP) { - this.verboseCheckTarget = "group/" + this.metadata.getObjectName(); - } else { - this.verboseCheckTarget = this.metadata.getObjectName(); - } } @Override public String getMetaValue(String key, MetaCheckEvent.Origin origin) { String value = super.getMetaValue(key, origin); - this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), key, String.valueOf(value)); + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.metadata.getVerboseCheckInfo(), this.metadata.getQueryOptions(), key, String.valueOf(value)); return value; } @Override public String getPrefix(MetaCheckEvent.Origin origin) { String value = super.getPrefix(origin); - this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), Prefix.NODE_KEY, String.valueOf(value)); + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.metadata.getVerboseCheckInfo(), this.metadata.getQueryOptions(), Prefix.NODE_KEY, String.valueOf(value)); return value; } @Override public String getSuffix(MetaCheckEvent.Origin origin) { String value = super.getSuffix(origin); - this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), Suffix.NODE_KEY, String.valueOf(value)); + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.metadata.getVerboseCheckInfo(), this.metadata.getQueryOptions(), Suffix.NODE_KEY, String.valueOf(value)); return value; } @@ -97,14 +87,14 @@ public class MetaCache extends SimpleMetaCache implements CachedMetaData { @Override public int getWeight(MetaCheckEvent.Origin origin) { int value = super.getWeight(origin); - this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), "weight", String.valueOf(value)); + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.metadata.getVerboseCheckInfo(), this.metadata.getQueryOptions(), "weight", String.valueOf(value)); return value; } @Override public @Nullable String getPrimaryGroup(MetaCheckEvent.Origin origin) { String value = super.getPrimaryGroup(origin); - this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), "primarygroup", String.valueOf(value)); + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.metadata.getVerboseCheckInfo(), this.metadata.getQueryOptions(), "primarygroup", String.valueOf(value)); return value; } @@ -130,7 +120,7 @@ public class MetaCache extends SimpleMetaCache implements CachedMetaData { String key = (String) k; List values = super.get(key); - MetaCache.this.plugin.getVerboseHandler().offerMetaCheckEvent(this.origin, MetaCache.this.verboseCheckTarget, MetaCache.this.metadata.getQueryOptions(), key, String.valueOf(values)); + MetaCache.this.plugin.getVerboseHandler().offerMetaCheckEvent(this.origin, MetaCache.this.metadata.getVerboseCheckInfo(), MetaCache.this.metadata.getQueryOptions(), key, String.valueOf(values)); return values; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java b/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java index bde9a65bb..d878b4095 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java @@ -29,7 +29,6 @@ import me.lucko.luckperms.common.cache.LoadingMap; import me.lucko.luckperms.common.cacheddata.CacheMetadata; import me.lucko.luckperms.common.calculator.processor.PermissionProcessor; import me.lucko.luckperms.common.calculator.result.TristateResult; -import me.lucko.luckperms.common.model.HolderType; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent; @@ -56,19 +55,10 @@ public class PermissionCalculator implements Function { /** Loading cache for permission checks */ private final LoadingMap lookupCache = LoadingMap.of(this); - /** The object name passed to the verbose handler when checks are made */ - private final String verboseCheckTarget; - public PermissionCalculator(LuckPermsPlugin plugin, CacheMetadata metadata, Collection processors) { this.plugin = plugin; this.metadata = metadata; this.processors = processors.toArray(new PermissionProcessor[0]); - - if (this.metadata.getHolderType() == HolderType.GROUP) { - this.verboseCheckTarget = "group/" + this.metadata.getObjectName(); - } else { - this.verboseCheckTarget = this.metadata.getObjectName(); - } } /** @@ -85,7 +75,7 @@ public class PermissionCalculator implements Function { TristateResult result = this.lookupCache.get(permission); // log this permission lookup to the verbose handler - this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), permission, result); + this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.metadata.getVerboseCheckInfo(), this.metadata.getQueryOptions(), permission, result); // return the result return result; diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseCheckTarget.java b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseCheckTarget.java new file mode 100644 index 000000000..50d0e82d0 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseCheckTarget.java @@ -0,0 +1,113 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * 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.common.verbose; + +import me.lucko.luckperms.common.model.Group; +import me.lucko.luckperms.common.model.User; + +import net.luckperms.api.model.PermissionHolder; + +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.Objects; +import java.util.UUID; + +public class VerboseCheckTarget { + + public static final String USER_TYPE = PermissionHolder.Identifier.USER_TYPE; + public static final String GROUP_TYPE = PermissionHolder.Identifier.GROUP_TYPE; + public static final String INTERNAL_TYPE = "internal"; + + public static VerboseCheckTarget user(User user) { + return new VerboseCheckTarget(USER_TYPE, user.getPlainDisplayName(), user.getUniqueId()); + } + + public static VerboseCheckTarget group(Group group) { + return new VerboseCheckTarget(GROUP_TYPE, group.getPlainDisplayName(), null); + } + + public static VerboseCheckTarget internal(String name) { + return new VerboseCheckTarget(INTERNAL_TYPE, name, null); + } + + public static VerboseCheckTarget of(String type, String name) { + return new VerboseCheckTarget(type, name, null); + } + + private final String type; + private final String name; + private final UUID id; + private final String desc; + + private VerboseCheckTarget(String type, String name, UUID id) { + this.type = type; + this.name = name; + this.id = id; + + if (this.type.equals(USER_TYPE)) { + this.desc = this.name; + } else { + this.desc = this.type + '/' + this.name; + } + } + + public String getType() { + return this.type; + } + + public String getName() { + return this.name; + } + + public @Nullable UUID getId() { + return this.id; + } + + public String describe() { + return this.desc; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + VerboseCheckTarget that = (VerboseCheckTarget) o; + return this.type.equals(that.type) && this.name.equals(that.name) && Objects.equals(this.id, that.id); + } + + @Override + public int hashCode() { + return Objects.hash(this.type, this.name, this.id); + } + + @Override + public String toString() { + return "VerboseCheckTarget{" + + "type=" + this.type + ", " + + "name=" + this.name + ", " + + "id=" + this.id + '}'; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseHandler.java b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseHandler.java index ae0e3aae6..98a09042f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseHandler.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseHandler.java @@ -74,7 +74,7 @@ public class VerboseHandler implements AutoCloseable { * @param permission the permission which was checked for * @param result the result of the permission check */ - public void offerPermissionCheckEvent(PermissionCheckEvent.Origin origin, String checkTarget, QueryOptions checkQueryOptions, String permission, TristateResult result) { + public void offerPermissionCheckEvent(PermissionCheckEvent.Origin origin, VerboseCheckTarget checkTarget, QueryOptions checkQueryOptions, String permission, TristateResult result) { // don't bother even processing the check if there are no listeners registered if (!this.listening) { return; @@ -100,7 +100,7 @@ public class VerboseHandler implements AutoCloseable { * @param key the meta key which was checked for * @param result the result of the meta check */ - public void offerMetaCheckEvent(MetaCheckEvent.Origin origin, String checkTarget, QueryOptions checkQueryOptions, String key, String result) { + public void offerMetaCheckEvent(MetaCheckEvent.Origin origin, VerboseCheckTarget checkTarget, QueryOptions checkQueryOptions, String key, String result) { // don't bother even processing the check if there are no listeners registered if (!this.listening) { return; diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java index 2d92f44a8..8d942b90b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java @@ -155,14 +155,14 @@ public class VerboseListener { if (event instanceof PermissionCheckEvent) { PermissionCheckEvent permissionEvent = (PermissionCheckEvent) event; Message.VERBOSE_LOG_PERMISSION.send(this.notifiedSender, - permissionEvent.getCheckTarget(), + permissionEvent.getCheckTarget().describe(), permissionEvent.getPermission(), permissionEvent.getResult().result() ); } else if (event instanceof MetaCheckEvent) { MetaCheckEvent metaEvent = (MetaCheckEvent) event; Message.VERBOSE_LOG_META.send(this.notifiedSender, - metaEvent.getCheckTarget(), + metaEvent.getCheckTarget().describe(), metaEvent.getKey(), metaEvent.getResult() ); @@ -177,14 +177,14 @@ public class VerboseListener { if (event instanceof PermissionCheckEvent) { PermissionCheckEvent permissionEvent = (PermissionCheckEvent) event; component = Message.VERBOSE_LOG_PERMISSION.build( - permissionEvent.getCheckTarget(), + permissionEvent.getCheckTarget().describe(), permissionEvent.getPermission(), permissionEvent.getResult().result() ); } else if (event instanceof MetaCheckEvent) { MetaCheckEvent metaEvent = (MetaCheckEvent) event; component = Message.VERBOSE_LOG_META.build( - metaEvent.getCheckTarget(), + metaEvent.getCheckTarget().describe(), metaEvent.getKey(), metaEvent.getResult() ); diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/event/MetaCheckEvent.java b/common/src/main/java/me/lucko/luckperms/common/verbose/event/MetaCheckEvent.java index d3eeb3dba..6c74b70ae 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/event/MetaCheckEvent.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/event/MetaCheckEvent.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.verbose.event; import me.lucko.luckperms.common.util.gson.JObject; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import net.luckperms.api.query.QueryOptions; @@ -46,7 +47,7 @@ public class MetaCheckEvent extends VerboseEvent { */ private final String result; - public MetaCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, long checkTime, Throwable checkTrace, String checkThread, String key, String result) { + public MetaCheckEvent(Origin origin, VerboseCheckTarget checkTarget, QueryOptions checkQueryOptions, long checkTime, Throwable checkTrace, String checkThread, String key, String result) { super(checkTarget, checkQueryOptions, checkTime, checkTrace, checkThread); this.origin = origin; this.key = key; @@ -76,7 +77,7 @@ public class MetaCheckEvent extends VerboseEvent { @Override public boolean eval(String variable) { return variable.equals("meta") || - getCheckTarget().equalsIgnoreCase(variable) || + getCheckTarget().describe().equalsIgnoreCase(variable) || getKey().toLowerCase().startsWith(variable.toLowerCase()) || getResult().equalsIgnoreCase(variable); } diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/event/PermissionCheckEvent.java b/common/src/main/java/me/lucko/luckperms/common/verbose/event/PermissionCheckEvent.java index 5cb9f03f0..48b200ab9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/event/PermissionCheckEvent.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/event/PermissionCheckEvent.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.verbose.event; import me.lucko.luckperms.common.calculator.result.TristateResult; import me.lucko.luckperms.common.util.gson.JObject; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import net.luckperms.api.query.QueryOptions; @@ -47,7 +48,7 @@ public class PermissionCheckEvent extends VerboseEvent { */ private final TristateResult result; - public PermissionCheckEvent(Origin origin, String checkTarget, QueryOptions checkQueryOptions, long checkTime, Throwable checkTrace, String checkThread, String permission, TristateResult result) { + public PermissionCheckEvent(Origin origin, VerboseCheckTarget checkTarget, QueryOptions checkQueryOptions, long checkTime, Throwable checkTrace, String checkThread, String permission, TristateResult result) { super(checkTarget, checkQueryOptions, checkTime, checkTrace, checkThread); this.origin = origin; this.permission = permission; @@ -89,7 +90,7 @@ public class PermissionCheckEvent extends VerboseEvent { @Override public boolean eval(String variable) { return variable.equals("permission") || - getCheckTarget().equalsIgnoreCase(variable) || + getCheckTarget().describe().equalsIgnoreCase(variable) || getPermission().toLowerCase().startsWith(variable.toLowerCase()) || getResult().result().name().equalsIgnoreCase(variable); } diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java b/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java index 2ab503a66..aff8d66a8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java @@ -30,6 +30,7 @@ import com.google.gson.JsonObject; import me.lucko.luckperms.common.util.StackTracePrinter; import me.lucko.luckperms.common.util.gson.JArray; import me.lucko.luckperms.common.util.gson.JObject; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import me.lucko.luckperms.common.verbose.expression.BooleanExpressionCompiler.VariableEvaluator; import net.luckperms.api.context.Context; @@ -37,6 +38,7 @@ import net.luckperms.api.query.QueryMode; import net.luckperms.api.query.QueryOptions; import java.util.Objects; +import java.util.UUID; /** * Represents a verbose event. @@ -46,7 +48,7 @@ public abstract class VerboseEvent implements VariableEvaluator { /** * The name of the entity which was checked */ - private final String checkTarget; + private final VerboseCheckTarget checkTarget; /** * The query options used for the check @@ -68,7 +70,7 @@ public abstract class VerboseEvent implements VariableEvaluator { */ private final String checkThread; - protected VerboseEvent(String checkTarget, QueryOptions checkQueryOptions, long checkTime, Throwable checkTrace, String checkThread) { + protected VerboseEvent(VerboseCheckTarget checkTarget, QueryOptions checkQueryOptions, long checkTime, Throwable checkTrace, String checkThread) { this.checkTarget = checkTarget; this.checkQueryOptions = checkQueryOptions; this.checkTime = checkTime; @@ -76,7 +78,7 @@ public abstract class VerboseEvent implements VariableEvaluator { this.checkThread = checkThread; } - public String getCheckTarget() { + public VerboseCheckTarget getCheckTarget() { return this.checkTarget; } @@ -101,7 +103,15 @@ public abstract class VerboseEvent implements VariableEvaluator { public JsonObject toJson(StackTracePrinter tracePrinter) { return new JObject() .add("who", new JObject() - .add("identifier", this.checkTarget) + .add("identifier", this.checkTarget.describe()) + .add("type", this.checkTarget.getType()) + .add("name", this.checkTarget.getName()) + .consume(obj -> { + UUID uuid = this.checkTarget.getId(); + if (uuid != null) { + obj.add("uuid", uuid.toString()); + } + }) ) .add("queryMode", this.checkQueryOptions.mode().name().toLowerCase()) .consume(obj -> { diff --git a/fabric/src/main/java/me/lucko/luckperms/fabric/listeners/PermissionCheckListener.java b/fabric/src/main/java/me/lucko/luckperms/fabric/listeners/PermissionCheckListener.java index adaab827f..515bd5d7b 100644 --- a/fabric/src/main/java/me/lucko/luckperms/fabric/listeners/PermissionCheckListener.java +++ b/fabric/src/main/java/me/lucko/luckperms/fabric/listeners/PermissionCheckListener.java @@ -28,6 +28,8 @@ package me.lucko.luckperms.fabric.listeners; import me.lucko.fabric.api.permissions.v0.PermissionCheckEvent; import me.lucko.luckperms.common.calculator.result.TristateResult; import me.lucko.luckperms.common.query.QueryOptionsImpl; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; +import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin; import me.lucko.luckperms.fabric.LPFabricPlugin; import me.lucko.luckperms.fabric.model.MixinUser; @@ -79,7 +81,9 @@ public class PermissionCheckListener { private TriState onOtherPermissionCheck(CommandSource source, String permission) { if (source instanceof ServerCommandSource) { String name = ((ServerCommandSource) source).getName(); - this.plugin.getVerboseHandler().offerPermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK, name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.UNDEFINED); + VerboseCheckTarget target = VerboseCheckTarget.internal(name); + + this.plugin.getVerboseHandler().offerPermissionCheckEvent(Origin.PLATFORM_PERMISSION_CHECK, target, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.UNDEFINED); this.plugin.getPermissionRegistry().offer(permission); } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/MonitoredPermissibleBase.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/MonitoredPermissibleBase.java index c333f9359..d728d4014 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/MonitoredPermissibleBase.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/inject/permissible/MonitoredPermissibleBase.java @@ -28,6 +28,7 @@ package me.lucko.luckperms.nukkit.inject.permissible; import me.lucko.luckperms.common.calculator.result.TristateResult; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.query.QueryOptionsImpl; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import me.lucko.luckperms.common.verbose.VerboseHandler; import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent; @@ -50,7 +51,7 @@ import java.util.Map; public class MonitoredPermissibleBase extends PermissibleBase { final LuckPermsPlugin plugin; private final PermissibleBase delegate; - private final String name; + private final VerboseCheckTarget verboseCheckTarget; // remains false until the object has been constructed // necessary to catch the superclass call to #recalculatePermissions on init @@ -63,12 +64,12 @@ public class MonitoredPermissibleBase extends PermissibleBase { this.plugin = plugin; this.delegate = delegate; - this.name = name; + this.verboseCheckTarget = VerboseCheckTarget.internal(name); this.initialised = true; } private void logCheck(PermissionCheckEvent.Origin origin, String permission, boolean result) { - this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(Tristate.of(result))); + this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.verboseCheckTarget, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(Tristate.of(result))); this.plugin.getPermissionRegistry().offer(permission); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java index 389192480..eb03ca20a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java @@ -39,6 +39,7 @@ import me.lucko.luckperms.common.calculator.processor.WildcardProcessor; import me.lucko.luckperms.common.metastacking.SimpleMetaStackDefinition; import me.lucko.luckperms.common.metastacking.StandardStackElements; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import me.lucko.luckperms.sponge.calculator.FixedDefaultsProcessor; import net.luckperms.api.metastacking.DuplicateRemovalFunction; @@ -67,7 +68,8 @@ public class CalculatedSubjectCachedDataManager extends AbstractCachedDataManage @Override protected CacheMetadata getMetadataForQueryOptions(QueryOptions queryOptions) { - return new CacheMetadata(null, this.subject.getParentCollection().getIdentifier() + "/" + this.subject.getIdentifier(), queryOptions); + VerboseCheckTarget target = VerboseCheckTarget.of(this.subject.getParentCollection().getIdentifier(), this.subject.getIdentifier()); + return new CacheMetadata(null, target, queryOptions); } @Override diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/MonitoringPermissionCheckListener.java b/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/MonitoringPermissionCheckListener.java index 44bed168b..81db28ec4 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/MonitoringPermissionCheckListener.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/listeners/MonitoringPermissionCheckListener.java @@ -35,6 +35,7 @@ import com.velocitypowered.api.proxy.Player; import me.lucko.luckperms.common.calculator.result.TristateResult; import me.lucko.luckperms.common.query.QueryOptionsImpl; +import me.lucko.luckperms.common.verbose.VerboseCheckTarget; import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent; import me.lucko.luckperms.velocity.LPVelocityPlugin; import me.lucko.luckperms.velocity.service.CompatibilityUtil; @@ -75,12 +76,12 @@ public class MonitoringPermissionCheckListener { } private final class MonitoredPermissionFunction implements PermissionFunction { - private final String name; + private final VerboseCheckTarget verboseCheckTarget; private final PermissionFunction delegate; MonitoredPermissionFunction(PermissionSubject subject, PermissionFunction delegate) { this.delegate = delegate; - this.name = "internal/" + determineName(subject); + this.verboseCheckTarget = VerboseCheckTarget.internal(determineName(subject)); } @Override @@ -90,7 +91,7 @@ public class MonitoringPermissionCheckListener { // report result Tristate result = CompatibilityUtil.convertTristate(setting); - MonitoringPermissionCheckListener.this.plugin.getVerboseHandler().offerPermissionCheckEvent(PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, this.name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result)); + MonitoringPermissionCheckListener.this.plugin.getVerboseHandler().offerPermissionCheckEvent(PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, this.verboseCheckTarget, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result)); MonitoringPermissionCheckListener.this.plugin.getPermissionRegistry().offer(permission); return setting;