More cleanup
This commit is contained in:
@@ -123,11 +123,13 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
private CalculatorFactory calculatorFactory;
|
||||
private BufferedRequest<Void> updateTaskBuffer;
|
||||
private DebugHandler debugHandler;
|
||||
private SpongeSenderFactory senderFactory;
|
||||
|
||||
@Listener
|
||||
public void onEnable(GamePreInitializationEvent event) {
|
||||
log = LogFactory.wrap(logger);
|
||||
debugHandler = new DebugHandler();
|
||||
senderFactory = new SpongeSenderFactory(this);
|
||||
timings = new LPTimings(this);
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
@@ -304,16 +306,15 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sender> getNotifyListeners() {
|
||||
public List<Sender> getSenders() {
|
||||
return game.getServer().getOnlinePlayers().stream()
|
||||
.map(s -> SpongeSenderFactory.get(this).wrap(s))
|
||||
.filter(Permission.LOG_NOTIFY::isAuthorized)
|
||||
.map(s -> getSenderFactory().wrap(s))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sender getConsoleSender() {
|
||||
return SpongeSenderFactory.get(this).wrap(game.getServer().getConsole());
|
||||
return getSenderFactory().wrap(game.getServer().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,7 +54,7 @@ class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
public CommandResult process(CommandSource source, String s) throws CommandException {
|
||||
try (Timing ignored = plugin.getTimings().time(LPTiming.ON_COMMAND)) {
|
||||
onCommand(
|
||||
SpongeSenderFactory.get(getPlugin()).wrap(source),
|
||||
plugin.getSenderFactory().wrap(source),
|
||||
"perms",
|
||||
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(s)),
|
||||
Callback.empty()
|
||||
@@ -66,13 +66,13 @@ class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String s, @Nullable Location<World> location) throws CommandException {
|
||||
try (Timing ignored = plugin.getTimings().time(LPTiming.COMMAND_TAB_COMPLETE)) {
|
||||
return onTabComplete(SpongeSenderFactory.get(getPlugin()).wrap(source), Splitter.on(' ').splitToList(s));
|
||||
return onTabComplete(plugin.getSenderFactory().wrap(source), Splitter.on(' ').splitToList(s));
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getSuggestions(CommandSource source, String s) throws CommandException {
|
||||
try (Timing ignored = plugin.getTimings().time(LPTiming.COMMAND_TAB_COMPLETE)) {
|
||||
return onTabComplete(SpongeSenderFactory.get(getPlugin()).wrap(source), Splitter.on(' ').splitToList(s));
|
||||
return onTabComplete(plugin.getSenderFactory().wrap(source), Splitter.on(' ').splitToList(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,19 +32,10 @@ import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeSenderFactory extends SenderFactory<CommandSource> {
|
||||
private static SpongeSenderFactory instance = null;
|
||||
|
||||
private SpongeSenderFactory(LuckPermsPlugin plugin) {
|
||||
public SpongeSenderFactory(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
public static synchronized SpongeSenderFactory get(LuckPermsPlugin plugin) {
|
||||
if (instance == null) {
|
||||
instance = new SpongeSenderFactory(plugin);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(CommandSource source) {
|
||||
if (source instanceof Player) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@@ -97,7 +98,7 @@ public abstract class LuckPermsSubject implements Subject {
|
||||
@Override
|
||||
@Deprecated
|
||||
public Set<Context> getActiveContexts() {
|
||||
return LuckPermsService.convertContexts(getActiveContextSet());
|
||||
return ImmutableSet.copyOf(LuckPermsService.convertContexts(getActiveContextSet()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.core.NodeBuilder;
|
||||
@@ -97,12 +98,12 @@ public class LuckPermsSubjectData implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getPermissions(Set<Context> contexts) {
|
||||
public Map<String, Boolean> getPermissions(@NonNull Set<Context> contexts) {
|
||||
return getAllPermissions().getOrDefault(contexts, ImmutableMap.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPermission(Set<Context> contexts, String permission, Tristate tristate) {
|
||||
public boolean setPermission(@NonNull Set<Context> contexts, @NonNull String permission, @NonNull Tristate tristate) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_SET_PERMISSION)) {
|
||||
if (tristate == Tristate.UNDEFINED) {
|
||||
// Unset
|
||||
@@ -158,7 +159,7 @@ public class LuckPermsSubjectData implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearPermissions(Set<Context> c) {
|
||||
public boolean clearPermissions(@NonNull Set<Context> c) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PERMISSIONS)) {
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
||||
@@ -232,12 +233,12 @@ public class LuckPermsSubjectData implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
public List<Subject> getParents(@NonNull Set<Context> contexts) {
|
||||
return getAllParents().getOrDefault(contexts, ImmutableList.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addParent(Set<Context> set, Subject subject) {
|
||||
public boolean addParent(@NonNull Set<Context> set, @NonNull Subject subject) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_ADD_PARENT)) {
|
||||
if (subject instanceof LuckPermsGroupSubject) {
|
||||
LuckPermsGroupSubject permsSubject = ((LuckPermsGroupSubject) subject);
|
||||
@@ -263,7 +264,7 @@ public class LuckPermsSubjectData implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeParent(Set<Context> set, Subject subject) {
|
||||
public boolean removeParent(@NonNull Set<Context> set, @NonNull Subject subject) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_REMOVE_PARENT)) {
|
||||
if (subject instanceof LuckPermsGroupSubject) {
|
||||
LuckPermsGroupSubject permsSubject = ((LuckPermsGroupSubject) subject);
|
||||
@@ -315,7 +316,7 @@ public class LuckPermsSubjectData implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearParents(Set<Context> set) {
|
||||
public boolean clearParents(@NonNull Set<Context> set) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_PARENTS)) {
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
||||
@@ -421,12 +422,12 @@ public class LuckPermsSubjectData implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getOptions(Set<Context> set) {
|
||||
public Map<String, String> getOptions(@NonNull Set<Context> set) {
|
||||
return getAllOptions().getOrDefault(set, ImmutableMap.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOption(Set<Context> set, String key, String value) {
|
||||
public boolean setOption(@NonNull Set<Context> set, @NonNull String key, @NonNull String value) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_SET_OPTION)) {
|
||||
ContextSet context = LuckPermsService.convertContexts(set);
|
||||
|
||||
@@ -452,7 +453,7 @@ public class LuckPermsSubjectData implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOptions(Set<Context> set) {
|
||||
public boolean clearOptions(@NonNull Set<Context> set) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_CLEAR_OPTIONS)) {
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node n : enduring ? holder.getNodes() : holder.getTransientNodes()) {
|
||||
|
||||
+1
-2
@@ -40,7 +40,6 @@ import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupCollection implements SubjectCollection {
|
||||
private final LuckPermsService service;
|
||||
@@ -92,7 +91,7 @@ public class GroupCollection implements SubjectCollection {
|
||||
return manager.getAll().values().stream()
|
||||
.map(u -> LuckPermsGroupSubject.wrapGroup(u, service))
|
||||
.filter(sub -> sub.getPermissionValue(cs, node) != Tristate.UNDEFINED)
|
||||
.collect(Collectors.toMap(sub -> sub, sub -> sub.getPermissionValue(cs, node).asBoolean()));
|
||||
.collect(ImmutableCollectors.toImmutableMap(sub -> sub, sub -> sub.getPermissionValue(cs, node).asBoolean()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,13 +62,6 @@ public class UserCollection implements SubjectCollection {
|
||||
private final SimpleCollection fallback;
|
||||
|
||||
private final LoadingCache<UUID, LuckPermsUserSubject> users = CacheBuilder.newBuilder()
|
||||
/*
|
||||
.removalListener((RemovalListener<UUID, LuckPermsUserSubject>) r -> {
|
||||
if (r.getValue() != null) {
|
||||
r.getValue().deprovision();
|
||||
}
|
||||
})
|
||||
*/
|
||||
.build(new CacheLoader<UUID, LuckPermsUserSubject>() {
|
||||
@Override
|
||||
public LuckPermsUserSubject load(UUID uuid) throws Exception {
|
||||
|
||||
+2
-2
@@ -26,6 +26,7 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -36,7 +37,6 @@ import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class PersistedCollection implements SubjectCollection {
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(@NonNull String id) {
|
||||
return getAllWithPermission(Collections.emptySet(), id);
|
||||
return getAllWithPermission(ImmutableSet.of(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||
@@ -196,7 +197,7 @@ public class PersistedSubject implements Subject {
|
||||
@Override
|
||||
public Set<Context> getActiveContexts() {
|
||||
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.PERSISTED_SUBJECT_GET_ACTIVE_CONTEXTS)) {
|
||||
return LuckPermsService.convertContexts(service.getPlugin().getContextManager().getApplicableContext(this));
|
||||
return ImmutableSet.copyOf(LuckPermsService.convertContexts(service.getPlugin().getContextManager().getApplicableContext(this)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,20 +25,20 @@ package me.lucko.luckperms.sponge.service.simple;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Super simple SubjectCollection implementation
|
||||
@@ -70,17 +70,17 @@ public class SimpleCollection implements SubjectCollection {
|
||||
|
||||
@Override
|
||||
public Iterable<Subject> getAllSubjects() {
|
||||
return subjects.asMap().values().stream().map(s -> (Subject) s).collect(Collectors.toList());
|
||||
return subjects.asMap().values().stream().map(s -> (Subject) s).collect(ImmutableCollectors.toImmutableList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(@NonNull String id) {
|
||||
return getAllWithPermission(Collections.emptySet(), id);
|
||||
return getAllWithPermission(ImmutableSet.of(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(@NonNull Set<Context> contexts, @NonNull String node) {
|
||||
Map<Subject, Boolean> m = new HashMap<>();
|
||||
ImmutableMap.Builder<Subject, Boolean> m = ImmutableMap.builder();
|
||||
for (Subject subject : subjects.asMap().values()) {
|
||||
Tristate ts = subject.getPermissionValue(contexts, node);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
@@ -88,7 +88,7 @@ public class SimpleCollection implements SubjectCollection {
|
||||
}
|
||||
|
||||
}
|
||||
return m;
|
||||
return m.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ package me.lucko.luckperms.sponge.service.simple;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
@@ -162,7 +163,7 @@ public class SimpleSubject implements Subject {
|
||||
@Override
|
||||
public Set<Context> getActiveContexts() {
|
||||
try (Timing ignored = service.getPlugin().getTimings().time(LPTiming.SIMPLE_SUBJECT_GET_ACTIVE_CONTEXTS)) {
|
||||
return LuckPermsService.convertContexts(service.getPlugin().getContextManager().getApplicableContext(this));
|
||||
return ImmutableSet.copyOf(LuckPermsService.convertContexts(service.getPlugin().getContextManager().getApplicableContext(this)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user