More cleanup

This commit is contained in:
Luck 2016-11-08 20:46:29 +00:00
parent 90f8dbe243
commit 1c534d7475
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
31 changed files with 223 additions and 169 deletions

View File

@ -25,7 +25,6 @@ package me.lucko.luckperms.bukkit;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.CommandManager;
import me.lucko.luckperms.common.commands.Util;
import me.lucko.luckperms.common.constants.Patterns;
@ -38,14 +37,17 @@ import java.util.Arrays;
import java.util.List;
class BukkitCommand extends CommandManager implements CommandExecutor, TabExecutor {
BukkitCommand(LuckPermsPlugin plugin) {
private final LPBukkitPlugin plugin;
BukkitCommand(LPBukkitPlugin plugin) {
super(plugin);
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
onCommand(
BukkitSenderFactory.get(getPlugin()).wrap(sender),
plugin.getSenderFactory().wrap(sender),
label,
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))),
Callback.empty()
@ -53,9 +55,8 @@ class BukkitCommand extends CommandManager implements CommandExecutor, TabExecut
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return onTabComplete(BukkitSenderFactory.get(getPlugin()).wrap(sender), Arrays.asList(args));
return onTabComplete(plugin.getSenderFactory().wrap(sender), Arrays.asList(args));
}
}

View File

@ -31,19 +31,10 @@ import org.bukkit.entity.Player;
import java.util.UUID;
public class BukkitSenderFactory extends SenderFactory<CommandSender> {
private static BukkitSenderFactory instance = null;
private BukkitSenderFactory(LuckPermsPlugin plugin) {
public BukkitSenderFactory(LuckPermsPlugin plugin) {
super(plugin);
}
public static synchronized BukkitSenderFactory get(LuckPermsPlugin plugin) {
if (instance == null) {
instance = new BukkitSenderFactory(plugin);
}
return instance;
}
@Override
protected String getName(CommandSender sender) {
if (sender instanceof Player) {

View File

@ -97,6 +97,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
private BufferedRequest<Void> updateTaskBuffer;
private boolean started = false;
private DebugHandler debugHandler;
private BukkitSenderFactory senderFactory;
private ExecutorService executorService;
private boolean schedulerAvailable = false;
@ -108,6 +109,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
log = LogFactory.wrap(getLogger());
debugHandler = new DebugHandler();
senderFactory = new BukkitSenderFactory(this);
getLog().info("Loading configuration...");
configuration = new BukkitConfig(this);
@ -319,16 +321,15 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
}
@Override
public List<Sender> getNotifyListeners() {
public List<Sender> getSenders() {
return getServer().getOnlinePlayers().stream()
.map(p -> BukkitSenderFactory.get(this).wrap(p))
.filter(Permission.LOG_NOTIFY::isAuthorized)
.map(p -> getSenderFactory().wrap(p))
.collect(Collectors.toList());
}
@Override
public Sender getConsoleSender() {
return BukkitSenderFactory.get(this).wrap(getServer().getConsoleSender());
return getSenderFactory().wrap(getServer().getConsoleSender());
}
@Override

View File

@ -184,7 +184,7 @@ public class LPPermissible extends PermissibleBase {
}
PermissionAttachment result = addAttachment(plugin);
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveAttachmentRunnable(result), ticks) == -1) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> result.remove(), ticks) == -1) {
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
result.remove();
return null;
@ -254,16 +254,4 @@ public class LPPermissible extends PermissibleBase {
}
}
}
private class RemoveAttachmentRunnable implements Runnable {
private PermissionAttachment attachment;
private RemoveAttachmentRunnable(PermissionAttachment attachment) {
this.attachment = attachment;
}
public void run() {
attachment.remove();
}
}
}

View File

