mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-30 12:11:49 +01:00
Improve the way meta lookups are caught & reported to the verbose handler
This commit is contained in:
parent
8584a9b72c
commit
9988011308
@ -133,7 +133,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
User user = this.permissionHook.lookupUser(uuid);
|
User user = this.permissionHook.lookupUser(uuid);
|
||||||
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
Contexts contexts = this.permissionHook.contextForLookup(user, world);
|
||||||
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
MetaCache metaData = user.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getMetaValue(key, MetaCheckEvent.Origin.THIRD_PARTY_API);
|
String ret = metaData.getMeta(MetaCheckEvent.Origin.THIRD_PARTY_API).get(key);
|
||||||
if (log()) {
|
if (log()) {
|
||||||
logMsg("#getUserMeta: %s - %s - %s - %s", user.getPlainDisplayName(), contexts.getContexts().toMultimap(), key, ret);
|
logMsg("#getUserMeta: %s - %s - %s - %s", user.getPlainDisplayName(), contexts.getContexts().toMultimap(), key, ret);
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ public class VaultChatHook extends AbstractVaultChat {
|
|||||||
}
|
}
|
||||||
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
Contexts contexts = this.permissionHook.contextForLookup(null, world);
|
||||||
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
MetaCache metaData = group.getCachedData().getMetaData(contexts);
|
||||||
String ret = metaData.getMetaValue(key, MetaCheckEvent.Origin.THIRD_PARTY_API);
|
String ret = metaData.getMeta(MetaCheckEvent.Origin.THIRD_PARTY_API).get(key);
|
||||||
if (log()) {
|
if (log()) {
|
||||||
logMsg("#getGroupMeta: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), key, ret);
|
logMsg("#getGroupMeta: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), key, ret);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.caching.type;
|
package me.lucko.luckperms.common.caching.type;
|
||||||
|
|
||||||
|
import com.google.common.collect.ForwardingListMultimap;
|
||||||
|
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;
|
||||||
@ -152,22 +154,20 @@ public class MetaCache implements MetaData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ListMultimap<String, String> getMetaMultimap() {
|
public @NonNull ListMultimap<String, String> getMetaMultimap() {
|
||||||
return this.metaMultimap;
|
return getMetaMultimap(MetaCheckEvent.Origin.LUCKPERMS_API);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListMultimap<String, String> getMetaMultimap(MetaCheckEvent.Origin origin) {
|
||||||
|
return new VerboseLoggedMetaMultimap(origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Map<String, String> getMeta() {
|
public @NonNull Map<String, String> getMeta() {
|
||||||
return this.meta;
|
return getMeta(MetaCheckEvent.Origin.LUCKPERMS_API);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMetaValue(String key, MetaCheckEvent.Origin origin) {
|
public Map<String, String> getMeta(MetaCheckEvent.Origin origin) {
|
||||||
String value = this.meta.get(key);
|
return new VerboseLoggedMetaMap(origin);
|
||||||
|
|
||||||
// log this meta lookup to the verbose handler
|
|
||||||
VerboseHandler verboseHandler = this.metadata.getParentContainer().getPlugin().getVerboseHandler();
|
|
||||||
verboseHandler.offerMetaCheckEvent(origin, this.metadata.getObjectName(), this.metadata.getContext(), key, String.valueOf(value));
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -180,4 +180,54 @@ public class MetaCache implements MetaData {
|
|||||||
return this.suffixes;
|
return this.suffixes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class VerboseLoggedMetaMap extends ForwardingMap<String, String> {
|
||||||
|
private final MetaCheckEvent.Origin origin;
|
||||||
|
|
||||||
|
private VerboseLoggedMetaMap(MetaCheckEvent.Origin origin) {
|
||||||
|
this.origin = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> delegate() {
|
||||||
|
return MetaCache.this.meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(Object key) {
|
||||||
|
String value = 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.getContext(), (String) key, String.valueOf(value));
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class VerboseLoggedMetaMultimap extends ForwardingListMultimap<String, String> {
|
||||||
|
private final MetaCheckEvent.Origin origin;
|
||||||
|
|
||||||
|
private VerboseLoggedMetaMultimap(MetaCheckEvent.Origin origin) {
|
||||||
|
this.origin = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ListMultimap<String, String> delegate() {
|
||||||
|
return MetaCache.this.metaMultimap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> get(String key) {
|
||||||
|
List<String> values = super.get(key);
|
||||||
|
|
||||||
|
// log this meta lookup to the verbose handler
|
||||||
|
VerboseHandler verboseHandler = MetaCache.this.metadata.getParentContainer().getPlugin().getVerboseHandler();
|
||||||
|
for (String value : values) {
|
||||||
|
verboseHandler.offerMetaCheckEvent(this.origin, MetaCache.this.metadata.getObjectName(), MetaCache.this.metadata.getContext(), key, String.valueOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -264,14 +264,14 @@ public class DebugCommand extends SingleCommand {
|
|||||||
})
|
})
|
||||||
.add("meta", () -> {
|
.add("meta", () -> {
|
||||||
JObject metaMap = new JObject();
|
JObject metaMap = new JObject();
|
||||||
for (Map.Entry<String, String> entry : metaData.getMeta().entrySet()) {
|
for (Map.Entry<String, String> entry : metaData.getMeta(MetaCheckEvent.Origin.INTERNAL).entrySet()) {
|
||||||
metaMap.add(entry.getKey(), entry.getValue());
|
metaMap.add(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return metaMap;
|
return metaMap;
|
||||||
})
|
})
|
||||||
.add("metaMap", () -> {
|
.add("metaMap", () -> {
|
||||||
JObject metaMultimap = new JObject();
|
JObject metaMultimap = new JObject();
|
||||||
for (Map.Entry<String, Collection<String>> entry : metaData.getMetaMultimap().asMap().entrySet()) {
|
for (Map.Entry<String, Collection<String>> entry : metaData.getMetaMultimap(MetaCheckEvent.Origin.INTERNAL).asMap().entrySet()) {
|
||||||
JArray values = new JArray();
|
JArray values = new JArray();
|
||||||
for (String v : entry.getValue()) {
|
for (String v : entry.getValue()) {
|
||||||
values.add(v);
|
values.add(v);
|
||||||
|
@ -121,7 +121,7 @@ public class UserInfo extends SubCommand<User> {
|
|||||||
suffix = "&f\"" + sussexValue + "&f\"";
|
suffix = "&f\"" + sussexValue + "&f\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
ListMultimap<String, String> metaMap = data.getMetaMultimap();
|
ListMultimap<String, String> metaMap = data.getMetaMultimap(MetaCheckEvent.Origin.INTERNAL);
|
||||||
if (!metaMap.isEmpty()) {
|
if (!metaMap.isEmpty()) {
|
||||||
meta = metaMap.entries().stream()
|
meta = metaMap.entries().stream()
|
||||||
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
|
.map(e -> MessageUtils.contextToString(plugin.getLocaleManager(), e.getKey(), e.getValue()))
|
||||||
|
@ -311,7 +311,7 @@ public abstract class CalculatedSubject implements LPSubject {
|
|||||||
@Override
|
@Override
|
||||||
public Optional<String> getOption(ImmutableContextSet contexts, String key) {
|
public Optional<String> getOption(ImmutableContextSet contexts, String key) {
|
||||||
Contexts lookupContexts = Contexts.of(contexts, Contexts.global().getSettings());
|
Contexts lookupContexts = Contexts.of(contexts, Contexts.global().getSettings());
|
||||||
return Optional.ofNullable(this.cachedData.getMetaData(lookupContexts).getMetaValue(key, MetaCheckEvent.Origin.PLATFORM_API));
|
return Optional.ofNullable(this.cachedData.getMetaData(lookupContexts).getMeta(MetaCheckEvent.Origin.PLATFORM_API).get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -153,7 +153,7 @@ public abstract class HolderSubject<T extends PermissionHolder> implements LPSub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String val = data.getMetaValue(s, MetaCheckEvent.Origin.PLATFORM_API);
|
String val = data.getMeta(MetaCheckEvent.Origin.PLATFORM_API).get(s);
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
return Optional.of(val);
|
return Optional.of(val);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user