Remove lombok from the project
This commit is contained in:
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
@@ -129,7 +127,6 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* LuckPerms implementation for the Sponge API.
|
||||
*/
|
||||
@Getter
|
||||
@Plugin(
|
||||
id = "luckperms",
|
||||
name = "LuckPerms",
|
||||
@@ -194,97 +191,97 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
@Listener(order = Order.FIRST)
|
||||
public void onEnable(GamePreInitializationEvent event) {
|
||||
startTime = System.currentTimeMillis();
|
||||
scheduler = new SpongeSchedulerAdapter(this);
|
||||
localeManager = new NoopLocaleManager();
|
||||
senderFactory = new SpongeSenderFactory(this);
|
||||
log = new SenderLogger(this, getConsoleSender());
|
||||
dependencyManager = new DependencyManager(this);
|
||||
this.startTime = System.currentTimeMillis();
|
||||
this.scheduler = new SpongeSchedulerAdapter(this);
|
||||
this.localeManager = new NoopLocaleManager();
|
||||
this.senderFactory = new SpongeSenderFactory(this);
|
||||
this.log = new SenderLogger(this, getConsoleSender());
|
||||
this.dependencyManager = new DependencyManager(this);
|
||||
|
||||
sendStartupBanner(getConsoleSender());
|
||||
verboseHandler = new VerboseHandler(scheduler.async(), getVersion());
|
||||
permissionVault = new PermissionVault(scheduler.async());
|
||||
logDispatcher = new LogDispatcher(this);
|
||||
this.verboseHandler = new VerboseHandler(this.scheduler.async(), getVersion());
|
||||
this.permissionVault = new PermissionVault(this.scheduler.async());
|
||||
this.logDispatcher = new LogDispatcher(this);
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new AbstractConfiguration(this, new SpongeConfigAdapter(this, resolveConfig("luckperms.conf")));
|
||||
configuration.loadAll();
|
||||
this.configuration = new AbstractConfiguration(this, new SpongeConfigAdapter(this, resolveConfig("luckperms.conf")));
|
||||
this.configuration.loadAll();
|
||||
|
||||
StorageFactory storageFactory = new StorageFactory(this);
|
||||
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
||||
dependencyManager.loadStorageDependencies(storageTypes);
|
||||
this.dependencyManager.loadStorageDependencies(storageTypes);
|
||||
|
||||
// register events
|
||||
game.getEventManager().registerListeners(this, new SpongeConnectionListener(this));
|
||||
game.getEventManager().registerListeners(this, new SpongePlatformListener(this));
|
||||
this.game.getEventManager().registerListeners(this, new SpongeConnectionListener(this));
|
||||
this.game.getEventManager().registerListeners(this, new SpongePlatformListener(this));
|
||||
|
||||
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
||||
fileWatcher = new FileWatcher(this);
|
||||
getScheduler().asyncRepeating(fileWatcher, 30L);
|
||||
this.fileWatcher = new FileWatcher(this);
|
||||
getScheduler().asyncRepeating(this.fileWatcher, 30L);
|
||||
}
|
||||
|
||||
// initialise datastore
|
||||
storage = storageFactory.getInstance(StorageType.H2);
|
||||
this.storage = storageFactory.getInstance(StorageType.H2);
|
||||
|
||||
// initialise messaging
|
||||
messagingService = new SpongeMessagingFactory(this).getInstance();
|
||||
this.messagingService = new SpongeMessagingFactory(this).getInstance();
|
||||
|
||||
// setup the update task buffer
|
||||
updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||
this.updateTaskBuffer = new UpdateTaskBuffer(this);
|
||||
|
||||
// load locale
|
||||
localeManager = new SimpleLocaleManager();
|
||||
localeManager.tryLoad(this, new File(getDataDirectory(), "lang.yml"));
|
||||
this.localeManager = new SimpleLocaleManager();
|
||||
this.localeManager.tryLoad(this, new File(getDataDirectory(), "lang.yml"));
|
||||
|
||||
// register commands
|
||||
CommandManager cmdService = game.getCommandManager();
|
||||
commandManager = new SpongeCommandExecutor(this);
|
||||
cmdService.register(this, commandManager, "luckperms", "lp", "perm", "perms", "permission", "permissions");
|
||||
CommandManager cmdService = this.game.getCommandManager();
|
||||
this.commandManager = new SpongeCommandExecutor(this);
|
||||
cmdService.register(this, this.commandManager, "luckperms", "lp", "perm", "perms", "permission", "permissions");
|
||||
|
||||
// load internal managers
|
||||
getLog().info("Loading internal permission managers...");
|
||||
uuidCache = new UuidCache(this);
|
||||
userManager = new SpongeUserManager(this);
|
||||
groupManager = new SpongeGroupManager(this);
|
||||
trackManager = new GenericTrackManager(this);
|
||||
calculatorFactory = new SpongeCalculatorFactory(this);
|
||||
cachedStateManager = new CachedStateManager();
|
||||
this.uuidCache = new UuidCache(this);
|
||||
this.userManager = new SpongeUserManager(this);
|
||||
this.groupManager = new SpongeGroupManager(this);
|
||||
this.trackManager = new GenericTrackManager(this);
|
||||
this.calculatorFactory = new SpongeCalculatorFactory(this);
|
||||
this.cachedStateManager = new CachedStateManager();
|
||||
|
||||
// setup context manager
|
||||
contextManager = new SpongeContextManager(this);
|
||||
contextManager.registerCalculator(new WorldCalculator(this));
|
||||
contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
this.contextManager = new SpongeContextManager(this);
|
||||
this.contextManager.registerCalculator(new WorldCalculator(this));
|
||||
this.contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
|
||||
// register the PermissionService with Sponge
|
||||
getLog().info("Registering PermissionService...");
|
||||
service = new LuckPermsService(this);
|
||||
this.service = new LuckPermsService(this);
|
||||
|
||||
if (game.getPluginManager().getPlugin("permissionsex").isPresent()) {
|
||||
if (this.game.getPluginManager().getPlugin("permissionsex").isPresent()) {
|
||||
getLog().warn("Detected PermissionsEx - assuming it's loaded for migration.");
|
||||
getLog().warn("Delaying LuckPerms PermissionService registration.");
|
||||
lateLoad = true;
|
||||
this.lateLoad = true;
|
||||
} else {
|
||||
game.getServiceManager().setProvider(this, LPPermissionService.class, service);
|
||||
game.getServiceManager().setProvider(this, PermissionService.class, service.sponge());
|
||||
game.getServiceManager().setProvider(this, LuckPermsService.class, service);
|
||||
this.game.getServiceManager().setProvider(this, LPPermissionService.class, this.service);
|
||||
this.game.getServiceManager().setProvider(this, PermissionService.class, this.service.sponge());
|
||||
this.game.getServiceManager().setProvider(this, LuckPermsService.class, this.service);
|
||||
}
|
||||
|
||||
// register with the LP API
|
||||
apiProvider = new LuckPermsApiProvider(this);
|
||||
this.apiProvider = new LuckPermsApiProvider(this);
|
||||
|
||||
// setup event factory
|
||||
eventFactory = new EventFactory(this, apiProvider);
|
||||
this.eventFactory = new EventFactory(this, this.apiProvider);
|
||||
|
||||
ApiRegistrationUtil.registerProvider(apiProvider);
|
||||
game.getServiceManager().setProvider(this, LuckPermsApi.class, apiProvider);
|
||||
ApiRegistrationUtil.registerProvider(this.apiProvider);
|
||||
this.game.getServiceManager().setProvider(this, LuckPermsApi.class, this.apiProvider);
|
||||
|
||||
// schedule update tasks
|
||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||
if (mins > 0) {
|
||||
long ticks = mins * 60 * 20;
|
||||
scheduler.asyncRepeating(() -> updateTaskBuffer.request(), ticks);
|
||||
this.scheduler.asyncRepeating(() -> this.updateTaskBuffer.request(), ticks);
|
||||
}
|
||||
scheduler.asyncLater(() -> updateTaskBuffer.request(), 40L);
|
||||
this.scheduler.asyncLater(() -> this.updateTaskBuffer.request(), 40L);
|
||||
|
||||
// run an update instantly.
|
||||
getLog().info("Performing initial data load...");
|
||||
@@ -295,69 +292,69 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
// register tasks
|
||||
scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||
scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||
scheduler.asyncRepeating(new ServiceCacheHousekeepingTask(service), 2400L);
|
||||
this.scheduler.asyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||
this.scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||
this.scheduler.asyncRepeating(new ServiceCacheHousekeepingTask(this.service), 2400L);
|
||||
|
||||
// register permissions
|
||||
for (CommandPermission perm : CommandPermission.values()) {
|
||||
service.registerPermissionDescription(perm.getPermission(), null, pluginContainer);
|
||||
this.service.registerPermissionDescription(perm.getPermission(), null, this.pluginContainer);
|
||||
}
|
||||
|
||||
getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - startTime) + "ms)");
|
||||
getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - this.startTime) + "ms)");
|
||||
}
|
||||
|
||||
@Listener(order = Order.LATE)
|
||||
public void onLateEnable(GamePreInitializationEvent event) {
|
||||
if (lateLoad) {
|
||||
if (this.lateLoad) {
|
||||
getLog().info("Providing late registration of PermissionService...");
|
||||
game.getServiceManager().setProvider(this, LPPermissionService.class, service);
|
||||
game.getServiceManager().setProvider(this, PermissionService.class, service.sponge());
|
||||
game.getServiceManager().setProvider(this, LuckPermsService.class, service);
|
||||
this.game.getServiceManager().setProvider(this, LPPermissionService.class, this.service);
|
||||
this.game.getServiceManager().setProvider(this, PermissionService.class, this.service.sponge());
|
||||
this.game.getServiceManager().setProvider(this, LuckPermsService.class, this.service);
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onDisable(GameStoppingServerEvent event) {
|
||||
permissionVault.shutdown();
|
||||
verboseHandler.shutdown();
|
||||
this.permissionVault.shutdown();
|
||||
this.verboseHandler.shutdown();
|
||||
|
||||
getLog().info("Closing storage...");
|
||||
storage.shutdown();
|
||||
this.storage.shutdown();
|
||||
|
||||
if (fileWatcher != null) {
|
||||
fileWatcher.close();
|
||||
if (this.fileWatcher != null) {
|
||||
this.fileWatcher.close();
|
||||
}
|
||||
|
||||
if (messagingService != null) {
|
||||
if (this.messagingService != null) {
|
||||
getLog().info("Closing messaging service...");
|
||||
messagingService.close();
|
||||
this.messagingService.close();
|
||||
}
|
||||
|
||||
ApiRegistrationUtil.unregisterProvider();
|
||||
|
||||
getLog().info("Shutting down internal scheduler...");
|
||||
scheduler.shutdown();
|
||||
this.scheduler.shutdown();
|
||||
|
||||
getLog().info("Goodbye!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostUpdate() {
|
||||
for (LPSubjectCollection collection : service.getLoadedCollections().values()) {
|
||||
for (LPSubjectCollection collection : this.service.getLoadedCollections().values()) {
|
||||
if (collection instanceof PersistedCollection) {
|
||||
((PersistedCollection) collection).loadAll();
|
||||
}
|
||||
}
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
}
|
||||
|
||||
private Path resolveConfig(String file) {
|
||||
Path path = configDirectory.resolve(file);
|
||||
Path path = this.configDirectory.resolve(file);
|
||||
|
||||
if (!Files.exists(path)) {
|
||||
try {
|
||||
Files.createDirectories(configDirectory);
|
||||
Files.createDirectories(this.configDirectory);
|
||||
try (InputStream is = getClass().getClassLoader().getResourceAsStream(file)) {
|
||||
Files.copy(is, path);
|
||||
}
|
||||
@@ -371,16 +368,17 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public Optional<ExtendedMessagingService> getMessagingService() {
|
||||
return Optional.ofNullable(messagingService);
|
||||
return Optional.ofNullable(this.messagingService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<FileWatcher> getFileWatcher() {
|
||||
return Optional.ofNullable(fileWatcher);
|
||||
return Optional.ofNullable(this.fileWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataDirectory() {
|
||||
File serverRoot = configDirectory.toFile().getParentFile().getParentFile();
|
||||
File serverRoot = this.configDirectory.toFile().getParentFile().getParentFile();
|
||||
File dataDirectory = new File(serverRoot, "luckperms");
|
||||
dataDirectory.mkdirs();
|
||||
return dataDirectory;
|
||||
@@ -388,7 +386,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public File getConfigDirectory() {
|
||||
return configDirectory.toFile();
|
||||
return this.configDirectory.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -398,20 +396,20 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public Player getPlayer(User user) {
|
||||
if (!game.isServerAvailable()) {
|
||||
if (!this.game.isServerAvailable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return game.getServer().getPlayer(uuidCache.getExternalUUID(user.getUuid())).orElse(null);
|
||||
return this.game.getServer().getPlayer(this.uuidCache.getExternalUUID(user.getUuid())).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UUID> lookupUuid(String username) {
|
||||
if (!game.isServerAvailable()) {
|
||||
if (!this.game.isServerAvailable()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
CompletableFuture<GameProfile> fut = game.getServer().getGameProfileManager().get(username);
|
||||
CompletableFuture<GameProfile> fut = this.game.getServer().getGameProfileManager().get(username);
|
||||
try {
|
||||
return Optional.of(fut.get().getUniqueId());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
@@ -426,7 +424,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
return contextManager.getApplicableContexts(player);
|
||||
return this.contextManager.getApplicableContexts(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -454,47 +452,47 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
public int getPlayerCount() {
|
||||
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().size() : 0;
|
||||
return this.game.isServerAvailable() ? this.game.getServer().getOnlinePlayers().size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getPlayerList() {
|
||||
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getName) : Stream.empty();
|
||||
return this.game.isServerAvailable() ? this.game.getServer().getOnlinePlayers().stream().map(Player::getName) : Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<UUID> getOnlinePlayers() {
|
||||
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId) : Stream.empty();
|
||||
return this.game.isServerAvailable() ? this.game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId) : Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerOnline(UUID external) {
|
||||
return game.isServerAvailable() ? game.getServer().getPlayer(external).map(Player::isOnline).orElse(false) : false;
|
||||
return this.game.isServerAvailable() ? this.game.getServer().getPlayer(external).map(Player::isOnline).orElse(false) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Sender> getOnlineSenders() {
|
||||
if (!game.isServerAvailable()) {
|
||||
if (!this.game.isServerAvailable()) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
return Stream.concat(
|
||||
Stream.of(getConsoleSender()),
|
||||
game.getServer().getOnlinePlayers().stream().map(s -> getSenderFactory().wrap(s))
|
||||
this.game.getServer().getOnlinePlayers().stream().map(s -> getSenderFactory().wrap(s))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sender getConsoleSender() {
|
||||
if (!game.isServerAvailable()) {
|
||||
if (!this.game.isServerAvailable()) {
|
||||
return new DummySender(this, me.lucko.luckperms.common.commands.CommandManager.CONSOLE_UUID, me.lucko.luckperms.common.commands.CommandManager.CONSOLE_NAME) {
|
||||
@Override
|
||||
protected void consumeMessage(String s) {
|
||||
logger.info(s);
|
||||
LPSpongePlugin.this.logger.info(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
return getSenderFactory().wrap(game.getServer().getConsole());
|
||||
return getSenderFactory().wrap(this.game.getServer().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -505,15 +503,148 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
@Override
|
||||
public Map<String, Object> getExtraInfo() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("SubjectCollection count", service.getLoadedCollections().size());
|
||||
map.put("SubjectCollection count", this.service.getLoadedCollections().size());
|
||||
map.put("Subject count",
|
||||
service.getLoadedCollections().values().stream()
|
||||
this.service.getLoadedCollections().values().stream()
|
||||
.map(LPSubjectCollection::getLoadedSubjects)
|
||||
.mapToInt(AbstractCollection::size)
|
||||
.sum()
|
||||
);
|
||||
map.put("PermissionDescription count", service.getDescriptions().size());
|
||||
map.put("PermissionDescription count", this.service.getDescriptions().size());
|
||||
return map;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return this.game;
|
||||
}
|
||||
|
||||
public Scheduler getSpongeScheduler() {
|
||||
return this.spongeScheduler;
|
||||
}
|
||||
|
||||
public SpongeExecutorService getSyncExecutorService() {
|
||||
return this.syncExecutorService;
|
||||
}
|
||||
|
||||
public SpongeExecutorService getAsyncExecutorService() {
|
||||
return this.asyncExecutorService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerAdapter getScheduler() {
|
||||
return this.scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeCommandExecutor getCommandManager() {
|
||||
return this.commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsConfiguration getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeUserManager getUserManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeGroupManager getGroupManager() {
|
||||
return this.groupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackManager getTrackManager() {
|
||||
return this.trackManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage getStorage() {
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UuidCache getUuidCache() {
|
||||
return this.uuidCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsApiProvider getApiProvider() {
|
||||
return this.apiProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventFactory getEventFactory() {
|
||||
return this.eventFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public me.lucko.luckperms.common.logging.Logger getLog() {
|
||||
return this.log;
|
||||
}
|
||||
|
||||
public LuckPermsService getService() {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocaleManager getLocaleManager() {
|
||||
return this.localeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DependencyManager getDependencyManager() {
|
||||
return this.dependencyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedStateManager getCachedStateManager() {
|
||||
return this.cachedStateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextManager<Subject> getContextManager() {
|
||||
return this.contextManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorFactory getCalculatorFactory() {
|
||||
return this.calculatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedRequest<Void> getUpdateTaskBuffer() {
|
||||
return this.updateTaskBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VerboseHandler getVerboseHandler() {
|
||||
return this.verboseHandler;
|
||||
}
|
||||
|
||||
public SpongeSenderFactory getSenderFactory() {
|
||||
return this.senderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionVault getPermissionVault() {
|
||||
return this.permissionVault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogDispatcher getLogDispatcher() {
|
||||
return this.logDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getUniqueConnections() {
|
||||
return this.uniqueConnections;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SpongeCommandExecutor extends CommandManager implements CommandCallable {
|
||||
@@ -56,40 +57,45 @@ public class SpongeCommandExecutor extends CommandManager implements CommandCall
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CommandResult process(CommandSource source, String s) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(source);
|
||||
public CommandResult process(@Nonnull CommandSource source, @Nonnull String s) {
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(source);
|
||||
List<String> arguments = processSelectors(source, CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(s)));
|
||||
|
||||
onCommand(lpSender, "lp", arguments);
|
||||
return CommandResult.success();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String s, @Nullable Location<World> location) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(source);
|
||||
public List<String> getSuggestions(@Nonnull CommandSource source, @Nonnull String s, @Nullable Location<World> location) {
|
||||
Sender lpSender = this.plugin.getSenderFactory().wrap(source);
|
||||
List<String> arguments = processSelectors(source, CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(s)));
|
||||
|
||||
return onTabComplete(lpSender, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandSource source) {
|
||||
public boolean testPermission(@Nonnull CommandSource source) {
|
||||
return true; // we run permission checks internally
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<Text> getShortDescription(CommandSource source) {
|
||||
public Optional<Text> getShortDescription(@Nonnull CommandSource source) {
|
||||
return Optional.of(Text.of("Manage permissions"));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<Text> getHelp(CommandSource source) {
|
||||
public Optional<Text> getHelp(@Nonnull CommandSource source) {
|
||||
return Optional.of(Text.of("Run /luckperms to view usage."));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Text getUsage(CommandSource source) {
|
||||
public Text getUsage(@Nonnull CommandSource source) {
|
||||
return Text.of("/luckperms");
|
||||
}
|
||||
|
||||
|
||||
@@ -57,10 +57,10 @@ public class SpongeConfigAdapter extends AbstractConfigurationAdapter implements
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(path).build();
|
||||
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(this.path).build();
|
||||
|
||||
try {
|
||||
root = loader.load();
|
||||
this.root = loader.load();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class SpongeConfigAdapter extends AbstractConfigurationAdapter implements
|
||||
|
||||
private ConfigurationNode resolvePath(String path) {
|
||||
Iterable<String> paths = Splitter.on('.').split(path);
|
||||
ConfigurationNode node = root;
|
||||
ConfigurationNode node = this.root;
|
||||
|
||||
if (node == null) {
|
||||
throw new RuntimeException("Config is not loaded.");
|
||||
|
||||
@@ -43,48 +43,48 @@ public class SpongeSchedulerAdapter implements SchedulerAdapter {
|
||||
|
||||
@Override
|
||||
public Executor async() {
|
||||
return plugin.getAsyncExecutorService();
|
||||
return this.plugin.getAsyncExecutorService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor sync() {
|
||||
return plugin.getSyncExecutorService();
|
||||
return this.plugin.getSyncExecutorService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAsync(Runnable runnable) {
|
||||
plugin.getSpongeScheduler().createTaskBuilder().async().execute(runnable).submit(plugin);
|
||||
this.plugin.getSpongeScheduler().createTaskBuilder().async().execute(runnable).submit(this.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doSync(Runnable runnable) {
|
||||
plugin.getSpongeScheduler().createTaskBuilder().execute(runnable).submit(plugin);
|
||||
this.plugin.getSpongeScheduler().createTaskBuilder().execute(runnable).submit(this.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void asyncRepeating(Runnable runnable, long intervalTicks) {
|
||||
Task task = plugin.getSpongeScheduler().createTaskBuilder().async().intervalTicks(intervalTicks).delayTicks(intervalTicks).execute(runnable).submit(plugin);
|
||||
tasks.add(task);
|
||||
Task task = this.plugin.getSpongeScheduler().createTaskBuilder().async().intervalTicks(intervalTicks).delayTicks(intervalTicks).execute(runnable).submit(this.plugin);
|
||||
this.tasks.add(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncRepeating(Runnable runnable, long intervalTicks) {
|
||||
Task task = plugin.getSpongeScheduler().createTaskBuilder().intervalTicks(intervalTicks).delayTicks(intervalTicks).execute(runnable).submit(plugin);
|
||||
tasks.add(task);
|
||||
Task task = this.plugin.getSpongeScheduler().createTaskBuilder().intervalTicks(intervalTicks).delayTicks(intervalTicks).execute(runnable).submit(this.plugin);
|
||||
this.tasks.add(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void asyncLater(Runnable runnable, long delayTicks) {
|
||||
plugin.getSpongeScheduler().createTaskBuilder().async().delayTicks(delayTicks).execute(runnable).submit(plugin);
|
||||
this.plugin.getSpongeScheduler().createTaskBuilder().async().delayTicks(delayTicks).execute(runnable).submit(this.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncLater(Runnable runnable, long delayTicks) {
|
||||
plugin.getSpongeScheduler().createTaskBuilder().delayTicks(delayTicks).execute(runnable).submit(plugin);
|
||||
this.plugin.getSpongeScheduler().createTaskBuilder().delayTicks(delayTicks).execute(runnable).submit(this.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
tasks.forEach(Task::cancel);
|
||||
this.tasks.forEach(Task::cancel);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-14
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.calculators;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
@@ -46,47 +44,50 @@ import me.lucko.luckperms.sponge.processors.UserDefaultsProcessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class SpongeCalculatorFactory extends AbstractCalculatorFactory {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
public SpongeCalculatorFactory(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionCalculator build(Contexts contexts, PermissionCalculatorMetadata metadata) {
|
||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||
|
||||
processors.add(new MapProcessor());
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_IMPLICIT_WILDCARDS)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_IMPLICIT_WILDCARDS)) {
|
||||
processors.add(new SpongeWildcardProcessor());
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
processors.add(new RegexProcessor());
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
processors.add(new WildcardProcessor());
|
||||
}
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_DEFAULT_SUBJECTS)) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_DEFAULT_SUBJECTS)) {
|
||||
if (metadata.getHolderType() == HolderType.USER) {
|
||||
processors.add(new UserDefaultsProcessor(plugin.getService(), contexts.getContexts().makeImmutable()));
|
||||
processors.add(new UserDefaultsProcessor(this.plugin.getService(), contexts.getContexts().makeImmutable()));
|
||||
} else if (metadata.getHolderType() == HolderType.GROUP) {
|
||||
processors.add(new GroupDefaultsProcessor(plugin.getService(), contexts.getContexts().makeImmutable()));
|
||||
processors.add(new GroupDefaultsProcessor(this.plugin.getService(), contexts.getContexts().makeImmutable()));
|
||||
}
|
||||
}
|
||||
|
||||
return registerCalculator(new PermissionCalculator(plugin, metadata, processors.build()));
|
||||
return registerCalculator(new PermissionCalculator(this.plugin, metadata, processors.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getActiveProcessors() {
|
||||
ImmutableList.Builder<String> ret = ImmutableList.builder();
|
||||
ret.add("Map");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_IMPLICIT_WILDCARDS)) ret.add("SpongeWildcard");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcard");
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_DEFAULT_SUBJECTS)) ret.add("Defaults");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_IMPLICIT_WILDCARDS)) ret.add("SpongeWildcard");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ret.add("Regex");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) ret.add("Wildcard");
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_DEFAULT_SUBJECTS)) ret.add("Defaults");
|
||||
return ret.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -47,7 +46,7 @@ public class OptionClear extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
||||
if (contextSet.isEmpty()) {
|
||||
subjectData.clearOptions();
|
||||
|
||||
@@ -28,7 +28,6 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -50,7 +49,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
||||
if (contextSet.isEmpty()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aShowing options matching contexts &bANY&a.");
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -47,7 +46,7 @@ public class OptionSet extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
String key = args.get(0);
|
||||
String value = args.get(1);
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -47,7 +46,7 @@ public class OptionUnset extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
String key = args.get(0);
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(1, args);
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -52,7 +51,7 @@ public class ParentAdd extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
String collection = args.get(0);
|
||||
String name = args.get(1);
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -47,7 +46,7 @@ public class ParentClear extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
||||
if (contextSet.isEmpty()) {
|
||||
subjectData.clearParents();
|
||||
|
||||
@@ -28,7 +28,6 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -51,7 +50,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
||||
if (contextSet.isEmpty()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a.");
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -52,7 +51,7 @@ public class ParentRemove extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
String collection = args.get(0);
|
||||
String name = args.get(1);
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -47,7 +46,7 @@ public class PermissionClear extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
||||
if (contextSet.isEmpty()) {
|
||||
subjectData.clearPermissions();
|
||||
|
||||
@@ -28,7 +28,6 @@ package me.lucko.luckperms.sponge.commands;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -50,7 +49,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
|
||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
||||
if (contextSet.isEmpty()) {
|
||||
CommandUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &bANY&a.");
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.commands;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||
@@ -36,8 +34,7 @@ import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class SpongeCommandUtils {
|
||||
public final class SpongeCommandUtils {
|
||||
|
||||
public static Tristate parseTristate(int index, List<String> args) throws ArgumentUtils.ArgumentException {
|
||||
String s = args.get(index).toLowerCase();
|
||||
@@ -92,4 +89,6 @@ public class SpongeCommandUtils {
|
||||
return CommandUtils.contextSetToString(set);
|
||||
}
|
||||
|
||||
private SpongeCommandUtils() {}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SpongeMainCommand extends Command<Void, LPSubjectData> {
|
||||
|
||||
LocaleManager locale = plugin.getLocaleManager();
|
||||
|
||||
subCommands = ImmutableMap.<String, List<Command<LPSubjectData, ?>>>builder()
|
||||
this.subCommands = ImmutableMap.<String, List<Command<LPSubjectData, ?>>>builder()
|
||||
.put("permission", ImmutableList.<Command<LPSubjectData, ?>>builder()
|
||||
.add(new PermissionInfo(locale))
|
||||
.add(new PermissionSet(locale))
|
||||
@@ -90,7 +90,7 @@ public class SpongeMainCommand extends Command<Void, LPSubjectData> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) {
|
||||
LuckPermsService service = this.plugin.getService();
|
||||
|
||||
if (args.size() < 1) {
|
||||
@@ -152,7 +152,7 @@ public class SpongeMainCommand extends Command<Void, LPSubjectData> {
|
||||
}
|
||||
|
||||
String cmd = args.get(3);
|
||||
Optional<Command<LPSubjectData, ?>> o = subCommands.get(type).stream()
|
||||
Optional<Command<LPSubjectData, ?>> o = this.subCommands.get(type).stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(cmd))
|
||||
.findAny();
|
||||
|
||||
@@ -203,7 +203,7 @@ public class SpongeMainCommand extends Command<Void, LPSubjectData> {
|
||||
public void sendDetailedUsage(Sender sender, String label) {
|
||||
CommandUtils.sendPluginMessage(sender, "&b" + getName() + " Sub Commands: &7(" + String.format("/%s sponge <collection> <subject> [-transient]", label) + " ...)");
|
||||
for (String s : Arrays.asList("Permission", "Parent", "Option")) {
|
||||
List<Command> subs = subCommands.get(s.toLowerCase()).stream()
|
||||
List<Command> subs = this.subCommands.get(s.toLowerCase()).stream()
|
||||
.filter(sub -> sub.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -222,7 +222,7 @@ public class SpongeMainCommand extends Command<Void, LPSubjectData> {
|
||||
}
|
||||
|
||||
public List<Command<LPSubjectData, ?>> getSubCommands() {
|
||||
return subCommands.values().stream().flatMap(List::stream).collect(ImmutableCollectors.toList());
|
||||
return this.subCommands.values().stream().flatMap(List::stream).collect(ImmutableCollectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-5
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.contexts;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.sponge.service.context.DelegatingMutableContextSet;
|
||||
@@ -36,14 +34,20 @@ import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@AllArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ProxiedContextCalculator implements ContextCalculator<Subject> {
|
||||
private final org.spongepowered.api.service.context.ContextCalculator<Subject> delegate;
|
||||
|
||||
public ProxiedContextCalculator(org.spongepowered.api.service.context.ContextCalculator<Subject> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
||||
public MutableContextSet giveApplicableContext(@Nonnull Subject subject, @Nonnull MutableContextSet accumulator) {
|
||||
Set<Context> contexts = new DelegatingMutableContextSet(accumulator);
|
||||
delegate.accumulateContexts(subject, contexts);
|
||||
this.delegate.accumulateContexts(subject, contexts);
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,11 +42,11 @@ public class SpongeContextManager extends AbstractContextManager<Subject> {
|
||||
public Contexts formContexts(Subject subject, ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
contextSet,
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.contexts;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
@@ -37,12 +35,18 @@ import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class WorldCalculator implements ContextCalculator<Subject> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public WorldCalculator(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
||||
public MutableContextSet giveApplicableContext(@Nonnull Subject subject, @Nonnull MutableContextSet accumulator) {
|
||||
CommandSource source = subject.getCommandSource().orElse(null);
|
||||
if (source == null || !(source instanceof Player)) {
|
||||
return accumulator;
|
||||
@@ -52,7 +56,7 @@ public class WorldCalculator implements ContextCalculator<Subject> {
|
||||
String world = p.getWorld().getName().toLowerCase();
|
||||
while (!accumulator.has(Contexts.WORLD_KEY, world)) {
|
||||
accumulator.add(Contexts.WORLD_KEY, world);
|
||||
world = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||
world = this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
|
||||
+23
-22
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@@ -47,13 +45,16 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SpongeConnectionListener {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
private final Set<UUID> deniedAsyncLogin = Collections.synchronizedSet(new HashSet<>());
|
||||
private final Set<UUID> deniedLogin = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
public SpongeConnectionListener(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Listener(order = Order.EARLY)
|
||||
@IsCancelled(Tristate.UNDEFINED)
|
||||
public void onClientAuth(ClientConnectionEvent.Auth e) {
|
||||
@@ -63,11 +64,11 @@ public class SpongeConnectionListener {
|
||||
final GameProfile p = e.getProfile();
|
||||
final String username = p.getName().orElseThrow(() -> new RuntimeException("No username present for user " + p.getUniqueId()));
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
plugin.getLog().info("Processing auth event for " + p.getUniqueId() + " - " + p.getName());
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
this.plugin.getLog().info("Processing auth event for " + p.getUniqueId() + " - " + p.getName());
|
||||
}
|
||||
|
||||
plugin.getUniqueConnections().add(p.getUniqueId());
|
||||
this.plugin.getUniqueConnections().add(p.getUniqueId());
|
||||
|
||||
/* Actually process the login for the connection.
|
||||
We do this here to delay the login until the data is ready.
|
||||
@@ -79,18 +80,18 @@ public class SpongeConnectionListener {
|
||||
- creating a user instance in the UserManager for this connection.
|
||||
- setting up cached data. */
|
||||
try {
|
||||
User user = LoginHelper.loadUser(plugin, p.getUniqueId(), username, false);
|
||||
plugin.getEventFactory().handleUserLoginProcess(p.getUniqueId(), username, user);
|
||||
User user = LoginHelper.loadUser(this.plugin, p.getUniqueId(), username, false);
|
||||
this.plugin.getEventFactory().handleUserLoginProcess(p.getUniqueId(), username, user);
|
||||
} catch (Exception ex) {
|
||||
plugin.getLog().severe("Exception occured whilst loading data for " + p.getUniqueId() + " - " + p.getName());
|
||||
this.plugin.getLog().severe("Exception occured whilst loading data for " + p.getUniqueId() + " - " + p.getName());
|
||||
ex.printStackTrace();
|
||||
|
||||
deniedAsyncLogin.add(p.getUniqueId());
|
||||
this.deniedAsyncLogin.add(p.getUniqueId());
|
||||
|
||||
e.setCancelled(true);
|
||||
e.setMessageCancelled(false);
|
||||
//noinspection deprecation
|
||||
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
|
||||
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,11 +102,11 @@ public class SpongeConnectionListener {
|
||||
If the connection was cancelled here, we need to do something to clean up the data that was loaded. */
|
||||
|
||||
// Check to see if this connection was denied at LOW.
|
||||
if (deniedAsyncLogin.remove(e.getProfile().getUniqueId())) {
|
||||
if (this.deniedAsyncLogin.remove(e.getProfile().getUniqueId())) {
|
||||
|
||||
// This is a problem, as they were denied at low priority, but are now being allowed.
|
||||
if (e.isCancelled()) {
|
||||
plugin.getLog().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
|
||||
this.plugin.getLog().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -120,21 +121,21 @@ public class SpongeConnectionListener {
|
||||
|
||||
final GameProfile player = e.getProfile();
|
||||
|
||||
if (plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
plugin.getLog().info("Processing login event for " + player.getUniqueId() + " - " + player.getName());
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
this.plugin.getLog().info("Processing login event for " + player.getUniqueId() + " - " + player.getName());
|
||||
}
|
||||
|
||||
final User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
|
||||
/* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
|
||||
if (user == null) {
|
||||
deniedLogin.add(player.getUniqueId());
|
||||
this.deniedLogin.add(player.getUniqueId());
|
||||
|
||||
plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
|
||||
this.plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
|
||||
e.setCancelled(true);
|
||||
e.setMessageCancelled(false);
|
||||
//noinspection deprecation
|
||||
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
|
||||
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,10 +146,10 @@ public class SpongeConnectionListener {
|
||||
If the connection was cancelled here, we need to do something to clean up the data that was loaded. */
|
||||
|
||||
// Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present.
|
||||
if (deniedLogin.remove(e.getProfile().getUniqueId())) {
|
||||
if (this.deniedLogin.remove(e.getProfile().getUniqueId())) {
|
||||
// This is a problem, as they were denied at low priority, but are now being allowed.
|
||||
if (!e.isCancelled()) {
|
||||
plugin.getLog().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
|
||||
this.plugin.getLog().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -160,7 +161,7 @@ public class SpongeConnectionListener {
|
||||
on players when they disconnect. The instance gets cleared up on a housekeeping task
|
||||
after a period of inactivity. */
|
||||
|
||||
final UuidCache cache = plugin.getUuidCache();
|
||||
final UuidCache cache = this.plugin.getUuidCache();
|
||||
|
||||
// Unload the user from memory when they disconnect
|
||||
cache.clearCache(e.getTargetEntity().getUniqueId());
|
||||
|
||||
+5
-4
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
@@ -34,10 +32,13 @@ import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.command.SendCommandEvent;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SpongePlatformListener {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
public SpongePlatformListener(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onSendCommand(SendCommandEvent e) {
|
||||
CommandSource source = e.getCause().first(CommandSource.class).orElse(null);
|
||||
@@ -45,7 +46,7 @@ public class SpongePlatformListener {
|
||||
|
||||
final String name = e.getCommand().toLowerCase();
|
||||
if (((name.equals("op") || name.equals("minecraft:op")) && source.hasPermission("minecraft.command.op")) || ((name.equals("deop") || name.equals("minecraft:deop")) && source.hasPermission("minecraft.command.deop"))) {
|
||||
Message.OP_DISABLED_SPONGE.send(plugin.getSenderFactory().wrap(source));
|
||||
Message.OP_DISABLED_SPONGE.send(this.plugin.getSenderFactory().wrap(source));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -57,6 +54,7 @@ import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -65,7 +63,6 @@ import java.util.function.Predicate;
|
||||
|
||||
public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
|
||||
@Getter
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
private SubjectCollection spongeProxy = null;
|
||||
@@ -104,7 +101,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public SpongeGroup apply(String name) {
|
||||
return new SpongeGroup(name, plugin);
|
||||
return new SpongeGroup(name, this.plugin);
|
||||
}
|
||||
|
||||
/* ------------------------------------------
|
||||
@@ -113,28 +110,28 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public Map<String, SpongeGroup> getAll() {
|
||||
return ImmutableMap.copyOf(objects.asMap());
|
||||
return ImmutableMap.copyOf(this.objects.asMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeGroup getOrMake(String id) {
|
||||
return objects.get(id.toLowerCase());
|
||||
return this.objects.get(id.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeGroup getIfLoaded(String id) {
|
||||
return objects.getIfPresent(id.toLowerCase());
|
||||
return this.objects.getIfPresent(id.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(String id) {
|
||||
return objects.asMap().containsKey(id.toLowerCase());
|
||||
return this.objects.asMap().containsKey(id.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(String id) {
|
||||
if (id != null) {
|
||||
objects.invalidate(id.toLowerCase());
|
||||
this.objects.invalidate(id.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +144,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public void unloadAll() {
|
||||
objects.invalidateAll();
|
||||
this.objects.invalidateAll();
|
||||
}
|
||||
|
||||
/* ------------------------------------------
|
||||
@@ -156,16 +153,16 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public synchronized SubjectCollection sponge() {
|
||||
if (spongeProxy == null) {
|
||||
Preconditions.checkNotNull(plugin.getService(), "service");
|
||||
spongeProxy = ProxyFactory.toSponge(this);
|
||||
if (this.spongeProxy == null) {
|
||||
Objects.requireNonNull(this.plugin.getService(), "service");
|
||||
this.spongeProxy = ProxyFactory.toSponge(this);
|
||||
}
|
||||
return spongeProxy;
|
||||
return this.spongeProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return plugin.getService();
|
||||
return this.plugin.getService();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,12 +183,12 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
return fut;
|
||||
}
|
||||
|
||||
LPSubject present = subjectLoadingCache.getIfPresent(identifier.toLowerCase());
|
||||
LPSubject present = this.subjectLoadingCache.getIfPresent(identifier.toLowerCase());
|
||||
if (present != null) {
|
||||
return CompletableFuture.completedFuture(present);
|
||||
}
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> subjectLoadingCache.get(identifier.toLowerCase()), plugin.getScheduler().async());
|
||||
return CompletableFuture.supplyAsync(() -> this.subjectLoadingCache.get(identifier.toLowerCase()), this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,7 +214,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
}
|
||||
|
||||
return ret.build();
|
||||
}, plugin.getScheduler().async());
|
||||
}, this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,7 +232,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||
|
||||
List<HeldPermission<String>> lookup = plugin.getStorage().getGroupsWithPermission(permission).join();
|
||||
List<HeldPermission<String>> lookup = this.plugin.getStorage().getGroupsWithPermission(permission).join();
|
||||
for (HeldPermission<String> holder : lookup) {
|
||||
if (holder.asNode().getFullContexts().equals(ImmutableContextSet.empty())) {
|
||||
ret.put(SubjectReferenceFactory.obtain(getService(), getIdentifier(), holder.getHolder()), holder.getValue());
|
||||
@@ -243,7 +240,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
}
|
||||
|
||||
return ret.build();
|
||||
}, plugin.getScheduler().async());
|
||||
}, this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -251,7 +248,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||
|
||||
List<HeldPermission<String>> lookup = plugin.getStorage().getGroupsWithPermission(permission).join();
|
||||
List<HeldPermission<String>> lookup = this.plugin.getStorage().getGroupsWithPermission(permission).join();
|
||||
for (HeldPermission<String> holder : lookup) {
|
||||
if (holder.asNode().getFullContexts().equals(contexts)) {
|
||||
ret.put(SubjectReferenceFactory.obtain(getService(), getIdentifier(), holder.getHolder()), holder.getValue());
|
||||
@@ -259,12 +256,12 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
}
|
||||
|
||||
return ret.build();
|
||||
}, plugin.getScheduler().async());
|
||||
}, this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(String permission) {
|
||||
return objects.asMap().values().stream()
|
||||
return this.objects.asMap().values().stream()
|
||||
.map(SpongeGroup::sponge)
|
||||
.map(sub -> Maps.immutableEntry(sub, sub.getPermissionValue(ImmutableContextSet.empty(), permission)))
|
||||
.filter(pair -> pair.getValue() != Tristate.UNDEFINED)
|
||||
@@ -273,7 +270,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(ImmutableContextSet contexts, String permission) {
|
||||
return objects.asMap().values().stream()
|
||||
return this.objects.asMap().values().stream()
|
||||
.map(SpongeGroup::sponge)
|
||||
.map(sub -> Maps.immutableEntry(sub, sub.getPermissionValue(contexts, permission)))
|
||||
.filter(pair -> pair.getValue() != Tristate.UNDEFINED)
|
||||
@@ -309,4 +306,9 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public LPSpongePlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,11 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -57,6 +54,7 @@ import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@@ -66,7 +64,6 @@ import java.util.function.Predicate;
|
||||
|
||||
public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
|
||||
@Getter
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
private SubjectCollection spongeProxy = null;
|
||||
@@ -109,8 +106,8 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
@Override
|
||||
public SpongeUser apply(UserIdentifier id) {
|
||||
return !id.getUsername().isPresent() ?
|
||||
new SpongeUser(id.getUuid(), plugin) :
|
||||
new SpongeUser(id.getUuid(), id.getUsername().get(), plugin);
|
||||
new SpongeUser(id.getUuid(), this.plugin) :
|
||||
new SpongeUser(id.getUuid(), id.getUsername().get(), this.plugin);
|
||||
}
|
||||
|
||||
/* ------------------------------------------
|
||||
@@ -119,12 +116,12 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public Map<UserIdentifier, SpongeUser> getAll() {
|
||||
return ImmutableMap.copyOf(objects.asMap());
|
||||
return ImmutableMap.copyOf(this.objects.asMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeUser getOrMake(UserIdentifier id) {
|
||||
SpongeUser ret = objects.get(id);
|
||||
SpongeUser ret = this.objects.get(id);
|
||||
if (id.getUsername().isPresent()) {
|
||||
ret.setName(id.getUsername().get(), false);
|
||||
}
|
||||
@@ -133,18 +130,18 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public SpongeUser getIfLoaded(UserIdentifier id) {
|
||||
return objects.getIfPresent(id);
|
||||
return this.objects.getIfPresent(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(UserIdentifier id) {
|
||||
return objects.asMap().containsKey(id);
|
||||
return this.objects.asMap().containsKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(UserIdentifier id) {
|
||||
if (id != null) {
|
||||
objects.invalidate(id);
|
||||
this.objects.invalidate(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +154,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public void unloadAll() {
|
||||
objects.invalidateAll();
|
||||
this.objects.invalidateAll();
|
||||
}
|
||||
|
||||
/* ------------------------------------------
|
||||
@@ -182,7 +179,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public boolean giveDefaultIfNeeded(User user, boolean save) {
|
||||
return GenericUserManager.giveDefaultIfNeeded(user, save, plugin);
|
||||
return GenericUserManager.giveDefaultIfNeeded(user, save, this.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,10 +196,10 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
@Override
|
||||
public CompletableFuture<Void> updateAllUsers() {
|
||||
return CompletableFuture.runAsync(
|
||||
() -> plugin.getOnlinePlayers()
|
||||
.map(u -> plugin.getUuidCache().getUUID(u))
|
||||
.forEach(u -> plugin.getStorage().loadUser(u, null).join()),
|
||||
plugin.getScheduler().async()
|
||||
() -> this.plugin.getOnlinePlayers()
|
||||
.map(u -> this.plugin.getUuidCache().getUUID(u))
|
||||
.forEach(u -> this.plugin.getStorage().loadUser(u, null).join()),
|
||||
this.plugin.getScheduler().async()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -212,16 +209,16 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public synchronized SubjectCollection sponge() {
|
||||
if (spongeProxy == null) {
|
||||
Preconditions.checkNotNull(plugin.getService(), "service");
|
||||
spongeProxy = ProxyFactory.toSponge(this);
|
||||
if (this.spongeProxy == null) {
|
||||
Objects.requireNonNull(this.plugin.getService(), "service");
|
||||
this.spongeProxy = ProxyFactory.toSponge(this);
|
||||
}
|
||||
return spongeProxy;
|
||||
return this.spongeProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return plugin.getService();
|
||||
return this.plugin.getService();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -253,12 +250,12 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
return fut;
|
||||
}
|
||||
|
||||
LPSubject present = subjectLoadingCache.getIfPresent(uuid);
|
||||
LPSubject present = this.subjectLoadingCache.getIfPresent(uuid);
|
||||
if (present != null) {
|
||||
return CompletableFuture.completedFuture(present);
|
||||
}
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> subjectLoadingCache.get(uuid), plugin.getScheduler().async());
|
||||
return CompletableFuture.supplyAsync(() -> this.subjectLoadingCache.get(uuid), this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,7 +285,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
}
|
||||
|
||||
UUID finalUuid = uuid;
|
||||
return plugin.getStorage().getUniqueUsers().thenApply(set -> set.contains(finalUuid));
|
||||
return this.plugin.getStorage().getUniqueUsers().thenApply(set -> set.contains(finalUuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -307,7 +304,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
}
|
||||
|
||||
return ret.build();
|
||||
}, plugin.getScheduler().async());
|
||||
}, this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -321,10 +318,10 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
ImmutableSet.Builder<String> ids = ImmutableSet.builder();
|
||||
|
||||
getAll().keySet().forEach(uuid -> ids.add(uuid.getUuid().toString()));
|
||||
plugin.getStorage().getUniqueUsers().join().forEach(uuid -> ids.add(uuid.toString()));
|
||||
this.plugin.getStorage().getUniqueUsers().join().forEach(uuid -> ids.add(uuid.toString()));
|
||||
|
||||
return ids.build();
|
||||
}, plugin.getScheduler().async());
|
||||
}, this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -332,7 +329,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||
|
||||
List<HeldPermission<UUID>> lookup = plugin.getStorage().getUsersWithPermission(permission).join();
|
||||
List<HeldPermission<UUID>> lookup = this.plugin.getStorage().getUsersWithPermission(permission).join();
|
||||
for (HeldPermission<UUID> holder : lookup) {
|
||||
if (holder.asNode().getFullContexts().equals(ImmutableContextSet.empty())) {
|
||||
ret.put(SubjectReferenceFactory.obtain(getService(), getIdentifier(), holder.getHolder().toString()), holder.getValue());
|
||||
@@ -340,7 +337,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
}
|
||||
|
||||
return ret.build();
|
||||
}, plugin.getScheduler().async());
|
||||
}, this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -348,7 +345,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||
|
||||
List<HeldPermission<UUID>> lookup = plugin.getStorage().getUsersWithPermission(permission).join();
|
||||
List<HeldPermission<UUID>> lookup = this.plugin.getStorage().getUsersWithPermission(permission).join();
|
||||
for (HeldPermission<UUID> holder : lookup) {
|
||||
if (holder.asNode().getFullContexts().equals(contexts)) {
|
||||
ret.put(SubjectReferenceFactory.obtain(getService(), getIdentifier(), holder.getHolder().toString()), holder.getValue());
|
||||
@@ -356,12 +353,12 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
}
|
||||
|
||||
return ret.build();
|
||||
}, plugin.getScheduler().async());
|
||||
}, this.plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(String permission) {
|
||||
return objects.asMap().values().stream()
|
||||
return this.objects.asMap().values().stream()
|
||||
.map(SpongeUser::sponge)
|
||||
.map(sub -> Maps.immutableEntry(sub, sub.getPermissionValue(ImmutableContextSet.empty(), permission)))
|
||||
.filter(pair -> pair.getValue() != Tristate.UNDEFINED)
|
||||
@@ -370,7 +367,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(ImmutableContextSet contexts, String permission) {
|
||||
return objects.asMap().values().stream()
|
||||
return this.objects.asMap().values().stream()
|
||||
.map(SpongeUser::sponge)
|
||||
.map(sub -> Maps.immutableEntry(sub, sub.getPermissionValue(contexts, permission)))
|
||||
.filter(pair -> pair.getValue() != Tristate.UNDEFINED)
|
||||
@@ -382,4 +379,8 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
return getService().getDefaultSubjects().loadSubject(getIdentifier()).join();
|
||||
}
|
||||
|
||||
public LPSpongePlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-9
@@ -41,6 +41,8 @@ import org.spongepowered.api.network.RemoteConnection;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An implementation of {@link ExtendedMessagingService} using the plugin messaging channels.
|
||||
*/
|
||||
@@ -54,25 +56,25 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
}
|
||||
|
||||
public void init() {
|
||||
channel = plugin.getGame().getChannelRegistrar().createRawChannel(plugin, CHANNEL);
|
||||
channel.addListener(Platform.Type.SERVER, this);
|
||||
this.channel = this.plugin.getGame().getChannelRegistrar().createRawChannel(this.plugin, CHANNEL);
|
||||
this.channel.addListener(Platform.Type.SERVER, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (channel != null) {
|
||||
plugin.getGame().getChannelRegistrar().unbindChannel(channel);
|
||||
if (this.channel != null) {
|
||||
this.plugin.getGame().getChannelRegistrar().unbindChannel(this.channel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(String message) {
|
||||
plugin.getSpongeScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(task -> {
|
||||
if (!plugin.getGame().isServerAvailable()) {
|
||||
this.plugin.getSpongeScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(task -> {
|
||||
if (!this.plugin.getGame().isServerAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<Player> players = plugin.getGame().getServer().getOnlinePlayers();
|
||||
Collection<Player> players = this.plugin.getGame().getServer().getOnlinePlayers();
|
||||
Player p = Iterables.getFirst(players, null);
|
||||
if (p == null) {
|
||||
return;
|
||||
@@ -81,11 +83,11 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
this.channel.sendTo(p, buf -> buf.writeUTF(message));
|
||||
|
||||
task.cancel();
|
||||
}).submit(plugin);
|
||||
}).submit(this.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePayload(ChannelBuf buf, RemoteConnection connection, Platform.Type type) {
|
||||
public void handlePayload(@Nonnull ChannelBuf buf, @Nonnull RemoteConnection connection, @Nonnull Platform.Type type) {
|
||||
String msg = buf.readUTF();
|
||||
onMessage(msg, null);
|
||||
}
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.migration;
|
||||
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -63,7 +62,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("PermissionManager");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.sponge.migration;
|
||||
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||
@@ -69,7 +68,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
|
||||
ProgressLogger log = new ProgressLogger("PermissionsEx");
|
||||
log.addListener(plugin.getConsoleSender());
|
||||
log.addListener(sender);
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.migration;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
@@ -44,8 +42,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class SpongeMigrationUtils {
|
||||
public final class SpongeMigrationUtils {
|
||||
|
||||
public static void migrateSubject(Subject from, PermissionHolder to, int priority) {
|
||||
if (to.getType().isGroup()) {
|
||||
@@ -121,4 +118,6 @@ public class SpongeMigrationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private SpongeMigrationUtils() {}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.model;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@@ -64,14 +62,12 @@ public class SpongeGroup extends Group {
|
||||
return this.spongeData;
|
||||
}
|
||||
|
||||
public class GroupSubject implements LPSubject {
|
||||
public static class GroupSubject implements LPSubject {
|
||||
private final SpongeGroup parent;
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
@Getter
|
||||
private final LuckPermsSubjectData subjectData;
|
||||
|
||||
@Getter
|
||||
private final LuckPermsSubjectData transientSubjectData;
|
||||
|
||||
private GroupSubject(LPSpongePlugin plugin, SpongeGroup parent) {
|
||||
@@ -83,12 +79,12 @@ public class SpongeGroup extends Group {
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return parent.getObjectName();
|
||||
return this.parent.getObjectName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getFriendlyIdentifier() {
|
||||
return parent.getDisplayName();
|
||||
return this.parent.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +94,7 @@ public class SpongeGroup extends Group {
|
||||
|
||||
@Override
|
||||
public LPSubjectCollection getParentCollection() {
|
||||
return plugin.getService().getGroupSubjects();
|
||||
return this.plugin.getService().getGroupSubjects();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,12 +104,22 @@ public class SpongeGroup extends Group {
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return plugin.getService();
|
||||
return this.plugin.getService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsSubjectData getSubjectData() {
|
||||
return this.subjectData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsSubjectData getTransientSubjectData() {
|
||||
return this.transientSubjectData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(ImmutableContextSet contexts, String permission) {
|
||||
return parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
return this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,7 +131,7 @@ public class SpongeGroup extends Group {
|
||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
||||
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
||||
|
||||
for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||
for (Map.Entry<String, Boolean> entry : this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||
if (!entry.getValue()) {
|
||||
continue;
|
||||
}
|
||||
@@ -135,20 +141,20 @@ public class SpongeGroup extends Group {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plugin.getGroupManager().isLoaded(groupName)) {
|
||||
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
|
||||
if (this.plugin.getGroupManager().isLoaded(groupName)) {
|
||||
subjects.add(this.plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
|
||||
}
|
||||
}
|
||||
|
||||
subjects.addAll(plugin.getService().getGroupSubjects().getDefaults().getParents(contexts));
|
||||
subjects.addAll(plugin.getService().getDefaults().getParents(contexts));
|
||||
subjects.addAll(this.plugin.getService().getGroupSubjects().getDefaults().getParents(contexts));
|
||||
subjects.addAll(this.plugin.getService().getDefaults().getParents(contexts));
|
||||
|
||||
return getService().sortSubjects(subjects.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(ImmutableContextSet contexts, String s) {
|
||||
MetaData data = parent.getCachedData().getMetaData(plugin.getContextManager().formContexts(contexts));
|
||||
MetaData data = this.parent.getCachedData().getMetaData(this.plugin.getContextManager().formContexts(contexts));
|
||||
if (s.equalsIgnoreCase(NodeFactory.PREFIX_KEY)) {
|
||||
if (data.getPrefix() != null) {
|
||||
return Optional.of(data.getPrefix());
|
||||
@@ -166,23 +172,23 @@ public class SpongeGroup extends Group {
|
||||
return Optional.of(val);
|
||||
}
|
||||
|
||||
Optional<String> v = plugin.getService().getGroupSubjects().getDefaults().getOption(contexts, s);
|
||||
Optional<String> v = this.plugin.getService().getGroupSubjects().getDefaults().getOption(contexts, s);
|
||||
if (v.isPresent()) {
|
||||
return v;
|
||||
}
|
||||
|
||||
return plugin.getService().getDefaults().getOption(contexts, s);
|
||||
return this.plugin.getService().getDefaults().getOption(contexts, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableContextSet getActiveContextSet() {
|
||||
return plugin.getContextManager().getApplicableContext(this.sponge());
|
||||
return this.plugin.getContextManager().getApplicableContext(this.sponge());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCaches(CacheLevel cacheLevel) {
|
||||
// invalidate for all changes
|
||||
parent.getCachedData().invalidateCaches();
|
||||
this.parent.getCachedData().invalidateCaches();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.model;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@@ -76,10 +74,8 @@ public class SpongeUser extends User {
|
||||
private final SpongeUser parent;
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
@Getter
|
||||
private final LuckPermsSubjectData subjectData;
|
||||
|
||||
@Getter
|
||||
private final LuckPermsSubjectData transientSubjectData;
|
||||
|
||||
private UserSubject(LPSpongePlugin plugin, SpongeUser parent) {
|
||||
@@ -91,23 +87,23 @@ public class SpongeUser extends User {
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return plugin.getUuidCache().getExternalUUID(parent.getUuid()).toString();
|
||||
return this.plugin.getUuidCache().getExternalUUID(this.parent.getUuid()).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getFriendlyIdentifier() {
|
||||
return parent.getName();
|
||||
return this.parent.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CommandSource> getCommandSource() {
|
||||
final UUID uuid = plugin.getUuidCache().getExternalUUID(parent.getUuid());
|
||||
final UUID uuid = this.plugin.getUuidCache().getExternalUUID(this.parent.getUuid());
|
||||
return Sponge.getServer().getPlayer(uuid).map(Function.identity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPSubjectCollection getParentCollection() {
|
||||
return plugin.getService().getUserSubjects();
|
||||
return this.plugin.getService().getUserSubjects();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,12 +113,22 @@ public class SpongeUser extends User {
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return plugin.getService();
|
||||
return this.plugin.getService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsSubjectData getSubjectData() {
|
||||
return this.subjectData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsSubjectData getTransientSubjectData() {
|
||||
return this.transientSubjectData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(ImmutableContextSet contexts, String permission) {
|
||||
return parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
return this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,7 +140,7 @@ public class SpongeUser extends User {
|
||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
||||
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
||||
|
||||
for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||
for (Map.Entry<String, Boolean> entry : this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||
if (!entry.getValue()) {
|
||||
continue;
|
||||
}
|
||||
@@ -144,20 +150,20 @@ public class SpongeUser extends User {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plugin.getGroupManager().isLoaded(groupName)) {
|
||||
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
|
||||
if (this.plugin.getGroupManager().isLoaded(groupName)) {
|
||||
subjects.add(this.plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
|
||||
}
|
||||
}
|
||||
|
||||
subjects.addAll(plugin.getService().getUserSubjects().getDefaults().getParents(contexts));
|
||||
subjects.addAll(plugin.getService().getDefaults().getParents(contexts));
|
||||
subjects.addAll(this.plugin.getService().getUserSubjects().getDefaults().getParents(contexts));
|
||||
subjects.addAll(this.plugin.getService().getDefaults().getParents(contexts));
|
||||
|
||||
return getService().sortSubjects(subjects.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(ImmutableContextSet contexts, String s) {
|
||||
MetaData data = parent.getCachedData().getMetaData(plugin.getContextManager().formContexts(contexts));
|
||||
MetaData data = this.parent.getCachedData().getMetaData(this.plugin.getContextManager().formContexts(contexts));
|
||||
if (s.equalsIgnoreCase(NodeFactory.PREFIX_KEY)) {
|
||||
if (data.getPrefix() != null) {
|
||||
return Optional.of(data.getPrefix());
|
||||
@@ -175,23 +181,23 @@ public class SpongeUser extends User {
|
||||
return Optional.of(val);
|
||||
}
|
||||
|
||||
Optional<String> v = plugin.getService().getUserSubjects().getDefaults().getOption(contexts, s);
|
||||
Optional<String> v = this.plugin.getService().getUserSubjects().getDefaults().getOption(contexts, s);
|
||||
if (v.isPresent()) {
|
||||
return v;
|
||||
}
|
||||
|
||||
return plugin.getService().getDefaults().getOption(contexts, s);
|
||||
return this.plugin.getService().getDefaults().getOption(contexts, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableContextSet getActiveContextSet() {
|
||||
return plugin.getContextManager().getApplicableContext(this.sponge());
|
||||
return this.plugin.getContextManager().getApplicableContext(this.sponge());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCaches(CacheLevel cacheLevel) {
|
||||
// invalidate for all changes
|
||||
parent.getCachedData().invalidateCaches();
|
||||
this.parent.getCachedData().invalidateCaches();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.processors;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||
@@ -34,19 +32,23 @@ import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class GroupDefaultsProcessor implements PermissionProcessor {
|
||||
private final LuckPermsService service;
|
||||
private final ImmutableContextSet contexts;
|
||||
|
||||
public GroupDefaultsProcessor(LuckPermsService service, ImmutableContextSet contexts) {
|
||||
this.service = service;
|
||||
this.contexts = contexts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(String permission) {
|
||||
Tristate t = service.getGroupSubjects().getDefaults().getPermissionValue(contexts, permission);
|
||||
Tristate t = this.service.getGroupSubjects().getDefaults().getPermissionValue(this.contexts, permission);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
t = service.getDefaults().getPermissionValue(contexts, permission);
|
||||
t = this.service.getDefaults().getPermissionValue(this.contexts, permission);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class SpongeWildcardProcessor implements PermissionProcessor {
|
||||
|
||||
node = node.substring(0, endIndex);
|
||||
if (!node.isEmpty()) {
|
||||
Tristate t = Tristate.fromNullableBoolean(map.get(node));
|
||||
Tristate t = Tristate.fromNullableBoolean(this.map.get(node));
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
+7
-5
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.processors;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||
@@ -34,19 +32,23 @@ import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class UserDefaultsProcessor implements PermissionProcessor {
|
||||
private final LuckPermsService service;
|
||||
private final ImmutableContextSet contexts;
|
||||
|
||||
public UserDefaultsProcessor(LuckPermsService service, ImmutableContextSet contexts) {
|
||||
this.service = service;
|
||||
this.contexts = contexts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(String permission) {
|
||||
Tristate t = service.getUserSubjects().getDefaults().getPermissionValue(contexts, permission);
|
||||
Tristate t = this.service.getUserSubjects().getDefaults().getPermissionValue(this.contexts, permission);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
t = service.getDefaults().getPermissionValue(contexts, permission);
|
||||
t = this.service.getDefaults().getPermissionValue(this.contexts, permission);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return t;
|
||||
}
|
||||
|
||||
+51
-21
@@ -25,11 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
@@ -41,54 +36,89 @@ import org.spongepowered.api.service.permission.PermissionDescription;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@EqualsAndHashCode(of = "id")
|
||||
@ToString(of = {"id", "description", "owner"})
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class LuckPermsPermissionDescription implements LPPermissionDescription {
|
||||
|
||||
@Getter
|
||||
private final LPPermissionService service;
|
||||
|
||||
@Getter
|
||||
private final String id;
|
||||
|
||||
private final Text description;
|
||||
|
||||
private final PluginContainer owner;
|
||||
@Nullable private final Text description;
|
||||
@Nullable private final PluginContainer owner;
|
||||
|
||||
private PermissionDescription spongeProxy = null;
|
||||
|
||||
public LuckPermsPermissionDescription(LPPermissionService service, String id, @Nullable Text description, @Nullable PluginContainer owner) {
|
||||
this.service = service;
|
||||
this.id = Objects.requireNonNull(id, "id");
|
||||
this.description = description;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PermissionDescription sponge() {
|
||||
if (spongeProxy == null) {
|
||||
spongeProxy = ProxyFactory.toSponge(this);
|
||||
if (this.spongeProxy == null) {
|
||||
this.spongeProxy = ProxyFactory.toSponge(this);
|
||||
}
|
||||
return spongeProxy;
|
||||
return this.spongeProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPPermissionService getService() {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Text> getDescription() {
|
||||
return Optional.ofNullable(description);
|
||||
return Optional.ofNullable(this.description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PluginContainer> getOwner() {
|
||||
return Optional.ofNullable(owner);
|
||||
return Optional.ofNullable(this.owner);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String id) {
|
||||
LPSubjectCollection collection = service.getCollection(id);
|
||||
LPSubjectCollection collection = this.service.getCollection(id);
|
||||
return (CompletableFuture) collection.getAllWithPermission(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<LPSubject, Boolean> getAssignedSubjects(String id) {
|
||||
LPSubjectCollection collection = service.getCollection(id);
|
||||
LPSubjectCollection collection = this.service.getCollection(id);
|
||||
return collection.getLoadedWithPermission(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof LuckPermsPermissionDescription)) return false;
|
||||
final LuckPermsPermissionDescription other = (LuckPermsPermissionDescription) o;
|
||||
return this.id.equals(other.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LuckPermsPermissionDescription(" +
|
||||
"id=" + this.id + ", " +
|
||||
"description=" + this.description + ", " +
|
||||
"owner=" + this.owner + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -62,6 +58,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -70,12 +67,10 @@ import java.util.function.Predicate;
|
||||
/**
|
||||
* LuckPerms implementation of the Sponge Permission Service
|
||||
*/
|
||||
@Getter
|
||||
public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final PermissionService spongeProxy;
|
||||
|
||||
private final SubjectReferenceFactory referenceFactory;
|
||||
@@ -85,7 +80,6 @@ public class LuckPermsService implements LPPermissionService {
|
||||
private final PersistedCollection defaultSubjects;
|
||||
private final Set<LPPermissionDescription> descriptionSet;
|
||||
|
||||
@Getter(value = AccessLevel.NONE)
|
||||
private final LoadingCache<String, LPSubjectCollection> collections = Caffeine.newBuilder()
|
||||
.build(s -> new PersistedCollection(this, s));
|
||||
|
||||
@@ -94,34 +88,63 @@ public class LuckPermsService implements LPPermissionService {
|
||||
this.referenceFactory = new SubjectReferenceFactory(this);
|
||||
this.spongeProxy = ProxyFactory.toSponge(this);
|
||||
|
||||
storage = new SubjectStorage(this, new File(plugin.getDataDirectory(), "sponge-data"));
|
||||
new LegacyDataMigrator(plugin, new File(plugin.getDataDirectory(), "local"), storage).run();
|
||||
this.storage = new SubjectStorage(this, new File(plugin.getDataDirectory(), "sponge-data"));
|
||||
new LegacyDataMigrator(plugin, new File(plugin.getDataDirectory(), "local"), this.storage).run();
|
||||
|
||||
userSubjects = plugin.getUserManager();
|
||||
groupSubjects = plugin.getGroupManager();
|
||||
defaultSubjects = new PersistedCollection(this, "defaults");
|
||||
defaultSubjects.loadAll();
|
||||
this.userSubjects = plugin.getUserManager();
|
||||
this.groupSubjects = plugin.getGroupManager();
|
||||
this.defaultSubjects = new PersistedCollection(this, "defaults");
|
||||
this.defaultSubjects.loadAll();
|
||||
|
||||
collections.put("user", userSubjects);
|
||||
collections.put("group", groupSubjects);
|
||||
collections.put("defaults", defaultSubjects);
|
||||
this.collections.put("user", this.userSubjects);
|
||||
this.collections.put("group", this.groupSubjects);
|
||||
this.collections.put("defaults", this.defaultSubjects);
|
||||
|
||||
for (String collection : storage.getSavedCollections()) {
|
||||
if (collections.asMap().containsKey(collection.toLowerCase())) {
|
||||
for (String collection : this.storage.getSavedCollections()) {
|
||||
if (this.collections.asMap().containsKey(collection.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PersistedCollection c = new PersistedCollection(this, collection.toLowerCase());
|
||||
c.loadAll();
|
||||
collections.put(c.getIdentifier(), c);
|
||||
this.collections.put(c.getIdentifier(), c);
|
||||
}
|
||||
|
||||
descriptionSet = ConcurrentHashMap.newKeySet();
|
||||
this.descriptionSet = ConcurrentHashMap.newKeySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionService sponge() {
|
||||
return spongeProxy;
|
||||
return this.spongeProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPSpongePlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectReferenceFactory getReferenceFactory() {
|
||||
return this.referenceFactory;
|
||||
}
|
||||
|
||||
public SubjectStorage getStorage() {
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeUserManager getUserSubjects() {
|
||||
return this.userSubjects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpongeGroupManager getGroupSubjects() {
|
||||
return this.groupSubjects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistedCollection getDefaultSubjects() {
|
||||
return this.defaultSubjects;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,24 +159,26 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
@Override
|
||||
public LPSubjectCollection getCollection(String s) {
|
||||
return collections.get(s.toLowerCase());
|
||||
Objects.requireNonNull(s);
|
||||
return this.collections.get(s.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, LPSubjectCollection> getLoadedCollections() {
|
||||
return ImmutableMap.copyOf(collections.asMap());
|
||||
return ImmutableMap.copyOf(this.collections.asMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPPermissionDescription registerPermissionDescription(String id, Text description, PluginContainer owner) {
|
||||
LuckPermsPermissionDescription desc = new LuckPermsPermissionDescription(this, id, description, owner);
|
||||
descriptionSet.add(desc);
|
||||
this.descriptionSet.add(desc);
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<LPPermissionDescription> getDescription(@NonNull String s) {
|
||||
for (LPPermissionDescription d : descriptionSet) {
|
||||
public Optional<LPPermissionDescription> getDescription(String s) {
|
||||
Objects.requireNonNull(s);
|
||||
for (LPPermissionDescription d : this.descriptionSet) {
|
||||
if (d.getId().equals(s)) {
|
||||
return Optional.of(d);
|
||||
}
|
||||
@@ -164,10 +189,10 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
@Override
|
||||
public ImmutableSet<LPPermissionDescription> getDescriptions() {
|
||||
Set<LPPermissionDescription> descriptions = new HashSet<>(descriptionSet);
|
||||
Set<LPPermissionDescription> descriptions = new HashSet<>(this.descriptionSet);
|
||||
|
||||
// collect known values from the permission vault
|
||||
for (String knownPermission : plugin.getPermissionVault().getKnownPermissions()) {
|
||||
for (String knownPermission : this.plugin.getPermissionVault().getKnownPermissions()) {
|
||||
LPPermissionDescription desc = new LuckPermsPermissionDescription(this, knownPermission, null, null);
|
||||
|
||||
// don't override plugin defined values
|
||||
@@ -181,7 +206,8 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
@Override
|
||||
public void registerContextCalculator(org.spongepowered.api.service.context.ContextCalculator<Subject> calculator) {
|
||||
plugin.getContextManager().registerCalculator(new ProxiedContextCalculator(calculator));
|
||||
Objects.requireNonNull(calculator);
|
||||
this.plugin.getContextManager().registerCalculator(new ProxiedContextCalculator(calculator));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,8 +230,8 @@ public class LuckPermsService implements LPPermissionService {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Group g1 = plugin.getGroupManager().getIfLoaded(o1.getSubjectIdentifier());
|
||||
Group g2 = plugin.getGroupManager().getIfLoaded(o2.getSubjectIdentifier());
|
||||
Group g1 = this.plugin.getGroupManager().getIfLoaded(o1.getSubjectIdentifier());
|
||||
Group g2 = this.plugin.getGroupManager().getIfLoaded(o2.getSubjectIdentifier());
|
||||
|
||||
boolean g1Null = g1 == null;
|
||||
boolean g2Null = g2 == null;
|
||||
@@ -226,14 +252,15 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
@Override
|
||||
public void invalidateAllCaches(LPSubject.CacheLevel cacheLevel) {
|
||||
for (LPSubjectCollection collection : collections.asMap().values()) {
|
||||
for (LPSubjectCollection collection : this.collections.asMap().values()) {
|
||||
for (LPSubject subject : collection.getLoadedSubjects()) {
|
||||
subject.invalidateCaches(cacheLevel);
|
||||
}
|
||||
}
|
||||
|
||||
if (cacheLevel != LPSubject.CacheLevel.OPTION) {
|
||||
plugin.getCalculatorFactory().invalidateAll();
|
||||
this.plugin.getCalculatorFactory().invalidateAll();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
@@ -52,27 +48,37 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class LuckPermsSubjectData implements LPSubjectData {
|
||||
private final boolean enduring;
|
||||
private final LuckPermsService service;
|
||||
|
||||
@Getter
|
||||
private final PermissionHolder holder;
|
||||
|
||||
@Getter
|
||||
private final LPSubject parentSubject;
|
||||
|
||||
public LuckPermsSubjectData(boolean enduring, LuckPermsService service, PermissionHolder holder, LPSubject parentSubject) {
|
||||
this.enduring = enduring;
|
||||
this.service = service;
|
||||
this.holder = holder;
|
||||
this.parentSubject = parentSubject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPSubject getParentSubject() {
|
||||
return this.parentSubject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
|
||||
Map<ImmutableContextSet, ImmutableMap.Builder<String, Boolean>> perms = new HashMap<>();
|
||||
|
||||
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (enduring ? holder.getEnduringNodes() : holder.getTransientNodes()).asMap().entrySet()) {
|
||||
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (this.enduring ? this.holder.getEnduringNodes() : this.holder.getTransientNodes()).asMap().entrySet()) {
|
||||
ImmutableMap.Builder<String, Boolean> results = ImmutableMap.builder();
|
||||
for (Node n : e.getValue()) {
|
||||
results.put(n.getPermission(), n.getValuePrimitive());
|
||||
@@ -88,66 +94,72 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> setPermission(@NonNull ImmutableContextSet contexts, @NonNull String permission, @NonNull Tristate tristate) {
|
||||
public CompletableFuture<Boolean> setPermission(ImmutableContextSet contexts, String permission, Tristate tristate) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
Objects.requireNonNull(tristate, "tristate");
|
||||
|
||||
if (tristate == Tristate.UNDEFINED) {
|
||||
// Unset
|
||||
Node node = NodeFactory.builder(permission).withExtraContext(contexts).build();
|
||||
|
||||
if (enduring) {
|
||||
holder.unsetPermission(node);
|
||||
if (this.enduring) {
|
||||
this.holder.unsetPermission(node);
|
||||
} else {
|
||||
holder.unsetTransientPermission(node);
|
||||
this.holder.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
Node node = NodeFactory.builder(permission).setValue(tristate.asBoolean()).withExtraContext(contexts).build();
|
||||
|
||||
// Workaround: unset the inverse, to allow false -> true, true -> false overrides.
|
||||
if (enduring) {
|
||||
holder.unsetPermission(node);
|
||||
if (this.enduring) {
|
||||
this.holder.unsetPermission(node);
|
||||
} else {
|
||||
holder.unsetTransientPermission(node);
|
||||
this.holder.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
if (enduring) {
|
||||
holder.setPermission(node);
|
||||
if (this.enduring) {
|
||||
this.holder.setPermission(node);
|
||||
} else {
|
||||
holder.setTransientPermission(node);
|
||||
this.holder.setTransientPermission(node);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearPermissions() {
|
||||
boolean ret;
|
||||
if (enduring) {
|
||||
ret = holder.clearNodes();
|
||||
if (this.enduring) {
|
||||
ret = this.holder.clearNodes();
|
||||
} else {
|
||||
ret = holder.clearTransientNodes();
|
||||
ret = this.holder.clearTransientNodes();
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
if (holder.getType().isUser()) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
if (this.holder.getType().isUser()) {
|
||||
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearPermissions(@NonNull ImmutableContextSet set) {
|
||||
public CompletableFuture<Boolean> clearPermissions(ImmutableContextSet contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
boolean ret;
|
||||
if (enduring) {
|
||||
ret = holder.clearNodes(set);
|
||||
if (this.enduring) {
|
||||
ret = this.holder.clearNodes(contexts);
|
||||
} else {
|
||||
List<Node> toRemove = streamNodes(false)
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.filter(n -> n.getFullContexts().equals(contexts))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(false));
|
||||
@@ -158,22 +170,22 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
if (holder.getType().isUser()) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
if (this.holder.getType().isUser()) {
|
||||
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<ImmutableContextSet, ImmutableList<SubjectReference>> getAllParents() {
|
||||
Map<ImmutableContextSet, ImmutableList.Builder<SubjectReference>> parents = new HashMap<>();
|
||||
|
||||
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (enduring ? holder.getEnduringNodes() : holder.getTransientNodes()).asMap().entrySet()) {
|
||||
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (this.enduring ? this.holder.getEnduringNodes() : this.holder.getTransientNodes()).asMap().entrySet()) {
|
||||
ImmutableList.Builder<SubjectReference> results = ImmutableList.builder();
|
||||
for (Node n : e.getValue()) {
|
||||
if (n.isGroupNode()) {
|
||||
results.add(service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
|
||||
results.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
|
||||
}
|
||||
}
|
||||
parents.put(e.getKey(), results);
|
||||
@@ -187,17 +199,20 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> addParent(@NonNull ImmutableContextSet contexts, @NonNull SubjectReference subject) {
|
||||
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, SubjectReference subject) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
|
||||
if (subject.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
return subject.resolveLp().thenCompose(sub -> {
|
||||
DataMutateResult result;
|
||||
|
||||
if (enduring) {
|
||||
result = holder.setPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
if (this.enduring) {
|
||||
result = this.holder.setPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
} else {
|
||||
result = holder.setTransientPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
result = this.holder.setTransientPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
}
|
||||
@@ -206,24 +221,27 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
});
|
||||
}
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> removeParent(@NonNull ImmutableContextSet contexts, @NonNull SubjectReference subject) {
|
||||
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, SubjectReference subject) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
|
||||
if (subject.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
subject.resolveLp().thenCompose(sub -> {
|
||||
DataMutateResult result;
|
||||
|
||||
if (enduring) {
|
||||
result = holder.unsetPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
if (this.enduring) {
|
||||
result = this.holder.unsetPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
} else {
|
||||
result = holder.unsetTransientPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
result = this.holder.unsetTransientPermission(NodeFactory.buildGroupNode(sub.getIdentifier())
|
||||
.withExtraContext(contexts)
|
||||
.build());
|
||||
}
|
||||
@@ -232,7 +250,7 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
});
|
||||
}
|
||||
return CompletableFuture.completedFuture(false);
|
||||
@@ -241,8 +259,8 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearParents() {
|
||||
boolean ret;
|
||||
if (enduring) {
|
||||
ret = holder.clearParents(true);
|
||||
if (this.enduring) {
|
||||
ret = this.holder.clearParents(true);
|
||||
} else {
|
||||
List<Node> toRemove = streamNodes(false)
|
||||
.filter(Node::isGroupNode)
|
||||
@@ -251,8 +269,8 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
toRemove.forEach(makeUnsetConsumer(false));
|
||||
ret = !toRemove.isEmpty();
|
||||
|
||||
if (ret && holder.getType().isUser()) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
if (ret && this.holder.getType().isUser()) {
|
||||
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,25 +278,27 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearParents(@NonNull ImmutableContextSet set) {
|
||||
public CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
boolean ret;
|
||||
if (enduring) {
|
||||
ret = holder.clearParents(set, true);
|
||||
if (this.enduring) {
|
||||
ret = this.holder.clearParents(contexts, true);
|
||||
} else {
|
||||
List<Node> toRemove = streamNodes(false)
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.filter(n -> n.getFullContexts().equals(contexts))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(false));
|
||||
ret = !toRemove.isEmpty();
|
||||
|
||||
if (ret && holder.getType().isUser()) {
|
||||
service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||
if (ret && this.holder.getType().isUser()) {
|
||||
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +306,7 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -295,7 +315,7 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
Map<ImmutableContextSet, Integer> minPrefixPriority = new HashMap<>();
|
||||
Map<ImmutableContextSet, Integer> minSuffixPriority = new HashMap<>();
|
||||
|
||||
for (Node n : enduring ? holder.getEnduringNodes().values() : holder.getTransientNodes().values()) {
|
||||
for (Node n : this.enduring ? this.holder.getEnduringNodes().values() : this.holder.getTransientNodes().values()) {
|
||||
if (!n.getValuePrimitive()) continue;
|
||||
if (!n.isMeta() && !n.isPrefix() && !n.isSuffix()) continue;
|
||||
|
||||
@@ -339,51 +359,58 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> setOption(@NonNull ImmutableContextSet context, @NonNull String key, @NonNull String value) {
|
||||
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(value, "value");
|
||||
|
||||
if (key.equalsIgnoreCase(NodeFactory.PREFIX_KEY) || key.equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
|
||||
// special handling.
|
||||
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
|
||||
|
||||
// remove all prefixes/suffixes from the user
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
List<Node> toRemove = streamNodes(this.enduring)
|
||||
.filter(type::matches)
|
||||
.filter(n -> n.getFullContexts().equals(context))
|
||||
.filter(n -> n.getFullContexts().equals(contexts))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
toRemove.forEach(makeUnsetConsumer(this.enduring));
|
||||
|
||||
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, null, service.getPlugin().getContextManager().formContexts(context));
|
||||
MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, null, this.service.getPlugin().getContextManager().formContexts(contexts));
|
||||
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
|
||||
priority += 10;
|
||||
|
||||
if (enduring) {
|
||||
holder.setPermission(NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(context).build());
|
||||
if (this.enduring) {
|
||||
this.holder.setPermission(NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(contexts).build());
|
||||
} else {
|
||||
holder.setTransientPermission(NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(context).build());
|
||||
this.holder.setTransientPermission(NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(contexts).build());
|
||||
}
|
||||
|
||||
} else {
|
||||
// standard remove
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
List<Node> toRemove = streamNodes(this.enduring)
|
||||
.filter(n -> n.isMeta() && n.getMeta().getKey().equals(key))
|
||||
.filter(n -> n.getFullContexts().equals(context))
|
||||
.filter(n -> n.getFullContexts().equals(contexts))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
toRemove.forEach(makeUnsetConsumer(this.enduring));
|
||||
|
||||
if (enduring) {
|
||||
holder.setPermission(NodeFactory.buildMetaNode(key, value).withExtraContext(context).build());
|
||||
if (this.enduring) {
|
||||
this.holder.setPermission(NodeFactory.buildMetaNode(key, value).withExtraContext(contexts).build());
|
||||
} else {
|
||||
holder.setTransientPermission(NodeFactory.buildMetaNode(key, value).withExtraContext(context).build());
|
||||
this.holder.setTransientPermission(NodeFactory.buildMetaNode(key, value).withExtraContext(contexts).build());
|
||||
}
|
||||
}
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> unsetOption(ImmutableContextSet set, String key) {
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
public CompletableFuture<Boolean> unsetOption(ImmutableContextSet contexts, String key) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
Objects.requireNonNull(key, "key");
|
||||
|
||||
List<Node> toRemove = streamNodes(this.enduring)
|
||||
.filter(n -> {
|
||||
if (key.equalsIgnoreCase(NodeFactory.PREFIX_KEY)) {
|
||||
return n.isPrefix();
|
||||
@@ -393,82 +420,84 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
return n.isMeta() && n.getMeta().getKey().equals(key);
|
||||
}
|
||||
})
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.filter(n -> n.getFullContexts().equals(contexts))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
toRemove.forEach(makeUnsetConsumer(this.enduring));
|
||||
|
||||
return objectSave(holder).thenApply(v -> true);
|
||||
return objectSave(this.holder).thenApply(v -> true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearOptions(@NonNull ImmutableContextSet set) {
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
public CompletableFuture<Boolean> clearOptions(ImmutableContextSet contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
List<Node> toRemove = streamNodes(this.enduring)
|
||||
.filter(n -> n.isMeta() || n.isPrefix() || n.isSuffix())
|
||||
.filter(n -> n.getFullContexts().equals(set))
|
||||
.filter(n -> n.getFullContexts().equals(contexts))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
toRemove.forEach(makeUnsetConsumer(this.enduring));
|
||||
|
||||
return objectSave(holder).thenApply(v -> !toRemove.isEmpty());
|
||||
return objectSave(this.holder).thenApply(v -> !toRemove.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearOptions() {
|
||||
List<Node> toRemove = streamNodes(enduring)
|
||||
List<Node> toRemove = streamNodes(this.enduring)
|
||||
.filter(n -> n.isMeta() || n.isPrefix() || n.isSuffix())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
toRemove.forEach(makeUnsetConsumer(enduring));
|
||||
toRemove.forEach(makeUnsetConsumer(this.enduring));
|
||||
|
||||
return objectSave(holder).thenApply(v -> !toRemove.isEmpty());
|
||||
return objectSave(this.holder).thenApply(v -> !toRemove.isEmpty());
|
||||
}
|
||||
|
||||
private Stream<Node> streamNodes(boolean enduring) {
|
||||
return (enduring ? holder.getEnduringNodes() : holder.getTransientNodes()).values().stream();
|
||||
return (enduring ? this.holder.getEnduringNodes() : this.holder.getTransientNodes()).values().stream();
|
||||
}
|
||||
|
||||
private Consumer<Node> makeUnsetConsumer(boolean enduring) {
|
||||
return n -> {
|
||||
if (enduring) {
|
||||
holder.unsetPermission(n);
|
||||
this.holder.unsetPermission(n);
|
||||
} else {
|
||||
holder.unsetTransientPermission(n);
|
||||
this.holder.unsetTransientPermission(n);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> objectSave(PermissionHolder t) {
|
||||
if (!enduring) {
|
||||
if (!this.enduring) {
|
||||
// don't bother saving to primary storage. just refresh
|
||||
if (t.getType().isUser()) {
|
||||
User user = ((User) t);
|
||||
return user.getRefreshBuffer().request();
|
||||
} else {
|
||||
return service.getPlugin().getUpdateTaskBuffer().request();
|
||||
return this.service.getPlugin().getUpdateTaskBuffer().request();
|
||||
}
|
||||
} else {
|
||||
if (t.getType().isUser()) {
|
||||
User user = ((User) t);
|
||||
CompletableFuture<Void> fut = new CompletableFuture<>();
|
||||
service.getPlugin().getStorage().saveUser(user).whenCompleteAsync((v, ex) -> {
|
||||
this.service.getPlugin().getStorage().saveUser(user).whenCompleteAsync((v, ex) -> {
|
||||
if (ex != null) {
|
||||
fut.complete(null);
|
||||
}
|
||||
|
||||
user.getRefreshBuffer().request().thenAccept(fut::complete);
|
||||
}, service.getPlugin().getScheduler().async());
|
||||
}, this.service.getPlugin().getScheduler().async());
|
||||
return fut;
|
||||
} else {
|
||||
Group group = ((Group) t);
|
||||
CompletableFuture<Void> fut = new CompletableFuture<>();
|
||||
service.getPlugin().getStorage().saveGroup(group).whenCompleteAsync((v, ex) -> {
|
||||
this.service.getPlugin().getStorage().saveGroup(group).whenCompleteAsync((v, ex) -> {
|
||||
if (ex != null) {
|
||||
fut.complete(null);
|
||||
}
|
||||
|
||||
service.getPlugin().getUpdateTaskBuffer().request().thenAccept(fut::complete);
|
||||
}, service.getPlugin().getScheduler().async());
|
||||
this.service.getPlugin().getUpdateTaskBuffer().request().thenAccept(fut::complete);
|
||||
}, this.service.getPlugin().getScheduler().async());
|
||||
return fut;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
@@ -40,8 +38,7 @@ import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
/**
|
||||
* Provides proxy instances which implement the SpongeAPI using the LuckPerms model.
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ProxyFactory {
|
||||
public final class ProxyFactory {
|
||||
private static final boolean IS_API_7 = isApi7();
|
||||
private static boolean isApi7() {
|
||||
try {
|
||||
@@ -77,4 +74,6 @@ public class ProxyFactory {
|
||||
new me.lucko.luckperms.sponge.service.proxy.api6.PermissionDescriptionProxy(luckPerms.getService(), luckPerms);
|
||||
}
|
||||
|
||||
private ProxyFactory() {}
|
||||
|
||||
}
|
||||
|
||||
+70
-60
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.calculated;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.CacheLoader;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
@@ -60,13 +57,13 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* In-memory implementation of {@link LPSubjectData}.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class CalculatedSubjectData implements LPSubjectData {
|
||||
|
||||
@Getter
|
||||
private final LPSubject parentSubject;
|
||||
|
||||
private final LPPermissionService service;
|
||||
@@ -80,61 +77,72 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||
.build(new CacheLoader<ImmutableContextSet, CalculatorHolder>() {
|
||||
@Override
|
||||
public CalculatorHolder load(ImmutableContextSet contexts) {
|
||||
public CalculatorHolder load(@Nonnull ImmutableContextSet contexts) {
|
||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||
processors.add(new MapProcessor());
|
||||
processors.add(new SpongeWildcardProcessor());
|
||||
|
||||
CalculatorHolder holder = new CalculatorHolder(new PermissionCalculator(service.getPlugin(), PermissionCalculatorMetadata.of(HolderType.GROUP, calculatorDisplayName, contexts), processors.build()));
|
||||
holder.setPermissions(flattenMap(getRelevantEntries(contexts, permissions)));
|
||||
CalculatorHolder holder = new CalculatorHolder(new PermissionCalculator(CalculatedSubjectData.this.service.getPlugin(), PermissionCalculatorMetadata.of(HolderType.GROUP, CalculatedSubjectData.this.calculatorDisplayName, contexts), processors.build()));
|
||||
holder.setPermissions(flattenMap(getRelevantEntries(contexts, CalculatedSubjectData.this.permissions)));
|
||||
|
||||
return holder;
|
||||
}
|
||||
});
|
||||
|
||||
public CalculatedSubjectData(LPSubject parentSubject, LPPermissionService service, String calculatorDisplayName) {
|
||||
this.parentSubject = parentSubject;
|
||||
this.service = service;
|
||||
this.calculatorDisplayName = calculatorDisplayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPSubject getParentSubject() {
|
||||
return this.parentSubject;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
permissionCache.cleanUp();
|
||||
this.permissionCache.cleanUp();
|
||||
}
|
||||
|
||||
public void invalidateLookupCache() {
|
||||
permissionCache.invalidateAll();
|
||||
this.permissionCache.invalidateAll();
|
||||
}
|
||||
|
||||
public Tristate getPermissionValue(ImmutableContextSet contexts, String permission) {
|
||||
return permissionCache.get(contexts).getCalculator().getPermissionValue(permission, CheckOrigin.INTERNAL);
|
||||
return this.permissionCache.get(contexts).getCalculator().getPermissionValue(permission, CheckOrigin.INTERNAL);
|
||||
}
|
||||
|
||||
public void replacePermissions(Map<ImmutableContextSet, Map<String, Boolean>> map) {
|
||||
permissions.clear();
|
||||
this.permissions.clear();
|
||||
for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> e : map.entrySet()) {
|
||||
permissions.put(e.getKey(), new ConcurrentHashMap<>(e.getValue()));
|
||||
this.permissions.put(e.getKey(), new ConcurrentHashMap<>(e.getValue()));
|
||||
}
|
||||
permissionCache.invalidateAll();
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
this.permissionCache.invalidateAll();
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
}
|
||||
|
||||
public void replaceParents(Map<ImmutableContextSet, List<SubjectReference>> map) {
|
||||
parents.clear();
|
||||
this.parents.clear();
|
||||
for (Map.Entry<ImmutableContextSet, List<SubjectReference>> e : map.entrySet()) {
|
||||
Set<SubjectReference> set = ConcurrentHashMap.newKeySet();
|
||||
set.addAll(e.getValue());
|
||||
parents.put(e.getKey(), set);
|
||||
this.parents.put(e.getKey(), set);
|
||||
}
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
}
|
||||
|
||||
public void replaceOptions(Map<ImmutableContextSet, Map<String, String>> map) {
|
||||
options.clear();
|
||||
this.options.clear();
|
||||
for (Map.Entry<ImmutableContextSet, Map<String, String>> e : map.entrySet()) {
|
||||
options.put(e.getKey(), new ConcurrentHashMap<>(e.getValue()));
|
||||
this.options.put(e.getKey(), new ConcurrentHashMap<>(e.getValue()));
|
||||
}
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
|
||||
ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, Boolean>> map = ImmutableMap.builder();
|
||||
for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> e : permissions.entrySet()) {
|
||||
for (Map.Entry<ImmutableContextSet, Map<String, Boolean>> e : this.permissions.entrySet()) {
|
||||
map.put(e.getKey(), ImmutableMap.copyOf(e.getValue()));
|
||||
}
|
||||
return map.build();
|
||||
@@ -144,42 +152,42 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
public CompletableFuture<Boolean> setPermission(ImmutableContextSet contexts, String permission, Tristate value) {
|
||||
boolean b;
|
||||
if (value == Tristate.UNDEFINED) {
|
||||
Map<String, Boolean> perms = permissions.get(contexts);
|
||||
Map<String, Boolean> perms = this.permissions.get(contexts);
|
||||
b = perms != null && perms.remove(permission.toLowerCase()) != null;
|
||||
} else {
|
||||
Map<String, Boolean> perms = permissions.computeIfAbsent(contexts, c -> new ConcurrentHashMap<>());
|
||||
Map<String, Boolean> perms = this.permissions.computeIfAbsent(contexts, c -> new ConcurrentHashMap<>());
|
||||
b = !Objects.equals(perms.put(permission.toLowerCase(), value.asBoolean()), value.asBoolean());
|
||||
}
|
||||
if (b) {
|
||||
permissionCache.invalidateAll();
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
this.permissionCache.invalidateAll();
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
}
|
||||
return CompletableFuture.completedFuture(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearPermissions() {
|
||||
if (permissions.isEmpty()) {
|
||||
if (this.permissions.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else {
|
||||
permissions.clear();
|
||||
permissionCache.invalidateAll();
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
this.permissions.clear();
|
||||
this.permissionCache.invalidateAll();
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearPermissions(ImmutableContextSet contexts) {
|
||||
Map<String, Boolean> perms = permissions.get(contexts);
|
||||
Map<String, Boolean> perms = this.permissions.get(contexts);
|
||||
if (perms == null) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
permissions.remove(contexts);
|
||||
this.permissions.remove(contexts);
|
||||
if (!perms.isEmpty()) {
|
||||
permissionCache.invalidateAll();
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
this.permissionCache.invalidateAll();
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
return CompletableFuture.completedFuture(false);
|
||||
@@ -188,59 +196,59 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public ImmutableMap<ImmutableContextSet, ImmutableList<SubjectReference>> getAllParents() {
|
||||
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<SubjectReference>> map = ImmutableMap.builder();
|
||||
for (Map.Entry<ImmutableContextSet, Set<SubjectReference>> e : parents.entrySet()) {
|
||||
map.put(e.getKey(), service.sortSubjects(e.getValue()));
|
||||
for (Map.Entry<ImmutableContextSet, Set<SubjectReference>> e : this.parents.entrySet()) {
|
||||
map.put(e.getKey(), this.service.sortSubjects(e.getValue()));
|
||||
}
|
||||
return map.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, SubjectReference parent) {
|
||||
Set<SubjectReference> set = parents.computeIfAbsent(contexts, c -> ConcurrentHashMap.newKeySet());
|
||||
Set<SubjectReference> set = this.parents.computeIfAbsent(contexts, c -> ConcurrentHashMap.newKeySet());
|
||||
boolean b = set.add(parent);
|
||||
if (b) {
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
}
|
||||
return CompletableFuture.completedFuture(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, SubjectReference parent) {
|
||||
Set<SubjectReference> set = parents.get(contexts);
|
||||
Set<SubjectReference> set = this.parents.get(contexts);
|
||||
boolean b = set != null && set.remove(parent);
|
||||
if (b) {
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
}
|
||||
return CompletableFuture.completedFuture(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearParents() {
|
||||
if (parents.isEmpty()) {
|
||||
if (this.parents.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else {
|
||||
parents.clear();
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
this.parents.clear();
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts) {
|
||||
Set<SubjectReference> set = parents.get(contexts);
|
||||
Set<SubjectReference> set = this.parents.get(contexts);
|
||||
if (set == null) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
parents.remove(contexts);
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
this.parents.remove(contexts);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
return CompletableFuture.completedFuture(!set.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, String>> getAllOptions() {
|
||||
ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, String>> map = ImmutableMap.builder();
|
||||
for (Map.Entry<ImmutableContextSet, Map<String, String>> e : options.entrySet()) {
|
||||
for (Map.Entry<ImmutableContextSet, Map<String, String>> e : this.options.entrySet()) {
|
||||
map.put(e.getKey(), ImmutableMap.copyOf(e.getValue()));
|
||||
}
|
||||
return map.build();
|
||||
@@ -251,7 +259,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
Map<String, String> options = this.options.computeIfAbsent(contexts, c -> new ConcurrentHashMap<>());
|
||||
boolean b = !stringEquals(options.put(key.toLowerCase(), value), value);
|
||||
if (b) {
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
}
|
||||
return CompletableFuture.completedFuture(b);
|
||||
}
|
||||
@@ -261,31 +269,31 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
Map<String, String> options = this.options.get(contexts);
|
||||
boolean b = options != null && options.remove(key.toLowerCase()) != null;
|
||||
if (b) {
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
}
|
||||
return CompletableFuture.completedFuture(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearOptions() {
|
||||
if (options.isEmpty()) {
|
||||
if (this.options.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} else {
|
||||
options.clear();
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
this.options.clear();
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearOptions(ImmutableContextSet contexts) {
|
||||
Map<String, String> map = options.get(contexts);
|
||||
Map<String, String> map = this.options.get(contexts);
|
||||
if (map == null) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
options.remove(contexts);
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
this.options.remove(contexts);
|
||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.OPTION);
|
||||
return CompletableFuture.completedFuture(!map.isEmpty());
|
||||
}
|
||||
|
||||
@@ -321,23 +329,25 @@ public class CalculatedSubjectData implements LPSubjectData {
|
||||
|
||||
private static class CalculatorHolder {
|
||||
|
||||
@Getter
|
||||
private final PermissionCalculator calculator;
|
||||
|
||||
@Getter
|
||||
private final Map<String, Boolean> permissions;
|
||||
|
||||
public CalculatorHolder(PermissionCalculator calculator) {
|
||||
this.calculator = calculator;
|
||||
this.permissions = new ConcurrentHashMap<>();
|
||||
this.calculator.updateBacking(permissions);
|
||||
this.calculator.updateBacking(this.permissions);
|
||||
}
|
||||
|
||||
public void setPermissions(Map<String, Boolean> permissions) {
|
||||
this.permissions.clear();
|
||||
this.permissions.putAll(permissions);
|
||||
calculator.updateBacking(this.permissions);
|
||||
calculator.invalidateCache();
|
||||
this.calculator.updateBacking(this.permissions);
|
||||
this.calculator.invalidateCache();
|
||||
}
|
||||
|
||||
public PermissionCalculator getCalculator() {
|
||||
return this.calculator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-9
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.legacy;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorage;
|
||||
|
||||
@@ -37,22 +35,27 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@RequiredArgsConstructor
|
||||
public class LegacyDataMigrator implements Runnable {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
private final File oldDirectory;
|
||||
private final SubjectStorage storage;
|
||||
|
||||
public LegacyDataMigrator(LPSpongePlugin plugin, File oldDirectory, SubjectStorage storage) {
|
||||
this.plugin = plugin;
|
||||
this.oldDirectory = oldDirectory;
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!oldDirectory.exists() || !oldDirectory.isDirectory()) {
|
||||
if (!this.oldDirectory.exists() || !this.oldDirectory.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getLog().warn("Migrating old sponge data... Please wait.");
|
||||
this.plugin.getLog().warn("Migrating old sponge data... Please wait.");
|
||||
|
||||
File[] collections = oldDirectory.listFiles(File::isDirectory);
|
||||
File[] collections = this.oldDirectory.listFiles(File::isDirectory);
|
||||
if (collections == null) {
|
||||
return;
|
||||
}
|
||||
@@ -68,8 +71,8 @@ public class LegacyDataMigrator implements Runnable {
|
||||
String subjectName = subjectFile.getName().substring(0, subjectFile.getName().length() - ".json".length());
|
||||
|
||||
try (BufferedReader reader = Files.newBufferedReader(subjectFile.toPath(), StandardCharsets.UTF_8)) {
|
||||
SubjectDataHolder holder = storage.getGson().fromJson(reader, SubjectDataHolder.class);
|
||||
storage.saveToFile(holder.asSubjectModel(plugin.getService()), storage.resolveFile(collectionDir.getName(), subjectName));
|
||||
SubjectDataHolder holder = this.storage.getGson().fromJson(reader, SubjectDataHolder.class);
|
||||
this.storage.saveToFile(holder.asSubjectModel(this.plugin.getService()), this.storage.resolveFile(collectionDir.getName(), subjectName));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -80,6 +83,6 @@ public class LegacyDataMigrator implements Runnable {
|
||||
collectionDir.delete();
|
||||
}
|
||||
|
||||
oldDirectory.delete();
|
||||
this.oldDirectory.delete();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-6
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.legacy;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
||||
@@ -41,7 +39,6 @@ import java.util.stream.Collectors;
|
||||
* @see SubjectStorageModel
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@ToString
|
||||
@Deprecated
|
||||
public class SubjectDataHolder {
|
||||
private Map<Map<String, String>, Map<String, Boolean>> permissions;
|
||||
@@ -54,17 +51,17 @@ public class SubjectDataHolder {
|
||||
|
||||
public SubjectStorageModel asSubjectModel(LPPermissionService service) {
|
||||
return new SubjectStorageModel(service,
|
||||
permissions.entrySet().stream()
|
||||
this.permissions.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
k -> ImmutableContextSet.fromMap(k.getKey()),
|
||||
Map.Entry::getValue
|
||||
)),
|
||||
options.entrySet().stream()
|
||||
this.options.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
k -> ImmutableContextSet.fromMap(k.getKey()),
|
||||
Map.Entry::getValue
|
||||
)),
|
||||
parents.entrySet().stream()
|
||||
this.parents.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
k -> ImmutableContextSet.fromMap(k.getKey()),
|
||||
v -> v.getValue().stream().map(s -> SubjectReferenceFactory.deserialize(service, s)).collect(Collectors.toList())
|
||||
|
||||
+39
-9
@@ -25,20 +25,50 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public final class OptionLookupKey {
|
||||
|
||||
public static OptionLookupKey of(String key, ImmutableContextSet contexts) {
|
||||
return new OptionLookupKey(key, contexts);
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private final ImmutableContextSet contexts;
|
||||
|
||||
private OptionLookupKey(String key, ImmutableContextSet contexts) {
|
||||
this.key = key;
|
||||
this.contexts = contexts;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public ImmutableContextSet getContexts() {
|
||||
return this.contexts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof OptionLookupKey)) return false;
|
||||
final OptionLookupKey other = (OptionLookupKey) o;
|
||||
|
||||
return this.getKey().equals(other.getKey()) && this.getContexts().equals(other.getContexts());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getKey().hashCode();
|
||||
result = result * PRIME + this.getContexts().hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OptionLookupKey(key=" + this.getKey() + ", contexts=" + this.getContexts() + ")";
|
||||
}
|
||||
}
|
||||
+39
-9
@@ -25,20 +25,50 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public final class PermissionLookupKey {
|
||||
|
||||
public static PermissionLookupKey of(String node, ImmutableContextSet contexts) {
|
||||
return new PermissionLookupKey(node, contexts);
|
||||
}
|
||||
|
||||
private final String node;
|
||||
private final ImmutableContextSet contexts;
|
||||
|
||||
private PermissionLookupKey(String node, ImmutableContextSet contexts) {
|
||||
this.node = node;
|
||||
this.contexts = contexts;
|
||||
}
|
||||
|
||||
public String getNode() {
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public ImmutableContextSet getContexts() {
|
||||
return this.contexts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof PermissionLookupKey)) return false;
|
||||
final PermissionLookupKey other = (PermissionLookupKey) o;
|
||||
|
||||
return this.getNode().equals(other.getNode()) && this.getContexts().equals(other.getContexts());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getNode().hashCode();
|
||||
result = result * PRIME + this.getContexts().hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PermissionLookupKey(node=" + this.getNode() + ", contexts=" + this.getContexts() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
+22
-18
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
@@ -57,15 +54,12 @@ import java.util.function.Predicate;
|
||||
/**
|
||||
* A simple persistable subject collection
|
||||
*/
|
||||
@Getter
|
||||
public class PersistedCollection implements LPSubjectCollection {
|
||||
private final LuckPermsService service;
|
||||
private final String identifier;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final SubjectCollection spongeProxy;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final LoadingCache<String, PersistedSubject> subjects = Caffeine.newBuilder()
|
||||
.build(s -> new PersistedSubject(s, getService(), PersistedCollection.this));
|
||||
|
||||
@@ -76,16 +70,26 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
}
|
||||
|
||||
public void loadAll() {
|
||||
Map<String, SubjectStorageModel> holders = service.getStorage().loadAllFromFile(identifier);
|
||||
Map<String, SubjectStorageModel> holders = this.service.getStorage().loadAllFromFile(this.identifier);
|
||||
for (Map.Entry<String, SubjectStorageModel> e : holders.entrySet()) {
|
||||
PersistedSubject subject = subjects.get(e.getKey().toLowerCase());
|
||||
PersistedSubject subject = this.subjects.get(e.getKey().toLowerCase());
|
||||
subject.loadData(e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectCollection sponge() {
|
||||
return spongeProxy;
|
||||
return this.spongeProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,36 +99,36 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<LPSubject> loadSubject(String identifier) {
|
||||
return CompletableFuture.completedFuture(subjects.get(identifier.toLowerCase()));
|
||||
return CompletableFuture.completedFuture(this.subjects.get(identifier.toLowerCase()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<LPSubject> getSubject(String identifier) {
|
||||
return Optional.of(subjects.get(identifier.toLowerCase()));
|
||||
return Optional.of(this.subjects.get(identifier.toLowerCase()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> hasRegistered(String identifier) {
|
||||
return CompletableFuture.completedFuture(subjects.asMap().containsKey(identifier.toLowerCase()));
|
||||
return CompletableFuture.completedFuture(this.subjects.asMap().containsKey(identifier.toLowerCase()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ImmutableCollection<LPSubject>> loadSubjects(Set<String> identifiers) {
|
||||
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
|
||||
for (String id : identifiers) {
|
||||
ret.add(subjects.get(id.toLowerCase()));
|
||||
ret.add(this.subjects.get(id.toLowerCase()));
|
||||
}
|
||||
return CompletableFuture.completedFuture(ret.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableCollection<LPSubject> getLoadedSubjects() {
|
||||
return ImmutableList.copyOf(subjects.asMap().values());
|
||||
return ImmutableList.copyOf(this.subjects.asMap().values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ImmutableSet<String>> getAllIdentifiers() {
|
||||
return CompletableFuture.completedFuture(ImmutableSet.copyOf(subjects.asMap().keySet()));
|
||||
return CompletableFuture.completedFuture(ImmutableSet.copyOf(this.subjects.asMap().keySet()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,7 +146,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(String permission) {
|
||||
ImmutableMap.Builder<LPSubject, Boolean> m = ImmutableMap.builder();
|
||||
for (LPSubject subject : subjects.asMap().values()) {
|
||||
for (LPSubject subject : this.subjects.asMap().values()) {
|
||||
Tristate ts = subject.getPermissionValue(ImmutableContextSet.empty(), permission);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
m.put(subject, ts.asBoolean());
|
||||
@@ -155,7 +159,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
@Override
|
||||
public ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(ImmutableContextSet contexts, String permission) {
|
||||
ImmutableMap.Builder<LPSubject, Boolean> m = ImmutableMap.builder();
|
||||
for (LPSubject subject : subjects.asMap().values()) {
|
||||
for (LPSubject subject : this.subjects.asMap().values()) {
|
||||
Tristate ts = subject.getPermissionValue(contexts, permission);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
m.put(subject, ts.asBoolean());
|
||||
@@ -167,7 +171,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
|
||||
@Override
|
||||
public LPSubject getDefaults() {
|
||||
return service.getDefaultSubjects().loadSubject(getIdentifier()).join();
|
||||
return this.service.getDefaultSubjects().loadSubject(getIdentifier()).join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+72
-43
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -49,13 +46,13 @@ import org.spongepowered.api.service.permission.Subject;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A simple persistable Subject implementation
|
||||
*/
|
||||
@Getter
|
||||
public class PersistedSubject implements LPSubject {
|
||||
private final String identifier;
|
||||
|
||||
@@ -81,7 +78,7 @@ public class PersistedSubject implements LPSubject {
|
||||
@Override
|
||||
protected Void perform() {
|
||||
try {
|
||||
service.getStorage().saveToFile(PersistedSubject.this);
|
||||
PersistedSubject.this.service.getStorage().saveToFile(PersistedSubject.this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -100,21 +97,21 @@ public class PersistedSubject implements LPSubject {
|
||||
|
||||
@Override
|
||||
public void invalidateCaches(CacheLevel type) {
|
||||
optionLookupCache.invalidateAll();
|
||||
this.optionLookupCache.invalidateAll();
|
||||
|
||||
if (type == CacheLevel.OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
permissionLookupCache.invalidateAll();
|
||||
subjectData.invalidateLookupCache();
|
||||
transientSubjectData.invalidateLookupCache();
|
||||
this.permissionLookupCache.invalidateAll();
|
||||
this.subjectData.invalidateLookupCache();
|
||||
this.transientSubjectData.invalidateLookupCache();
|
||||
|
||||
if (type == CacheLevel.PERMISSION) {
|
||||
return;
|
||||
}
|
||||
|
||||
parentLookupCache.invalidateAll();
|
||||
this.parentLookupCache.invalidateAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,13 +124,13 @@ public class PersistedSubject implements LPSubject {
|
||||
}
|
||||
|
||||
public void loadData(SubjectStorageModel dataHolder) {
|
||||
subjectData.setSave(false);
|
||||
dataHolder.applyToData(subjectData);
|
||||
subjectData.setSave(true);
|
||||
this.subjectData.setSave(false);
|
||||
dataHolder.applyToData(this.subjectData);
|
||||
this.subjectData.setSave(true);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
saveBuffer.request();
|
||||
this.saveBuffer.request();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,6 +138,31 @@ public class PersistedSubject implements LPSubject {
|
||||
return ProxyFactory.toSponge(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistedCollection getParentCollection() {
|
||||
return this.parentCollection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistedSubjectData getSubjectData() {
|
||||
return this.subjectData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatedSubjectData getTransientSubjectData() {
|
||||
return this.transientSubjectData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CommandSource> getCommandSource() {
|
||||
return Optional.empty();
|
||||
@@ -150,23 +172,23 @@ public class PersistedSubject implements LPSubject {
|
||||
Tristate res;
|
||||
|
||||
// if transient has priority
|
||||
if (!parentCollection.getIdentifier().equals("defaults")) {
|
||||
res = transientSubjectData.getPermissionValue(contexts, node);
|
||||
if (!this.parentCollection.getIdentifier().equals("defaults")) {
|
||||
res = this.transientSubjectData.getPermissionValue(contexts, node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = subjectData.getPermissionValue(contexts, node);
|
||||
res = this.subjectData.getPermissionValue(contexts, node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
res = subjectData.getPermissionValue(contexts, node);
|
||||
res = this.subjectData.getPermissionValue(contexts, node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = transientSubjectData.getPermissionValue(contexts, node);
|
||||
res = this.transientSubjectData.getPermissionValue(contexts, node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
@@ -188,44 +210,44 @@ public class PersistedSubject implements LPSubject {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = service.getDefaults().getPermissionValue(contexts, node);
|
||||
res = this.service.getDefaults().getPermissionValue(contexts, node);
|
||||
return res;
|
||||
}
|
||||
|
||||
private ImmutableList<SubjectReference> lookupParents(ImmutableContextSet contexts) {
|
||||
List<SubjectReference> s = new ArrayList<>();
|
||||
s.addAll(subjectData.getParents(contexts));
|
||||
s.addAll(transientSubjectData.getParents(contexts));
|
||||
s.addAll(this.subjectData.getParents(contexts));
|
||||
s.addAll(this.transientSubjectData.getParents(contexts));
|
||||
|
||||
if (!getParentCollection().getIdentifier().equalsIgnoreCase("defaults")) {
|
||||
s.addAll(getParentCollection().getDefaults().getParents(contexts));
|
||||
s.addAll(service.getDefaults().getParents(contexts));
|
||||
s.addAll(this.service.getDefaults().getParents(contexts));
|
||||
}
|
||||
|
||||
return service.sortSubjects(s);
|
||||
return this.service.sortSubjects(s);
|
||||
}
|
||||
|
||||
private Optional<String> lookupOptionValue(ImmutableContextSet contexts, String key) {
|
||||
Optional<String> res;
|
||||
|
||||
// if transient has priority
|
||||
if (!parentCollection.getIdentifier().equals("defaults")) {
|
||||
res = Optional.ofNullable(transientSubjectData.getOptions(contexts).get(key));
|
||||
if (!this.parentCollection.getIdentifier().equals("defaults")) {
|
||||
res = Optional.ofNullable(this.transientSubjectData.getOptions(contexts).get(key));
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = Optional.ofNullable(subjectData.getOptions(contexts).get(key));
|
||||
res = Optional.ofNullable(this.subjectData.getOptions(contexts).get(key));
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
res = Optional.ofNullable(subjectData.getOptions(contexts).get(key));
|
||||
res = Optional.ofNullable(this.subjectData.getOptions(contexts).get(key));
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res = Optional.ofNullable(transientSubjectData.getOptions(contexts).get(key));
|
||||
res = Optional.ofNullable(this.transientSubjectData.getOptions(contexts).get(key));
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
@@ -247,41 +269,48 @@ public class PersistedSubject implements LPSubject {
|
||||
return res;
|
||||
}
|
||||
|
||||
return service.getDefaults().getOption(contexts, key);
|
||||
return this.service.getDefaults().getOption(contexts, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(@NonNull ImmutableContextSet contexts, @NonNull String node) {
|
||||
Tristate t = permissionLookupCache.get(PermissionLookupKey.of(node, contexts));
|
||||
service.getPlugin().getVerboseHandler().offerCheckData(CheckOrigin.INTERNAL, getParentCollection().getIdentifier() + "/" + identifier, contexts, node, t);
|
||||
public Tristate getPermissionValue(ImmutableContextSet contexts, String node) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
Objects.requireNonNull(node, "node");
|
||||
|
||||
Tristate t = this.permissionLookupCache.get(PermissionLookupKey.of(node, contexts));
|
||||
this.service.getPlugin().getVerboseHandler().offerCheckData(CheckOrigin.INTERNAL, getParentCollection().getIdentifier() + "/" + this.identifier, contexts, node, t);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(@NonNull ImmutableContextSet contexts, @NonNull SubjectReference subject) {
|
||||
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference subject) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
|
||||
if (getParentCollection().getIdentifier().equalsIgnoreCase("defaults")) {
|
||||
return subjectData.getParents(contexts).contains(subject) ||
|
||||
transientSubjectData.getParents(contexts).contains(subject);
|
||||
return this.subjectData.getParents(contexts).contains(subject) ||
|
||||
this.transientSubjectData.getParents(contexts).contains(subject);
|
||||
} else {
|
||||
return subjectData.getParents(contexts).contains(subject) ||
|
||||
transientSubjectData.getParents(contexts).contains(subject) ||
|
||||
return this.subjectData.getParents(contexts).contains(subject) ||
|
||||
this.transientSubjectData.getParents(contexts).contains(subject) ||
|
||||
getParentCollection().getDefaults().getParents(contexts).contains(subject) ||
|
||||
service.getDefaults().getParents(contexts).contains(subject);
|
||||
this.service.getDefaults().getParents(contexts).contains(subject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<SubjectReference> getParents(@NonNull ImmutableContextSet contexts) {
|
||||
return parentLookupCache.get(contexts);
|
||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
return this.parentLookupCache.get(contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(ImmutableContextSet contexts, String key) {
|
||||
return optionLookupCache.get(OptionLookupKey.of(key, contexts));
|
||||
return this.optionLookupCache.get(OptionLookupKey.of(key, contexts));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableContextSet getActiveContextSet() {
|
||||
return service.getPlugin().getContextManager().getApplicableContext(sponge());
|
||||
return this.service.getPlugin().getContextManager().getApplicableContext(sponge());
|
||||
}
|
||||
}
|
||||
|
||||
+11
-8
@@ -25,9 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.persisted;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
@@ -43,8 +40,6 @@ import java.util.function.Function;
|
||||
public class PersistedSubjectData extends CalculatedSubjectData implements Function<Boolean, Boolean> {
|
||||
private final PersistedSubject subject;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean save = true;
|
||||
|
||||
public PersistedSubjectData(LuckPermsService service, String calculatorDisplayName, PersistedSubject subject) {
|
||||
@@ -53,12 +48,12 @@ public class PersistedSubjectData extends CalculatedSubjectData implements Funct
|
||||
}
|
||||
|
||||
private void save() {
|
||||
if (!save) {
|
||||
if (!this.save) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (subject != null) {
|
||||
subject.save();
|
||||
if (this.subject != null) {
|
||||
this.subject.save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,4 +117,12 @@ public class PersistedSubjectData extends CalculatedSubjectData implements Funct
|
||||
public CompletableFuture<Boolean> clearOptions(ImmutableContextSet contexts) {
|
||||
return super.clearOptions(contexts).thenApply(this);
|
||||
}
|
||||
|
||||
public boolean isSave() {
|
||||
return this.save;
|
||||
}
|
||||
|
||||
public void setSave(boolean save) {
|
||||
this.save = save;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.storage;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
@@ -55,7 +53,6 @@ public class SubjectStorage {
|
||||
|
||||
private final LPPermissionService service;
|
||||
|
||||
@Getter
|
||||
private final Gson gson;
|
||||
|
||||
private final File container;
|
||||
@@ -74,7 +71,7 @@ public class SubjectStorage {
|
||||
public Set<String> getSavedCollections() {
|
||||
checkContainer();
|
||||
|
||||
File[] dirs = container.listFiles(File::isDirectory);
|
||||
File[] dirs = this.container.listFiles(File::isDirectory);
|
||||
if (dirs == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
@@ -84,7 +81,7 @@ public class SubjectStorage {
|
||||
|
||||
public File resolveFile(String collectionName, String subjectName) {
|
||||
checkContainer();
|
||||
File collection = new File(container, collectionName);
|
||||
File collection = new File(this.container, collectionName);
|
||||
if (!collection.exists()) {
|
||||
collection.mkdirs();
|
||||
}
|
||||
@@ -105,14 +102,14 @@ public class SubjectStorage {
|
||||
file.createNewFile();
|
||||
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
|
||||
gson.toJson(model.toJson(), writer);
|
||||
this.gson.toJson(model.toJson(), writer);
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, SubjectStorageModel> loadAllFromFile(String collectionName) {
|
||||
checkContainer();
|
||||
File collection = new File(container, collectionName);
|
||||
File collection = new File(this.container, collectionName);
|
||||
if (!collection.exists()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
@@ -139,7 +136,7 @@ public class SubjectStorage {
|
||||
|
||||
public Map.Entry<String, SubjectStorageModel> loadFromFile(String collectionName, String subjectName) throws IOException {
|
||||
checkContainer();
|
||||
File collection = new File(container, collectionName);
|
||||
File collection = new File(this.container, collectionName);
|
||||
if (!collection.exists()) {
|
||||
return null;
|
||||
}
|
||||
@@ -156,10 +153,13 @@ public class SubjectStorage {
|
||||
String subjectName = file.getName().substring(0, file.getName().length() - ".json".length());
|
||||
|
||||
try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
|
||||
JsonObject data = gson.fromJson(reader, JsonObject.class);
|
||||
SubjectStorageModel model = new SubjectStorageModel(service, data);
|
||||
JsonObject data = this.gson.fromJson(reader, JsonObject.class);
|
||||
SubjectStorageModel model = new SubjectStorageModel(this.service, data);
|
||||
return Maps.immutableEntry(subjectName, model);
|
||||
}
|
||||
}
|
||||
|
||||
public Gson getGson() {
|
||||
return this.gson;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.storage;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -50,7 +48,6 @@ import java.util.Map;
|
||||
/**
|
||||
* Used for converting a SubjectData instance to and from JSON
|
||||
*/
|
||||
@Getter
|
||||
public class SubjectStorageModel {
|
||||
private final LPPermissionService service;
|
||||
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions;
|
||||
@@ -256,8 +253,13 @@ public class SubjectStorageModel {
|
||||
}
|
||||
|
||||
public void applyToData(CalculatedSubjectData subjectData) {
|
||||
subjectData.replacePermissions(permissions);
|
||||
subjectData.replaceOptions(options);
|
||||
subjectData.replaceParents(parents);
|
||||
subjectData.replacePermissions(this.permissions);
|
||||
subjectData.replaceOptions(this.options);
|
||||
subjectData.replaceParents(this.parents);
|
||||
}
|
||||
|
||||
public LPPermissionService getService() {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-4
@@ -25,19 +25,20 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.tasks;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ServiceCacheHousekeepingTask implements Runnable {
|
||||
private final LuckPermsService service;
|
||||
|
||||
public ServiceCacheHousekeepingTask(LuckPermsService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (LPSubjectCollection collection : service.getLoadedCollections().values()) {
|
||||
for (LPSubjectCollection collection : this.service.getLoadedCollections().values()) {
|
||||
for (LPSubject subject : collection.getLoadedSubjects()) {
|
||||
subject.performCleanup();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user