Refactor meta stacking to be mapped in MetaCache - towards lucko/LuckPermsPlaceholders#1
This commit is contained in:
@@ -58,9 +58,9 @@ public class SpongeSenderFactory extends SenderFactory<CommandSource> {
|
||||
return Constants.CONSOLE_UUID;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void sendMessage(CommandSource source, String s) {
|
||||
//noinspection deprecation
|
||||
source.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(s));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,18 @@ public class SpongeCalculatorLink implements ContextCalculator<Subject> {
|
||||
|
||||
@Override
|
||||
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
||||
Set<Context> contexts = new HashSet<>();
|
||||
Set<Context> contexts = new HashSet<Context>() {
|
||||
|
||||
// don't allow null elements
|
||||
@Override
|
||||
public boolean add(Context context) {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("context");
|
||||
}
|
||||
|
||||
return super.add(context);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
delegate.accumulateContexts(subject, contexts);
|
||||
|
||||
@@ -37,6 +37,7 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.caching.MetaAccumulator;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
@@ -197,10 +198,10 @@ public class SpongeGroup extends Group {
|
||||
try (Timing ignored = plugin.getService().getPlugin().getTimings().time(LPTiming.GROUP_GET_OPTION)) {
|
||||
Optional<String> option;
|
||||
if (s.equalsIgnoreCase("prefix")) {
|
||||
option = getChatMeta(contexts, true);
|
||||
option = getChatMeta(contexts, MetaType.PREFIX);
|
||||
|
||||
} else if (s.equalsIgnoreCase("suffix")) {
|
||||
option = getChatMeta(contexts, false);
|
||||
option = getChatMeta(contexts, MetaType.SUFFIX);
|
||||
|
||||
} else {
|
||||
option = getMeta(contexts, s);
|
||||
@@ -226,13 +227,9 @@ public class SpongeGroup extends Group {
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<String> getChatMeta(ImmutableContextSet contexts, boolean prefix) {
|
||||
private Optional<String> getChatMeta(ImmutableContextSet contexts, MetaType type) {
|
||||
MetaAccumulator metaAccumulator = parent.accumulateMeta(null, null, ExtractedContexts.generate(plugin.getService().calculateContexts(contexts)));
|
||||
if (prefix) {
|
||||
return Optional.ofNullable(metaAccumulator.getPrefixStack().toFormattedString());
|
||||
} else {
|
||||
return Optional.ofNullable(metaAccumulator.getSuffixStack().toFormattedString());
|
||||
}
|
||||
return Optional.ofNullable(metaAccumulator.getStack(type).toFormattedString());
|
||||
}
|
||||
|
||||
private Optional<String> getMeta(ImmutableContextSet contexts, String key) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.metastacking.MetaType;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
@@ -369,26 +370,24 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_SET_OPTION)) {
|
||||
if (key.equalsIgnoreCase("prefix") || key.equalsIgnoreCase("suffix")) {
|
||||
// special handling.
|
||||
String type = key.toLowerCase();
|
||||
boolean prefix = type.equals("prefix");
|
||||
MetaType type = MetaType.valueOf(key.toUpperCase());
|
||||
|
||||
// remove all prefixes/suffixes from the user
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
.filter(n -> prefix ? n.isPrefix() : n.isSuffix())
|
||||
.filter(type::matches)
|
||||
.filter(n -> n.getFullContexts().equals(context))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
|
||||
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, null, ExtractedContexts.generate(service.calculateContexts(context)));
|
||||
int priority = (type.equals("prefix") ? metaAccumulator.getPrefixes() : metaAccumulator.getSuffixes()).keySet().stream()
|
||||
.mapToInt(e -> e).max().orElse(0);
|
||||
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
|
||||
priority += 10;
|
||||
|
||||
if (enduring) {
|
||||
holder.setPermission(NodeFactory.makeChatMetaNode(type.equals("prefix"), priority, value).withExtraContext(context).build());
|
||||
holder.setPermission(NodeFactory.makeChatMetaNode(type, priority, value).withExtraContext(context).build());
|
||||
} else {
|
||||
holder.setTransientPermission(NodeFactory.makeChatMetaNode(type.equals("prefix"), priority, value).withExtraContext(context).build());
|
||||
holder.setTransientPermission(NodeFactory.makeChatMetaNode(type, priority, value).withExtraContext(context).build());
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user