Cleanup sponge service impl
This commit is contained in:
@@ -132,7 +132,7 @@ import java.util.stream.Stream;
|
||||
id = "luckperms",
|
||||
name = "LuckPerms",
|
||||
version = VersionData.VERSION,
|
||||
authors = {"Luck"},
|
||||
authors = "Luck",
|
||||
description = "A permissions plugin",
|
||||
url = "https://github.com/lucko/LuckPerms"
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.commands.sender.SenderFactory;
|
||||
import me.lucko.luckperms.common.constants.Constants;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.ComponentSerializers;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class OptionClear extends SubCommand<LPSubjectData> {
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a.");
|
||||
} else {
|
||||
subjectData.clearOptions(contextSet);
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
for (Map.Entry<ImmutableContextSet, ImmutableMap<String, String>> e : options.entrySet()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.optionsToString(e.getValue()));
|
||||
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.optionsToString(e.getValue()));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -72,7 +72,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
CommandUtils.sendPluginMessage(sender, "&aShowing options matching contexts &b" +
|
||||
SpongeUtils.contextToString(contextSet) + "&a.\n" + SpongeUtils.optionsToString(options));
|
||||
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.optionsToString(options));
|
||||
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class OptionSet extends SubCommand<LPSubjectData> {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
|
||||
|
||||
if (subjectData.setOption(contextSet, key, value).join()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
|
||||
CommandUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
|
||||
} else {
|
||||
CommandUtils.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?");
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class OptionUnset extends SubCommand<LPSubjectData> {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(1, args);
|
||||
|
||||
if (subjectData.unsetOption(contextSet, key).join()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
|
||||
CommandUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
|
||||
} else {
|
||||
CommandUtils.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?");
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ParentAdd extends SubCommand<LPSubjectData> {
|
||||
|
||||
if (subjectData.addParent(contextSet, subject.toReference()).join()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() +
|
||||
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
||||
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
|
||||
} else {
|
||||
CommandUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?");
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ParentClear extends SubCommand<LPSubjectData> {
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a.");
|
||||
} else {
|
||||
subjectData.clearParents(contextSet);
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
for (Map.Entry<ImmutableContextSet, ImmutableList<SubjectReference>> e : parents.entrySet()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.parentsToString(e.getValue()));
|
||||
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -73,7 +73,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
CommandUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &b" +
|
||||
SpongeUtils.contextToString(contextSet) + "&a.\n" + SpongeUtils.parentsToString(parents));
|
||||
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.parentsToString(parents));
|
||||
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ParentRemove extends SubCommand<LPSubjectData> {
|
||||
|
||||
if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() +
|
||||
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
||||
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
|
||||
} else {
|
||||
CommandUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?");
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class PermissionClear extends SubCommand<LPSubjectData> {
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a.");
|
||||
} else {
|
||||
subjectData.clearPermissions(contextSet);
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeUtils.contextToString(contextSet));
|
||||
CommandUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
for (Map.Entry<ImmutableContextSet, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.nodesToString(e.getValue()));
|
||||
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue()));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -72,7 +72,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
CommandUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &b" +
|
||||
SpongeUtils.contextToString(contextSet) + "&a.\n" + SpongeUtils.nodesToString(permissions));
|
||||
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.nodesToString(permissions));
|
||||
|
||||
}
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
@@ -50,11 +50,11 @@ public class PermissionSet extends SubCommand<LPSubjectData> {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
String node = args.get(0);
|
||||
Tristate tristate = SpongeUtils.parseTristate(1, args);
|
||||
Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
|
||||
|
||||
if (subjectData.setPermission(contextSet, node, tristate).join()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeUtils.contextToString(contextSet));
|
||||
CommandUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
|
||||
} else {
|
||||
CommandUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?");
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class SpongeUtils {
|
||||
public class SpongeCommandUtils {
|
||||
|
||||
public static Tristate parseTristate(int index, List<String> args) throws ArgumentUtils.ArgumentException {
|
||||
String s = args.get(index).toLowerCase();
|
||||
+3
-21
@@ -29,12 +29,11 @@ import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.context.DelegatingMutableContextSet;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@AllArgsConstructor
|
||||
@@ -43,26 +42,9 @@ public class ProxiedContextCalculator implements ContextCalculator<Subject> {
|
||||
|
||||
@Override
|
||||
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
||||
Set<Context> contexts = new NonNullContextHashSet();
|
||||
try {
|
||||
delegate.accumulateContexts(subject, contexts);
|
||||
accumulator.addAll(CompatibilityUtil.convertContexts(contexts));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Exception thrown by delegate Sponge calculator: " + delegate.getClass().getName(), e);
|
||||
}
|
||||
|
||||
Set<Context> contexts = new DelegatingMutableContextSet(accumulator);
|
||||
delegate.accumulateContexts(subject, contexts);
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
private final class NonNullContextHashSet extends HashSet<Context> {
|
||||
@Override
|
||||
public boolean add(Context context) {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("context");
|
||||
}
|
||||
|
||||
return super.add(context);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.node.NodeFactory;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeGroup extends Group {
|
||||
@@ -62,7 +63,7 @@ public class SpongeGroup extends Group {
|
||||
return this.spongeData;
|
||||
}
|
||||
|
||||
public static class GroupSubject implements LPSubject {
|
||||
public class GroupSubject implements LPSubject {
|
||||
private final SpongeGroup parent;
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
@@ -123,12 +124,16 @@ public class SpongeGroup extends Group {
|
||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
||||
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
||||
|
||||
for (String perm : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().keySet()) {
|
||||
if (!perm.startsWith("group.")) {
|
||||
for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||
if (!entry.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String groupName = perm.substring("group.".length());
|
||||
if (!entry.getKey().startsWith("group.")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String groupName = entry.getKey().substring("group.".length());
|
||||
if (plugin.getGroupManager().isLoaded(groupName)) {
|
||||
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
@@ -132,12 +133,16 @@ public class SpongeUser extends User {
|
||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
||||
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
||||
|
||||
for (String perm : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().keySet()) {
|
||||
if (!perm.startsWith("group.")) {
|
||||
for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||
if (!entry.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String groupName = perm.substring("group.".length());
|
||||
if (!entry.getKey().startsWith("group.")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String groupName = entry.getKey().substring("group.".length());
|
||||
if (plugin.getGroupManager().isLoaded(groupName)) {
|
||||
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings({"OptionalGetWithoutIsPresent", "unused"})
|
||||
@AllArgsConstructor
|
||||
public class LuckPermsSubjectData implements LPSubjectData {
|
||||
private final boolean enduring;
|
||||
|
||||
@@ -45,6 +45,7 @@ public class ProxyFactory {
|
||||
private static final boolean IS_API_7 = isApi7();
|
||||
private static boolean isApi7() {
|
||||
try {
|
||||
//noinspection JavaReflectionMemberAccess
|
||||
Subject.class.getDeclaredMethod("asSubjectReference");
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
+5
-6
@@ -36,7 +36,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
||||
import me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata;
|
||||
@@ -76,11 +75,11 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
private final Map<ImmutableContextSet, Set<SubjectReference>> parents = new ConcurrentHashMap<>();
|
||||
private final Map<ImmutableContextSet, Map<String, String>> options = new ConcurrentHashMap<>();
|
||||
|
||||
private final LoadingCache<ContextSet, CalculatorHolder> permissionCache = Caffeine.newBuilder()
|
||||
private final LoadingCache<ImmutableContextSet, CalculatorHolder> permissionCache = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||
.build(new CacheLoader<ContextSet, CalculatorHolder>() {
|
||||
.build(new CacheLoader<ImmutableContextSet, CalculatorHolder>() {
|
||||
@Override
|
||||
public CalculatorHolder load(ContextSet contexts) {
|
||||
public CalculatorHolder load(ImmutableContextSet contexts) {
|
||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||
processors.add(new MapProcessor());
|
||||
processors.add(new SpongeWildcardProcessor());
|
||||
@@ -100,7 +99,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
permissionCache.invalidateAll();
|
||||
}
|
||||
|
||||
public Tristate getPermissionValue(ContextSet contexts, String permission) {
|
||||
public Tristate getPermissionValue(ImmutableContextSet contexts, String permission) {
|
||||
return permissionCache.get(contexts).getCalculator().getPermissionValue(permission, CheckOrigin.INTERNAL);
|
||||
}
|
||||
|
||||
@@ -301,7 +300,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
private static <K, V> SortedMap<ImmutableContextSet, Map<K, V>> getRelevantEntries(ContextSet set, Map<ImmutableContextSet, Map<K, V>> map) {
|
||||
private static <K, V> SortedMap<ImmutableContextSet, Map<K, V>> getRelevantEntries(ImmutableContextSet set, Map<ImmutableContextSet, Map<K, V>> map) {
|
||||
ImmutableSortedMap.Builder<ImmutableContextSet, Map<K, V>> perms = ImmutableSortedMap.orderedBy(ContextSetComparator.reverse());
|
||||
|
||||
for (Map.Entry<ImmutableContextSet, Map<K, V>> e : map.entrySet()) {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.calculated;
|
||||
package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.calculated;
|
||||
package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -39,8 +39,6 @@ import me.lucko.luckperms.common.verbose.CheckOrigin;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.calculated.OptionLookupKey;
|
||||
import me.lucko.luckperms.sponge.service.calculated.PermissionLookupKey;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
||||
|
||||
Reference in New Issue
Block a user