@ -35,17 +35,19 @@ import net.md_5.bungee.api.plugin.TabExecutor;
import java.util.Arrays;
class BungeeCommand extends Command implements TabExecutor {
private final LPBungeePlugin plugin;
private final CommandManager manager;
BungeeCommand(CommandManager manager) {
BungeeCommand(LPBungeePlugin plugin, CommandManager manager) {
super("luckpermsbungee", null, "bperms", "lpb", "bpermissions", "bp", "bperm");
this.plugin = plugin;
this.manager = manager;
}
@Override
public void execute(CommandSender sender, String[] args) {
manager.onCommand(
BungeeSenderFactory.get(manager.getPlugin()).wrap(sender),
plugin.getSenderFactory().wrap(sender),
"bperms",
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))),
Callback.empty()
@ -54,6 +56,6 @@ class BungeeCommand extends Command implements TabExecutor {
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
return manager.onTabComplete(BungeeSenderFactory.get(manager.getPlugin()).wrap(sender), Arrays.asList(args));
return manager.onTabComplete(plugin.getSenderFactory().wrap(sender), Arrays.asList(args));
}
}

View File

@ -32,19 +32,10 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.UUID;
public class BungeeSenderFactory extends SenderFactory<CommandSender> {
private static BungeeSenderFactory instance = null;
private BungeeSenderFactory(LuckPermsPlugin plugin) {
public BungeeSenderFactory(LuckPermsPlugin plugin) {
super(plugin);
}
public static synchronized BungeeSenderFactory get(LuckPermsPlugin plugin) {
if (instance == null) {
instance = new BungeeSenderFactory(plugin);
}
return instance;
}
@Override
protected String getName(CommandSender sender) {
if (sender instanceof ProxiedPlayer) {

View File

@ -36,7 +36,6 @@ import me.lucko.luckperms.common.commands.CommandManager;
import me.lucko.luckperms.common.commands.ConsecutiveExecutor;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.config.LPConfiguration;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.contexts.ContextManager;
import me.lucko.luckperms.common.contexts.ServerCalculator;
import me.lucko.luckperms.common.core.UuidCache;
@ -85,11 +84,13 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
private CalculatorFactory calculatorFactory;
private BufferedRequest<Void> updateTaskBuffer;
private DebugHandler debugHandler;
private BungeeSenderFactory senderFactory;
@Override
public void onEnable() {
log = LogFactory.wrap(getLogger());
debugHandler = new DebugHandler();
senderFactory = new BungeeSenderFactory(this);
getLog().info("Loading configuration...");
configuration = new BungeeConfig(this);
@ -137,7 +138,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
// register commands
getLog().info("Registering commands...");
CommandManager commandManager = new CommandManager(this);
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(commandManager));
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(this, commandManager));
// disable the default Bungee /perms command so it gets handled by the Bukkit plugin
getProxy().getDisabledCommands().add("perms");
@ -229,16 +230,15 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
}
@Override
public List<Sender> getNotifyListeners() {
public List<Sender> getSenders() {
return getProxy().getPlayers().stream()
.map(p -> BungeeSenderFactory.get(this).wrap(p))
.filter(Permission.LOG_NOTIFY::isAuthorized)
.map(p -> getSenderFactory().wrap(p))
.collect(Collectors.toList());
}
@Override
public Sender getConsoleSender() {
return BungeeSenderFactory.get(this).wrap(getProxy().getConsole());
return getSenderFactory().wrap(getProxy().getConsole());
}
@Override

View File

@ -49,46 +49,142 @@ import java.util.Set;
import java.util.UUID;
/**
* Main internal interface for LuckPerms plugins, allowing the luckperms-common module to bind with the plugin instance.
* Main internal interface for LuckPerms plugins, providing the base for abstraction throughout the project.
*
* All plugin platforms implement this interface.
*/
public interface LuckPermsPlugin {
/*
* Access to all of the main internal manager classes
/**
* Gets the user manager instance for the platform
* @return the user manager
*/
UserManager getUserManager();
/**
* Gets the group manager instance for the platform
* @return the group manager
*/
GroupManager getGroupManager();
/**
* Gets the track manager instance for the platform
* @return the track manager
*/
TrackManager getTrackManager();
/**
* Gets the plugin's configuration
* @return the plugin config
*/
LPConfiguration getConfiguration();
/**
* Gets the primary datastore instance. This is likely to be wrapped with extra layers for caching, etc.
* @return the datastore
*/
Datastore getDatastore();
/**
* Gets the redis messaging instance if present. Could return null if redis is not enabled.
* @return the redis messaging service
*/
RedisMessaging getRedisMessaging();
/**
* Gets a wrapped logger instance for the platform.
* @return the plugin's logger
*/
Logger getLog();
/**
* Gets the UUID caching store for the platform
* @return the uuid cache
*/
UuidCache getUuidCache();
/**
* Returns the class implementing the LuckPermsAPI on this platform.
* @return the api
*/
ApiProvider getApiProvider();
/**
* Gets the importer instance
* @return the importer
*/
Importer getImporter();
/**
* Gets the consecutive command executor instance
* @return the consecutive executor
*/
ConsecutiveExecutor getConsecutiveExecutor();
/**
* Gets the instance providing locale translations for the plugin
* @return the locale manager
*/
LocaleManager getLocaleManager();
/**
* Gets the context manager.
* This object handles context accumulation for all players on the platform.
* @return the context manager
*/
ContextManager getContextManager();
/**
* Gets the class responsible for constructing PermissionCalculators on this platform.
* @return the permission calculator factory
*/
CalculatorFactory getCalculatorFactory();
/**
* Gets the verbose debug handler instance.
* @return the debug handler instance
*/
DebugHandler getDebugHandler();
/**
* Execute a runnable asynchronously
* @param r the task to run
*/
void doAsync(Runnable r);
/**
* Execute a runnable synchronously
* @param r the task to run
*/
void doSync(Runnable r);
/**
* Execute a runnable asynchronously on a loop
* @param r the task to run
* @param interval the time between runs in ticks
*/
void doAsyncRepeating(Runnable r, long interval);
/**
* Gets a string of the plugin's version
* @return the version of the plugin
*/
String getVersion();
/**
* Gets the platform type this instance of LuckPerms is running on.
* @return the platform type
*/
PlatformType getType();
/**
* Gets the plugins main directory
* @return the main plugin directory
*/
File getMainDir();
/**
* Gets the plugins main data storage directory
* @return the platforms data folder
*/
File getDataFolder();
@ -129,11 +225,13 @@ public interface LuckPermsPlugin {
boolean isOnline(UUID external);
/**
* Gets a list of online Senders on the platform
* @return a {@link List} of senders online on the platform
*/
List<Sender> getNotifyListeners();
List<Sender> getSenders();
/**
* Gets the console.
* @return the console sender of the instance
*/
Sender getConsoleSender();
@ -147,7 +245,7 @@ public interface LuckPermsPlugin {
/**
* Gets a set of players ignoring logging output
* @return a {@link Set} of uuids
* @return a {@link Set} of {@link UUID}s
*/
Set<UUID> getIgnoringLogs();
@ -166,7 +264,7 @@ public interface LuckPermsPlugin {
Object getService(Class clazz);
/**
* Used as a backup for migration
* Gets the UUID of a player. Used as a backup for migration
* @param playerName the players name
* @return a uuid if found, or null if not
*/
@ -180,27 +278,9 @@ public interface LuckPermsPlugin {
boolean isPluginLoaded(String name);
/**
* Runs an update task
* Gets the update task buffer of the platform, used for scheduling and running update tasks.
* @return the update task buffer instance
*/
BufferedRequest<Void> getUpdateTaskBuffer();
/**
* Execute a runnable asynchronously
* @param r the task to run
*/
void doAsync(Runnable r);
/**
* Execute a runnable synchronously
* @param r the task to run
*/
void doSync(Runnable r);
/**
* Execute a runnable asynchronously on a loop
* @param r the task to run
* @param interval the time between runs in ticks
*/
void doAsyncRepeating(Runnable r, long interval);
}

View File

@ -26,6 +26,7 @@ import me.lucko.luckperms.api.event.events.LogNotifyEvent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.Sender;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.PermissionHolder;
import me.lucko.luckperms.common.groups.Group;
import me.lucko.luckperms.common.tracks.Track;
@ -56,15 +57,17 @@ public class LogEntry extends me.lucko.luckperms.api.LogEntry {
final String msg = super.getFormatted();
List<Sender> senders = plugin.getNotifyListeners();
List<Sender> senders = plugin.getSenders();
senders.add(plugin.getConsoleSender());
if (sender == null) {
senders.stream()
.filter(Permission.LOG_NOTIFY::isAuthorized)
.filter(s -> !plugin.getIgnoringLogs().contains(s.getUuid()))
.forEach(s -> Message.LOG.send(s, msg));
} else {
senders.stream()
.filter(Permission.LOG_NOTIFY::isAuthorized)
.filter(s -> !plugin.getIgnoringLogs().contains(s.getUuid()))
.filter(s -> !s.getUuid().equals(sender.getUuid()))
.forEach(s -> Message.LOG.send(s, msg));

View File

@ -61,6 +61,9 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
@Setter
private String primaryGroup = null;
/**
* The users data cache instance, if present.
*/
@Getter
private UserCache userData = null;

View File

@ -26,6 +26,10 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Basic Future implementation
* @param <R> the return type
*/
public class AbstractFuture<R> implements LPFuture<R> {
private final CountDownLatch latch = new CountDownLatch(1);
private R value;

View File

@ -32,6 +32,9 @@ import me.lucko.luckperms.common.users.User;
import java.util.UUID;
/**
* An abstract listener shared by Bukkit & Sponge.
*/
@AllArgsConstructor
public class AbstractListener {
private final LuckPermsPlugin plugin;

View File

@ -25,6 +25,9 @@ package me.lucko.luckperms.common.utils;
import lombok.experimental.UtilityClass;
import me.lucko.luckperms.common.constants.Patterns;
/**
* Utility for checking arguments for consistency
*/
@UtilityClass
public class ArgumentChecker {

View File

@ -27,19 +27,24 @@ import lombok.*;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.locks.ReentrantLock;
/**
* Holds a buffer of objects to be processed after they've been in the buffer for a given time.
* Thread-safe buffer utility. Holds a buffer of objects to be processed after they've been waiting in the buffer
* for a given time. If the same object is pushed to the buffer again in that time, its wait time is reset.
*
* @param <T> the type of objects in the buffer
* @param <R> the type of result produced by the final process
*/
public abstract class Buffer<T, R> implements Runnable {
private static final long DEFAULT_FLUSH_TIME = 1000; // 1 second
private final ReentrantLock lock = new ReentrantLock();
private final List<BufferedObject<T, R>> buffer = new LinkedList<>();
public LPFuture<R> enqueue(@NonNull T t) {
synchronized (buffer) {
lock.lock();
try {
ListIterator<BufferedObject<T, R>> it = buffer.listIterator();
BufferedObject<T, R> o = null;
@ -62,6 +67,8 @@ public abstract class Buffer<T, R> implements Runnable {
buffer.add(o);
return o.getFuture();
} finally {
lock.unlock();
}
}
@ -70,7 +77,8 @@ public abstract class Buffer<T, R> implements Runnable {
public void flush(long flushTime) {
long time = System.currentTimeMillis();
synchronized (buffer) {
lock.lock();
try {
ListIterator<BufferedObject<T, R>> it = buffer.listIterator(buffer.size());
while (it.hasPrevious()) {
@ -85,6 +93,8 @@ public abstract class Buffer<T, R> implements Runnable {
it.remove();
}
}
} finally {
lock.unlock();
}
}

View File

@ -30,14 +30,20 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Thread-safe request buffer.
*
* Waits for the buffer time to pass before performing the operation. If the task is called again in that time, the
* buffer time is reset.
*
* @param <T> the return type
*/
@RequiredArgsConstructor
public abstract class BufferedRequest<T> {
private final long bufferTimeMillis;
private final Consumer<Runnable> executor;
private WeakReference<Processor<T>> processor = null;
@Getter
private ReentrantLock lock = new ReentrantLock();
public LPFuture<T> request() {
@ -66,7 +72,6 @@ public abstract class BufferedRequest<T> {
protected abstract T perform();
@RequiredArgsConstructor
private static class Processor<R> implements Runnable {
private final long delayMillis;

View File

@ -1,23 +1,7 @@
/*
* 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.
* All credit to Essentials / EssentialsX for this class
* https://github.com/drtshock/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/utils/DateUtil.java
* https://github.com/essentials/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/utils/DateUtil.java
*/
package me.lucko.luckperms.common.utils;
@ -30,9 +14,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* All credit to Essentials / EssentialsX for this class
* https://github.com/drtshock/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/utils/DateUtil.java
* https://github.com/essentials/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/utils/DateUtil.java
* Translates unix timestamps / durations into a readable format
*/
@UtilityClass
public class DateUtil {
@ -52,13 +34,7 @@ public class DateUtil {
*/
public static long parseDateDiff(String time, boolean future) throws IllegalDateException {
Matcher m = TIME_PATTERN.matcher(time);
int years = 0;
int months = 0;
int weeks = 0;
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
int years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0;
boolean found = false;
while (m.find()) {
if (m.group() == null || m.group().isEmpty()) {
@ -137,8 +113,7 @@ public class DateUtil {
int fromYear = fromDate.get(year);
int toYear = toDate.get(year);
if (Math.abs(fromYear - toYear) > MAX_YEARS) {
toDate.set(year, fromYear +
(future ? MAX_YEARS : -MAX_YEARS));
toDate.set(year, fromYear + (future ? MAX_YEARS : -MAX_YEARS));
}
int diff = 0;

View File

@ -36,11 +36,11 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class DebugHandler {
private final Map<Reciever, List<String>> listeners = new ConcurrentHashMap<>();
private final Map<Receiver, List<String>> listeners = new ConcurrentHashMap<>();
public void printOutput(String checked, String node, Tristate value) {
all:
for (Map.Entry<Reciever, List<String>> e : listeners.entrySet()) {
for (Map.Entry<Receiver, List<String>> e : listeners.entrySet()) {
for (String filter : e.getValue()) {
if (node.toLowerCase().startsWith(filter.toLowerCase())) {
continue;
@ -58,17 +58,17 @@ public class DebugHandler {
}
public void register(Sender sender, List<String> filters) {
listeners.put(new Reciever(sender.getUuid(), sender), ImmutableList.copyOf(filters));
listeners.put(new Receiver(sender.getUuid(), sender), ImmutableList.copyOf(filters));
}
public void unregister(UUID uuid) {
listeners.remove(new Reciever(uuid, null));
listeners.remove(new Receiver(uuid, null));
}
@Getter
@EqualsAndHashCode(of = "uuid")
@AllArgsConstructor
private static final class Reciever {
private static final class Receiver {
private final UUID uuid;
private final Sender sender;
}

View File

@ -27,7 +27,7 @@ import lombok.experimental.Delegate;
import me.lucko.luckperms.api.Node;
/**
* Holds a Node and where it was inherited from
* Holds a Node and where it was inherited from. All calls are passed onto the contained Node instance.
*/
@Getter
@ToString

View File

@ -25,6 +25,9 @@ package me.lucko.luckperms.common.utils;
import lombok.experimental.UtilityClass;
import me.lucko.luckperms.api.Logger;
/**
* Utility to help create wrapped log instances
*/
@UtilityClass
public class LogFactory {
public static Logger wrap(org.slf4j.Logger l) {

View File

@ -29,6 +29,9 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* A collection of predicate utilities used mostly in command classes
*/
@SuppressWarnings({"WeakerAccess", "unused"})
@UtilityClass
public class Predicates {

View File

@ -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

View File

@ -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));
}
}

View File

@ -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) {

View File

@ -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()));
}
}

View File

@ -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()) {

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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)));
}
}
}

View File

@ -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

View File

@ -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)));
}
}
}