Fix Sponge implementation, remove standalone module
This commit is contained in:
@@ -24,10 +24,12 @@ package me.lucko.luckperms;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.PlatformType;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
||||
import me.lucko.luckperms.calculators.CalculatorFactory;
|
||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.config.LPConfiguration;
|
||||
@@ -44,7 +46,6 @@ import me.lucko.luckperms.runnables.UpdateTask;
|
||||
import me.lucko.luckperms.storage.Datastore;
|
||||
import me.lucko.luckperms.storage.StorageFactory;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.SpongeUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LocaleManager;
|
||||
import me.lucko.luckperms.utils.LogFactory;
|
||||
@@ -101,6 +102,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
private LuckPermsService service;
|
||||
private LocaleManager localeManager;
|
||||
private ContextManager<Player> contextManager; // TODO convert this to use Subject instead of Player
|
||||
private CalculatorFactory calculatorFactory;
|
||||
|
||||
@Listener
|
||||
public void onEnable(GamePreInitializationEvent event) {
|
||||
@@ -138,6 +140,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
trackManager = new TrackManager();
|
||||
importer = new Importer(commandManager);
|
||||
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||
calculatorFactory = new SpongeCalculatorFactory(this);
|
||||
|
||||
contextManager = new ContextManager<>();
|
||||
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
|
||||
@@ -250,6 +253,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
return SpongeSenderFactory.get(this).wrap(game.getServer().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Contexts> getPreProcessContexts(boolean op) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlugin(String name) {
|
||||
return game.getPluginManager().getPlugin(name).get().getInstance().get();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* 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;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
||||
import me.lucko.luckperms.calculators.*;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class SpongeCalculatorFactory implements CalculatorFactory {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
@Override
|
||||
public PermissionCalculator build(Contexts contexts, User user, Map<String, Boolean> map) {
|
||||
List<PermissionProcessor> processors = new ArrayList<>(5);
|
||||
processors.add(new MapProcessor(map));
|
||||
if (plugin.getConfiguration().isApplyingWildcards()) {
|
||||
processors.add(new SpongeWildcardProcessor(map));
|
||||
processors.add(new WildcardProcessor(map));
|
||||
}
|
||||
if (plugin.getConfiguration().isApplyingRegex()) {
|
||||
processors.add(new RegexProcessor(map));
|
||||
}
|
||||
processors.add(new DefaultsProcessor(plugin.getService(), LuckPermsService.convertContexts(contexts.getContext())));
|
||||
|
||||
return new PermissionCalculator(plugin, user.getName(), plugin.getConfiguration().isDebugPermissionChecks(), processors);
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,23 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
||||
import me.lucko.luckperms.caching.UserData;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.AbstractListener;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.network.ClientConnectionEvent;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class SpongeListener extends AbstractListener {
|
||||
@@ -49,7 +59,6 @@ public class SpongeListener extends AbstractListener {
|
||||
|
||||
final GameProfile p = e.getProfile();
|
||||
onAsyncLogin(p.getUniqueId(), p.getName().get()); // Load the user into LuckPerms
|
||||
plugin.getService().getUserSubjects().load(p.getUniqueId()); // Load the user into the PermissionService
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -65,8 +74,26 @@ public class SpongeListener extends AbstractListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Refresh permissions again
|
||||
plugin.doAsync(user::refreshPermissions);
|
||||
// Attempt to pre-process some permissions for the user to save time later. Might not work, but it's better than nothing.
|
||||
Optional<Player> p = e.getCause().first(Player.class);
|
||||
if (p.isPresent()) {
|
||||
Map<String, String> context = plugin.getContextManager().giveApplicableContext(p.get(), new HashMap<>());
|
||||
|
||||
List<String> worlds = plugin.getGame().getServer().getWorlds().stream()
|
||||
.map(World::getName)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
plugin.doAsync(() -> {
|
||||
UserData data = user.getUserData();
|
||||
data.preCalculate(plugin.getService().calculateContexts(LuckPermsService.convertContexts(context)));
|
||||
|
||||
for (String world : worlds) {
|
||||
Map<String, String> modified = new HashMap<>(context);
|
||||
modified.put("world", world);
|
||||
data.preCalculate(plugin.getService().calculateContexts(LuckPermsService.convertContexts(modified)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
@@ -78,5 +105,6 @@ public class SpongeListener extends AbstractListener {
|
||||
@Listener
|
||||
public void onClientLeave(ClientConnectionEvent.Disconnect e) {
|
||||
onLeave(e.getTargetEntity().getUniqueId());
|
||||
plugin.getService().getUserSubjects().unload(plugin.getUuidCache().getUUID(e.getTargetEntity().getUniqueId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,18 +26,21 @@ import com.google.common.collect.ImmutableList;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.NodeTree;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
import org.spongepowered.api.service.permission.SubjectData;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.lucko.luckperms.utils.ArgumentChecker.unescapeCharacters;
|
||||
@@ -49,7 +52,7 @@ public class LuckPermsGroupSubject implements Subject {
|
||||
}
|
||||
|
||||
@Getter
|
||||
private PermissionHolder group;
|
||||
private Group group;
|
||||
|
||||
private LuckPermsService service;
|
||||
|
||||
@@ -59,7 +62,7 @@ public class LuckPermsGroupSubject implements Subject {
|
||||
@Getter
|
||||
private LuckPermsSubjectData transientSubjectData;
|
||||
|
||||
private LuckPermsGroupSubject(PermissionHolder group, LuckPermsService service) {
|
||||
private LuckPermsGroupSubject(Group group, LuckPermsService service) {
|
||||
this.group = group;
|
||||
this.subjectData = new LuckPermsSubjectData(true, service, group);
|
||||
this.transientSubjectData = new LuckPermsSubjectData(false, service, group);
|
||||
@@ -88,23 +91,22 @@ public class LuckPermsGroupSubject implements Subject {
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String node) {
|
||||
Map<String, String> context = new HashMap<>();
|
||||
for (Context c : contexts) {
|
||||
context.put(c.getKey(), c.getValue());
|
||||
Map<String, Boolean> permissions = group.getAllNodesFiltered(service.calculateContexts(contexts)).stream()
|
||||
.map(LocalizedNode::getNode)
|
||||
.collect(Collectors.toMap(Node::getPermission, Node::getValue));
|
||||
|
||||
Tristate t = NodeTree.of(permissions).get(node);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
switch (group.inheritsPermission(new me.lucko.luckperms.core.Node.Builder(node).withExtraContext(context).build())) {
|
||||
case UNDEFINED:
|
||||
return Tristate.UNDEFINED;
|
||||
case TRUE:
|
||||
return Tristate.TRUE;
|
||||
case FALSE:
|
||||
return Tristate.FALSE;
|
||||
default:
|
||||
return null;
|
||||
t = service.getGroupSubjects().getDefaults().getPermissionValue(contexts, node);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
// TODO
|
||||
t = service.getDefaults().getPermissionValue(contexts, node);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,39 +116,42 @@ public class LuckPermsGroupSubject implements Subject {
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(@NonNull Set<Context> contexts) {
|
||||
List<Subject> parents = new ArrayList<>();
|
||||
parents.addAll(subjectData.getParents(contexts));
|
||||
parents.addAll(transientSubjectData.getParents(contexts));
|
||||
return ImmutableList.copyOf(parents);
|
||||
List<Subject> subjects = group.getAllNodesFiltered(service.calculateContexts(contexts)).stream()
|
||||
.map(LocalizedNode::getNode)
|
||||
.filter(Node::isGroupNode)
|
||||
.map(Node::getGroupName)
|
||||
.map(s -> service.getGroupSubjects().get(s))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
subjects.addAll(service.getGroupSubjects().getDefaults().getParents(contexts));
|
||||
subjects.addAll(service.getDefaults().getParents(contexts));
|
||||
|
||||
return ImmutableList.copyOf(subjects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(Set<Context> set, String s) {
|
||||
Optional<String> option;
|
||||
if (s.equalsIgnoreCase("prefix")) {
|
||||
String prefix = getChatMeta(set, true, group);
|
||||
if (!prefix.equals("")) {
|
||||
return Optional.of(prefix);
|
||||
}
|
||||
option = getChatMeta(set, true);
|
||||
|
||||
} else if (s.equalsIgnoreCase("suffix")) {
|
||||
option = getChatMeta(set, false);
|
||||
|
||||
} else {
|
||||
option = getMeta(set, s);
|
||||
}
|
||||
|
||||
if (s.equalsIgnoreCase("suffix")) {
|
||||
String suffix = getChatMeta(set, false, group);
|
||||
if (!suffix.equals("")) {
|
||||
return Optional.of(suffix);
|
||||
}
|
||||
if (option.isPresent()) {
|
||||
return option;
|
||||
}
|
||||
|
||||
Map<String, String> transientOptions = subjectData.getOptions(set);
|
||||
if (transientOptions.containsKey(s)) {
|
||||
return Optional.of(transientOptions.get(s));
|
||||
option = service.getGroupSubjects().getDefaults().getOption(set, s);
|
||||
if (option.isPresent()) {
|
||||
return option;
|
||||
}
|
||||
|
||||
Map<String, String> enduringOptions = subjectData.getOptions(set);
|
||||
if (enduringOptions.containsKey(s)) {
|
||||
return Optional.of(enduringOptions.get(s));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
return service.getDefaults().getOption(set, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,19 +159,11 @@ public class LuckPermsGroupSubject implements Subject {
|
||||
return SubjectData.GLOBAL_CONTEXT;
|
||||
}
|
||||
|
||||
private String getChatMeta(Set<Context> contexts, boolean prefix, PermissionHolder holder) {
|
||||
if (holder == null) return "";
|
||||
|
||||
Map<String, String> context = contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||
String server = context.get("server");
|
||||
String world = context.get("world");
|
||||
context.remove("server");
|
||||
context.remove("world");
|
||||
|
||||
private Optional<String> getChatMeta(Set<Context> contexts, boolean prefix) {
|
||||
int priority = Integer.MIN_VALUE;
|
||||
String meta = null;
|
||||
|
||||
for (Node n : holder.getAllNodes(null, Contexts.allowAll())) {
|
||||
for (Node n : group.getAllNodesFiltered(service.calculateContexts(contexts))) {
|
||||
if (!n.getValue()) {
|
||||
continue;
|
||||
}
|
||||
@@ -175,18 +172,6 @@ public class LuckPermsGroupSubject implements Subject {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!n.shouldApplyOnServer(server, service.getPlugin().getConfiguration().isVaultIncludingGlobal(), false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!n.shouldApplyOnWorld(world, true, false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!n.shouldApplyWithContext(context, false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map.Entry<Integer, String> value = prefix ? n.getPrefix() : n.getSuffix();
|
||||
if (value.getKey() > priority) {
|
||||
meta = value.getValue();
|
||||
@@ -194,6 +179,27 @@ public class LuckPermsGroupSubject implements Subject {
|
||||
}
|
||||
}
|
||||
|
||||
return meta == null ? "" : unescapeCharacters(meta);
|
||||
return meta == null ? Optional.empty() : Optional.of(unescapeCharacters(meta));
|
||||
}
|
||||
|
||||
private Optional<String> getMeta(Set<Context> contexts, String key) {
|
||||
for (Node n : group.getAllNodesFiltered(service.calculateContexts(contexts))) {
|
||||
if (!n.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!n.isMeta()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map.Entry<String, String> m = n.getMeta();
|
||||
if (!m.getKey().equalsIgnoreCase(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return Optional.of(m.getValue());
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.*;
|
||||
import me.lucko.luckperms.LPSpongePlugin;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.sponge.collections.GroupCollection;
|
||||
import me.lucko.luckperms.api.sponge.collections.UserCollection;
|
||||
import me.lucko.luckperms.api.sponge.simple.SimpleCollection;
|
||||
@@ -142,6 +143,17 @@ public class LuckPermsService implements PermissionService {
|
||||
plugin.getContextManager().registerCalculator(new SpongeCalculatorLink(contextCalculator));
|
||||
}
|
||||
|
||||
public Contexts calculateContexts(Set<Context> contexts) {
|
||||
return new Contexts(
|
||||
LuckPermsService.convertContexts(contexts),
|
||||
plugin.getConfiguration().isIncludingGlobalPerms(),
|
||||
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
||||
true,
|
||||
plugin.getConfiguration().isApplyingGlobalGroups(),
|
||||
plugin.getConfiguration().isApplyingGlobalWorldGroups()
|
||||
);
|
||||
}
|
||||
|
||||
public static Map<String, String> convertContexts(Set<Context> contexts) {
|
||||
return contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
|
||||
package me.lucko.luckperms.api.sponge;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.caching.MetaData;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@@ -73,17 +73,6 @@ public class LuckPermsUserSubject implements Subject {
|
||||
transientSubjectData = null;
|
||||
}
|
||||
|
||||
private Contexts calculateContexts(Set<Context> contexts) {
|
||||
return new Contexts(
|
||||
LuckPermsService.convertContexts(contexts),
|
||||
service.getPlugin().getConfiguration().isIncludingGlobalPerms(),
|
||||
service.getPlugin().getConfiguration().isIncludingGlobalWorldPerms(),
|
||||
true,
|
||||
service.getPlugin().getConfiguration().isApplyingGlobalGroups(),
|
||||
service.getPlugin().getConfiguration().isApplyingGlobalWorldGroups()
|
||||
);
|
||||
}
|
||||
|
||||
private boolean hasData() {
|
||||
return user.getUserData() != null;
|
||||
}
|
||||
@@ -118,7 +107,7 @@ public class LuckPermsUserSubject implements Subject {
|
||||
@Override
|
||||
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String permission) {
|
||||
if (hasData()) {
|
||||
return LuckPermsService.convertTristate(user.getUserData().getPermissionData(calculateContexts(contexts)).getPermissionValue(permission));
|
||||
return LuckPermsService.convertTristate(user.getUserData().getPermissionData(service.calculateContexts(contexts)).getPermissionValue(permission));
|
||||
}
|
||||
|
||||
return Tristate.UNDEFINED;
|
||||
@@ -131,10 +120,10 @@ public class LuckPermsUserSubject implements Subject {
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
List<Subject> subjects = new ArrayList<>();
|
||||
ImmutableList.Builder<Subject> subjects = ImmutableList.builder();
|
||||
|
||||
if (hasData()) {
|
||||
for (String perm : user.getUserData().getPermissionData(calculateContexts(contexts)).getImmutableBacking().keySet()) {
|
||||
for (String perm : user.getUserData().getPermissionData(service.calculateContexts(contexts)).getImmutableBacking().keySet()) {
|
||||
if (!perm.startsWith("group.")) {
|
||||
continue;
|
||||
}
|
||||
@@ -149,13 +138,13 @@ public class LuckPermsUserSubject implements Subject {
|
||||
subjects.addAll(service.getUserSubjects().getDefaults().getParents(contexts));
|
||||
subjects.addAll(service.getDefaults().getParents(contexts));
|
||||
|
||||
return subjects;
|
||||
return subjects.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(Set<Context> contexts, String s) {
|
||||
if (hasData()) {
|
||||
MetaData data = user.getUserData().getMetaData(calculateContexts(contexts));
|
||||
MetaData data = user.getUserData().getMetaData(service.calculateContexts(contexts));
|
||||
if (s.equalsIgnoreCase("prefix")) {
|
||||
if (data.getPrefix() != null) {
|
||||
return Optional.of(data.getPrefix());
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
import org.spongepowered.api.service.permission.SubjectData;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -83,7 +84,7 @@ public class GroupCollection implements SubjectCollection {
|
||||
public Map<Subject, Boolean> getAllWithPermission(@NonNull Set<Context> contexts, @NonNull String node) {
|
||||
return manager.getAll().values().stream()
|
||||
.map(u -> LuckPermsGroupSubject.wrapGroup(u, service))
|
||||
.filter(sub -> sub.isPermissionSet(contexts, node))
|
||||
.filter(sub -> sub.getPermissionValue(contexts, node) != Tristate.UNDEFINED)
|
||||
.collect(Collectors.toMap(sub -> sub, sub -> sub.getPermissionValue(contexts, node).asBoolean()));
|
||||
}
|
||||
|
||||
|
||||
+39
-51
@@ -29,15 +29,16 @@ import me.lucko.luckperms.api.sponge.LuckPermsUserSubject;
|
||||
import me.lucko.luckperms.api.sponge.simple.SimpleCollection;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.users.UserIdentifier;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
import org.spongepowered.api.service.permission.SubjectData;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -66,31 +67,6 @@ public class UserCollection implements SubjectCollection {
|
||||
return PermissionService.SUBJECTS_USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a user into this manager
|
||||
* @param uuid the external uuid of the user
|
||||
*/
|
||||
public synchronized void load(UUID uuid) {
|
||||
UUID internal = service.getPlugin().getUuidCache().getUUID(uuid);
|
||||
if (!manager.isLoaded(UserIdentifier.of(internal, null))) {
|
||||
return; // Not loaded at a higher level
|
||||
}
|
||||
|
||||
if (users.containsKey(internal)) {
|
||||
return; // Already loaded
|
||||
}
|
||||
|
||||
User user = manager.get(internal);
|
||||
LuckPermsUserSubject subject = LuckPermsUserSubject.wrapUser(user, service);
|
||||
subject.calculateActivePermissions(true); // Pre-process some of their permissions
|
||||
|
||||
users.put(internal, subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload a user from this manager
|
||||
* @param uuid the internal uuid of the user
|
||||
*/
|
||||
public void unload(UUID uuid) {
|
||||
if (users.containsKey(uuid)) {
|
||||
users.remove(uuid).deprovision();
|
||||
@@ -99,19 +75,9 @@ public class UserCollection implements SubjectCollection {
|
||||
|
||||
@Override
|
||||
public Subject get(@NonNull String id) {
|
||||
final UUID uuid = Util.parseUuid(id);
|
||||
if (uuid != null) {
|
||||
UUID internal = service.getPlugin().getUuidCache().getUUID(uuid);
|
||||
if (users.containsKey(internal)) {
|
||||
return users.get(internal);
|
||||
}
|
||||
|
||||
} else {
|
||||
for (LuckPermsUserSubject subject : users.values()) {
|
||||
if (subject.getUser().getName().equals(id)) {
|
||||
return subject;
|
||||
}
|
||||
}
|
||||
Optional<Subject> s = getIfLoaded(id);
|
||||
if (s.isPresent()) {
|
||||
return s.get();
|
||||
}
|
||||
|
||||
if (service.getPlugin().getConfiguration().isDebugPermissionChecks()) {
|
||||
@@ -122,24 +88,46 @@ public class UserCollection implements SubjectCollection {
|
||||
return fallback.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegistered(@NonNull String id) {
|
||||
final UUID uuid = Util.parseUuid(id);
|
||||
if (uuid != null) {
|
||||
UUID internal = service.getPlugin().getUuidCache().getUUID(uuid);
|
||||
if (users.containsKey(internal)) {
|
||||
return true;
|
||||
}
|
||||
private Optional<Subject> getIfLoaded(String id) {
|
||||
UUID uuid = Util.parseUuid(id);
|
||||
|
||||
} else {
|
||||
find:
|
||||
if (uuid == null) {
|
||||
for (LuckPermsUserSubject subject : users.values()) {
|
||||
if (subject.getUser().getName().equals(id)) {
|
||||
return true;
|
||||
return Optional.of(subject);
|
||||
}
|
||||
}
|
||||
|
||||
for (User user : manager.getAll().values()) {
|
||||
if (user.getName().equalsIgnoreCase(id)) {
|
||||
uuid = user.getUuid();
|
||||
break find;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
if (uuid != null) {
|
||||
UUID internal = service.getPlugin().getUuidCache().getUUID(uuid);
|
||||
Subject s = users.computeIfAbsent(internal, u -> {
|
||||
User user = manager.get(u);
|
||||
if (user == null) return null;
|
||||
|
||||
return LuckPermsUserSubject.wrapUser(user, service);
|
||||
});
|
||||
|
||||
|
||||
if (s != null) {
|
||||
return Optional.of(s);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegistered(@NonNull String id) {
|
||||
return getIfLoaded(id).isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,7 +143,7 @@ public class UserCollection implements SubjectCollection {
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(@NonNull Set<Context> contexts, @NonNull String node) {
|
||||
return users.values().stream()
|
||||
.filter(sub -> sub.isPermissionSet(contexts, node))
|
||||
.filter(sub -> sub.getPermissionValue(contexts, node) != Tristate.UNDEFINED)
|
||||
.collect(Collectors.toMap(sub -> sub, sub -> sub.getPermissionValue(contexts, node).asBoolean()));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
package me.lucko.luckperms.api.sponge.simple;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
@@ -29,6 +30,7 @@ import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.*;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -69,41 +71,66 @@ public class SimpleSubject implements Subject {
|
||||
@Override
|
||||
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String node) {
|
||||
Tristate res = subjectData.getNodeTree(contexts).get(node);
|
||||
if (res == Tristate.UNDEFINED) {
|
||||
for (Subject parent : getParents(contexts)) {
|
||||
Tristate tempRes = parent.getPermissionValue(contexts, node);
|
||||
if (tempRes != Tristate.UNDEFINED) {
|
||||
res = tempRes;
|
||||
break;
|
||||
}
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
|
||||
for (Subject parent : getParents(contexts)) {
|
||||
Tristate tempRes = parent.getPermissionValue(contexts, node);
|
||||
if (tempRes != Tristate.UNDEFINED) {
|
||||
return tempRes;
|
||||
}
|
||||
}
|
||||
|
||||
if (getContainingCollection().getIdentifier().equalsIgnoreCase("defaults")) {
|
||||
return Tristate.UNDEFINED;
|
||||
}
|
||||
|
||||
res = service.getGroupSubjects().getDefaults().getPermissionValue(contexts, node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = service.getDefaults().getPermissionValue(contexts, node);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(@NonNull Set<Context> contexts, @NonNull Subject subject) {
|
||||
return subjectData.getParents(contexts).contains(subject);
|
||||
return subjectData.getParents(contexts).contains(subject) ||
|
||||
getContainingCollection().getDefaults().getParents(contexts).contains(subject) ||
|
||||
service.getDefaults().getParents(contexts).contains(subject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(@NonNull Set<Context> contexts) {
|
||||
return subjectData.getParents(contexts);
|
||||
List<Subject> s = new ArrayList<>();
|
||||
s.addAll(subjectData.getParents(contexts));
|
||||
s.addAll(getContainingCollection().getDefaults().getParents(contexts));
|
||||
s.addAll(service.getDefaults().getParents(contexts));
|
||||
return ImmutableList.copyOf(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(Set<Context> set, String key) {
|
||||
Optional<String> res = Optional.ofNullable(subjectData.getOptions(getActiveContexts()).get(key));
|
||||
if (!res.isPresent()) {
|
||||
for (Subject parent : getParents(getActiveContexts())) {
|
||||
Optional<String> tempRes = parent.getOption(getActiveContexts(), key);
|
||||
if (tempRes.isPresent()) {
|
||||
res = tempRes;
|
||||
break;
|
||||
}
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
for (Subject parent : getParents(getActiveContexts())) {
|
||||
Optional<String> tempRes = parent.getOption(getActiveContexts(), key);
|
||||
if (tempRes.isPresent()) {
|
||||
return tempRes;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
res = getContainingCollection().getDefaults().getOption(set, key);
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return service.getDefaults().getOption(set, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+51
-21
@@ -22,6 +22,7 @@
|
||||
|
||||
package me.lucko.luckperms.api.sponge.simple.persisted;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
||||
@@ -88,24 +89,42 @@ public class SimplePersistedSubject implements Subject {
|
||||
@Override
|
||||
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String node) {
|
||||
Tristate res = subjectData.getNodeTree(contexts).get(node);
|
||||
if (res == Tristate.UNDEFINED) {
|
||||
transientSubjectData.getNodeTree(contexts).get(node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
if (res == Tristate.UNDEFINED) {
|
||||
for (Subject parent : getParents(contexts)) {
|
||||
Tristate tempRes = parent.getPermissionValue(contexts, node);
|
||||
if (tempRes != Tristate.UNDEFINED) {
|
||||
res = tempRes;
|
||||
break;
|
||||
}
|
||||
|
||||
res = transientSubjectData.getNodeTree(contexts).get(node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
|
||||
for (Subject parent : getParents(contexts)) {
|
||||
Tristate tempRes = parent.getPermissionValue(contexts, node);
|
||||
if (tempRes != Tristate.UNDEFINED) {
|
||||
return tempRes;
|
||||
}
|
||||
}
|
||||
|
||||
if (getContainingCollection().getIdentifier().equalsIgnoreCase("defaults")) {
|
||||
return Tristate.UNDEFINED;
|
||||
}
|
||||
|
||||
res = service.getGroupSubjects().getDefaults().getPermissionValue(contexts, node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = service.getDefaults().getPermissionValue(contexts, node);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(@NonNull Set<Context> contexts, @NonNull Subject subject) {
|
||||
return subjectData.getParents(contexts).contains(subject) || transientSubjectData.getParents(contexts).contains(subject);
|
||||
return subjectData.getParents(contexts).contains(subject) ||
|
||||
transientSubjectData.getParents(contexts).contains(subject) ||
|
||||
getContainingCollection().getDefaults().getParents(contexts).contains(subject) ||
|
||||
service.getDefaults().getParents(contexts).contains(subject);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,25 +132,36 @@ public class SimplePersistedSubject implements Subject {
|
||||
List<Subject> s = new ArrayList<>();
|
||||
s.addAll(subjectData.getParents(contexts));
|
||||
s.addAll(transientSubjectData.getParents(contexts));
|
||||
return s;
|
||||
s.addAll(getContainingCollection().getDefaults().getParents(contexts));
|
||||
s.addAll(service.getDefaults().getParents(contexts));
|
||||
return ImmutableList.copyOf(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(Set<Context> set, String key) {
|
||||
Optional<String> res = Optional.ofNullable(subjectData.getOptions(getActiveContexts()).get(key));
|
||||
if (!res.isPresent()) {
|
||||
res = Optional.ofNullable(transientSubjectData.getOptions(getActiveContexts()).get(key));
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
if (!res.isPresent()) {
|
||||
for (Subject parent : getParents(getActiveContexts())) {
|
||||
Optional<String> tempRes = parent.getOption(getActiveContexts(), key);
|
||||
if (tempRes.isPresent()) {
|
||||
res = tempRes;
|
||||
break;
|
||||
}
|
||||
|
||||
res = Optional.ofNullable(transientSubjectData.getOptions(getActiveContexts()).get(key));
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
for (Subject parent : getParents(getActiveContexts())) {
|
||||
Optional<String> tempRes = parent.getOption(getActiveContexts(), key);
|
||||
if (tempRes.isPresent()) {
|
||||
return tempRes;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
res = getContainingCollection().getDefaults().getOption(set, key);
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return service.getDefaults().getOption(set, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user