misc refactoring

This commit is contained in:
Luck 2018-01-01 19:48:20 +00:00
parent 4fd89e6a34
commit 505a10a8b1
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
39 changed files with 300 additions and 236 deletions

View File

@ -25,10 +25,9 @@
package me.lucko.luckperms.bukkit;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.AbstractConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@ -40,24 +39,20 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
@RequiredArgsConstructor
public class BukkitConfigAdapter implements ConfigurationAdapter {
@Getter
private final LPBukkitPlugin plugin;
public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter {
private final File file;
private YamlConfiguration configuration;
public BukkitConfigAdapter(LuckPermsPlugin plugin, File file) {
super(plugin);
this.file = file;
reload();
}
@Override
public void init() {
File configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) {
configFile.getParentFile().mkdirs();
plugin.saveResource("config.yml", false);
}
configuration = YamlConfiguration.loadConfiguration(configFile);
public void reload() {
configuration = YamlConfiguration.loadConfiguration(file);
}
@Override

View File

@ -44,8 +44,8 @@ import me.lucko.luckperms.bukkit.processors.ChildPermissionProvider;
import me.lucko.luckperms.bukkit.processors.DefaultsProvider;
import me.lucko.luckperms.bukkit.vault.VaultHookManager;
import me.lucko.luckperms.common.actionlog.LogDispatcher;
import me.lucko.luckperms.common.api.ApiProvider;
import me.lucko.luckperms.common.api.ApiSingletonUtils;
import me.lucko.luckperms.common.api.ApiRegistrationUtil;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.buffers.BufferedRequest;
import me.lucko.luckperms.common.buffers.UpdateTaskBuffer;
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
@ -59,6 +59,7 @@ import me.lucko.luckperms.common.contexts.ContextManager;
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
import me.lucko.luckperms.common.dependencies.Dependency;
import me.lucko.luckperms.common.dependencies.DependencyManager;
import me.lucko.luckperms.common.event.EventFactory;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.NoopLocaleManager;
import me.lucko.luckperms.common.locale.SimpleLocaleManager;
@ -124,7 +125,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
private FileWatcher fileWatcher = null;
private ExtendedMessagingService messagingService = null;
private UuidCache uuidCache;
private ApiProvider apiProvider;
private LuckPermsApiProvider apiProvider;
private EventFactory eventFactory;
private Logger log;
private DefaultsProvider defaultsProvider;
private ChildPermissionProvider childPermissionProvider;
@ -182,16 +184,17 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
private void enable() {
startTime = System.currentTimeMillis();
LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this);
sendStartupBanner(getConsoleSender());
verboseHandler = new VerboseHandler(scheduler.asyncBukkit(), getVersion());
permissionVault = new PermissionVault(scheduler.asyncBukkit());
logDispatcher = new LogDispatcher(this);
getLog().info("Loading configuration...");
configuration = new AbstractConfiguration(this, new BukkitConfigAdapter(this));
configuration.init();
configuration = new AbstractConfiguration(this, new BukkitConfigAdapter(this, resolveConfig("config.yml")));
configuration.loadAll();
Set<StorageType> storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2);
StorageFactory storageFactory = new StorageFactory(this);
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
dependencyManager.loadStorageDependencies(storageTypes);
// setup the Bukkit defaults hook
@ -211,7 +214,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
}
// initialise datastore
storage = StorageFactory.getInstance(this, StorageType.H2);
storage = storageFactory.getInstance(StorageType.H2);
// initialise messaging
messagingService = new BukkitMessagingFactory(this).getInstance();
@ -256,8 +259,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
tryVaultHook(false);
// register with the LP API
apiProvider = new ApiProvider(this);
ApiSingletonUtils.registerProvider(apiProvider);
apiProvider = new LuckPermsApiProvider(this);
// setup event factory
eventFactory = new EventFactory(this, apiProvider);
ApiRegistrationUtil.registerProvider(apiProvider);
getServer().getServicesManager().register(LuckPermsApi.class, apiProvider, this, ServicePriority.Normal);
@ -373,7 +380,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
messagingService.close();
}
ApiSingletonUtils.unregisterProvider();
ApiRegistrationUtil.unregisterProvider();
getServer().getServicesManager().unregisterAll(this);
if (vaultHookManager != null) {
@ -419,6 +426,17 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
}
}
private File resolveConfig(String file) {
File configFile = new File(getDataFolder(), file);
if (!configFile.exists()) {
getDataFolder().mkdirs();
saveResource("config.yml", false);
}
return configFile;
}
@Override
public Optional<ExtendedMessagingService> getMessagingService() {
return Optional.ofNullable(messagingService);

View File

@ -86,7 +86,7 @@ public class BukkitConnectionListener implements Listener {
- setting up cached data. */
try {
User user = LoginHelper.loadUser(plugin, e.getUniqueId(), e.getName(), false);
plugin.getApiProvider().getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
} catch (Exception ex) {
plugin.getLog().severe("Exception occured whilst loading data for " + e.getUniqueId() + " - " + e.getName());
ex.printStackTrace();

View File

@ -25,10 +25,9 @@
package me.lucko.luckperms.bungee;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.AbstractConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
@ -36,42 +35,29 @@ import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@RequiredArgsConstructor
public class BungeeConfigAdapter implements ConfigurationAdapter {
@Getter
private final LPBungeePlugin plugin;
public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter {
private final File file;
private Configuration configuration;
@SuppressWarnings("ResultOfMethodCallIgnored")
private File makeFile(String file) throws IOException {
File configFile = new File(plugin.getDataFolder(), file);
if (!configFile.exists()) {
plugin.getDataFolder().mkdir();
try (InputStream is = plugin.getResourceAsStream(file)) {
Files.copy(is, configFile.toPath());
}
}
return configFile;
public BungeeConfigAdapter(LuckPermsPlugin plugin, File file) {
super(plugin);
this.file = file;
reload();
}
@Override
public void init() {
public void reload() {
try {
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(makeFile("config.yml"));
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

View File

@ -38,8 +38,8 @@ import me.lucko.luckperms.bungee.listeners.BungeePermissionCheckListener;
import me.lucko.luckperms.bungee.messaging.BungeeMessagingFactory;
import me.lucko.luckperms.bungee.util.RedisBungeeUtil;
import me.lucko.luckperms.common.actionlog.LogDispatcher;
import me.lucko.luckperms.common.api.ApiProvider;
import me.lucko.luckperms.common.api.ApiSingletonUtils;
import me.lucko.luckperms.common.api.ApiRegistrationUtil;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.buffers.BufferedRequest;
import me.lucko.luckperms.common.buffers.UpdateTaskBuffer;
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
@ -53,6 +53,7 @@ import me.lucko.luckperms.common.contexts.ContextManager;
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
import me.lucko.luckperms.common.dependencies.Dependency;
import me.lucko.luckperms.common.dependencies.DependencyManager;
import me.lucko.luckperms.common.event.EventFactory;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.NoopLocaleManager;
import me.lucko.luckperms.common.locale.SimpleLocaleManager;
@ -83,7 +84,9 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
@ -108,7 +111,8 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
private FileWatcher fileWatcher = null;
private ExtendedMessagingService messagingService = null;
private UuidCache uuidCache;
private ApiProvider apiProvider;
private LuckPermsApiProvider apiProvider;
private EventFactory eventFactory;
private Logger log;
private LocaleManager localeManager;
private DependencyManager dependencyManager;
@ -137,16 +141,17 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
@Override
public void onEnable() {
startTime = System.currentTimeMillis();
LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this);
sendStartupBanner(getConsoleSender());
verboseHandler = new VerboseHandler(scheduler.async(), getVersion());
permissionVault = new PermissionVault(scheduler.async());
logDispatcher = new LogDispatcher(this);
getLog().info("Loading configuration...");
configuration = new AbstractConfiguration(this, new BungeeConfigAdapter(this));
configuration.init();
configuration = new AbstractConfiguration(this, new BungeeConfigAdapter(this, resolveConfig("config.yml")));
configuration.loadAll();
Set<StorageType> storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2);
StorageFactory storageFactory = new StorageFactory(this);
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
dependencyManager.loadStorageDependencies(storageTypes);
// register events
@ -159,7 +164,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
}
// initialise datastore
storage = StorageFactory.getInstance(this, StorageType.H2);
storage = storageFactory.getInstance(StorageType.H2);
// initialise messaging
messagingService = new BungeeMessagingFactory(this).getInstance();
@ -197,8 +202,12 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
}
// register with the LP API
apiProvider = new ApiProvider(this);
ApiSingletonUtils.registerProvider(apiProvider);
apiProvider = new LuckPermsApiProvider(this);
// setup event factory
eventFactory = new EventFactory(this, apiProvider);
ApiRegistrationUtil.registerProvider(apiProvider);
// schedule update tasks
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
@ -241,7 +250,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
messagingService.close();
}
ApiSingletonUtils.unregisterProvider();
ApiRegistrationUtil.unregisterProvider();
getLog().info("Shutting down internal scheduler...");
scheduler.shutdown();
@ -251,6 +260,21 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
getLog().info("Goodbye!");
}
private File resolveConfig(String file) {
File configFile = new File(getDataFolder(), file);
if (!configFile.exists()) {
getDataFolder().mkdirs();
try (InputStream is = getResourceAsStream(file)) {
Files.copy(is, configFile.toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return configFile;
}
@Override
public Optional<ExtendedMessagingService> getMessagingService() {
return Optional.ofNullable(messagingService);

View File

@ -82,7 +82,7 @@ public class BungeeConnectionListener implements Listener {
- setting up cached data. */
try {
User user = LoginHelper.loadUser(plugin, c.getUniqueId(), c.getName(), true);
plugin.getApiProvider().getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
} catch (Exception ex) {
plugin.getLog().severe("Exception occured whilst loading data for " + c.getUniqueId() + " - " + c.getName());
ex.printStackTrace();

View File

@ -47,7 +47,7 @@ public class LogDispatcher {
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
.filter(s -> {
boolean shouldCancel = LogNotify.isIgnoring(plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
return !plugin.getApiProvider().getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
return !plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
})
.forEach(s -> Message.LOG.send(s,
entry.getActorFriendlyString(),
@ -59,7 +59,7 @@ public class LogDispatcher {
public void dispatch(ExtendedLogEntry entry, Sender sender) {
// set the event to cancelled if the sender is import
if (!plugin.getApiProvider().getEventFactory().handleLogPublish(sender.isImport(), entry)) {
if (!plugin.getEventFactory().handleLogPublish(sender.isImport(), entry)) {
plugin.getStorage().logAction(entry);
}
@ -74,13 +74,13 @@ public class LogDispatcher {
}
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) {
broadcast(entry, LogBroadcastEvent.Origin.LOCAL, sender);
}
}
public void dispatchFromApi(ExtendedLogEntry entry) {
if (!plugin.getApiProvider().getEventFactory().handleLogPublish(false, entry)) {
if (!plugin.getEventFactory().handleLogPublish(false, entry)) {
try {
plugin.getStorage().logAction(entry).get();
} catch (Exception e) {
@ -95,14 +95,14 @@ public class LogDispatcher {
plugin.getMessagingService().ifPresent(extendedMessagingService -> extendedMessagingService.pushLog(entry));
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) {
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
}
}
public void dispatchFromRemote(ExtendedLogEntry entry) {
boolean shouldCancel = !plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY);
if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
if (!plugin.getEventFactory().handleLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) {
broadcast(entry, LogBroadcastEvent.Origin.LOCAL_API, null);
}
}

View File

@ -30,7 +30,7 @@ import me.lucko.luckperms.api.LuckPermsApi;
import java.lang.reflect.Method;
public class ApiSingletonUtils {
public class ApiRegistrationUtil {
private static final Method REGISTER;
private static final Method UNREGISTER;
static {

View File

@ -50,8 +50,6 @@ import me.lucko.luckperms.common.api.delegates.misc.ApiActionLogger;
import me.lucko.luckperms.common.api.delegates.misc.ApiMetaStackFactory;
import me.lucko.luckperms.common.api.delegates.misc.ApiNodeFactory;
import me.lucko.luckperms.common.api.delegates.misc.ApiPlatformInfo;
import me.lucko.luckperms.common.event.EventFactory;
import me.lucko.luckperms.common.event.LuckPermsEventBus;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.Optional;
@ -61,7 +59,7 @@ import java.util.function.Function;
/**
* Implements the LuckPerms API using the plugin instance
*/
public class ApiProvider implements LuckPermsApi {
public class LuckPermsApiProvider implements LuckPermsApi {
@Getter(AccessLevel.NONE)
private final LuckPermsPlugin plugin;
@ -70,28 +68,20 @@ public class ApiProvider implements LuckPermsApi {
private final UserManager userManager;
private final GroupManager groupManager;
private final TrackManager trackManager;
private final LuckPermsEventBus eventBus;
private final ActionLogger actionLogger;
private final ContextManager contextManager;
private final MetaStackFactory metaStackFactory;
private final EventFactory eventFactory;
public ApiProvider(LuckPermsPlugin plugin) {
public LuckPermsApiProvider(LuckPermsPlugin plugin) {
this.plugin = plugin;
this.platformInfo = new ApiPlatformInfo(plugin);
this.userManager = new ApiUserManager(plugin, plugin.getUserManager());
this.groupManager = new ApiGroupManager(plugin.getGroupManager());
this.trackManager = new ApiTrackManager(plugin.getTrackManager());
this.eventBus = new LuckPermsEventBus(plugin);
this.actionLogger = new ApiActionLogger(plugin);
this.contextManager = new ApiContextManager(plugin, plugin.getContextManager());
this.metaStackFactory = new ApiMetaStackFactory(plugin);
this.eventFactory = new EventFactory(eventBus);
}
public EventFactory getEventFactory() {
return eventFactory;
}
@Override
@ -121,7 +111,7 @@ public class ApiProvider implements LuckPermsApi {
@Override
public EventBus getEventBus() {
return eventBus;
return plugin.getEventFactory().getEventBus();
}
@Override

View File

@ -138,7 +138,7 @@ public class UserDemote extends SubCommand<User> {
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().getEventFactory().handleUserDemote(user, track, old, null);
plugin.getEventFactory().handleUserDemote(user, track, old, null);
return CommandResult.SUCCESS;
}
@ -170,7 +170,7 @@ public class UserDemote extends SubCommand<User> {
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().getEventFactory().handleUserDemote(user, track, old, previousGroup.getName());
plugin.getEventFactory().handleUserDemote(user, track, old, previousGroup.getName());
return CommandResult.SUCCESS;
}

View File

@ -60,10 +60,12 @@ public class UserInfo extends SubCommand<User> {
return CommandResult.NO_PERMISSION;
}
Message status = plugin.isPlayerOnline(plugin.getUuidCache().getExternalUUID(user.getUuid())) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message.USER_INFO_GENERAL.send(sender,
user.getName().orElse("Unknown"),
user.getUuid(),
plugin.getPlayerStatus(user.getUuid()).asString(plugin.getLocaleManager()),
status.asString(plugin.getLocaleManager()),
user.getPrimaryGroup().getValue(),
user.getOwnNodes().size(),
user.getOwnNodes().stream().filter(n -> !(n.isGroupNode() || n.isPrefix() || n.isSuffix() || n.isMeta())).mapToInt(n -> 1).sum(),

View File

@ -125,7 +125,7 @@ public class UserPromote extends SubCommand<User> {
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().getEventFactory().handleUserPromote(user, track, null, first);
plugin.getEventFactory().handleUserPromote(user, track, null, first);
return CommandResult.SUCCESS;
}
@ -182,7 +182,7 @@ public class UserPromote extends SubCommand<User> {
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().getEventFactory().handleUserPromote(user, track, old, nextGroup.getName());
plugin.getEventFactory().handleUserPromote(user, track, old, nextGroup.getName());
return CommandResult.SUCCESS;
}

View File

@ -34,6 +34,7 @@ import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import me.lucko.luckperms.common.api.delegates.misc.ApiConfiguration;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
import me.lucko.luckperms.common.config.keys.EnduringKey;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -78,21 +79,15 @@ public class AbstractConfiguration implements LuckPermsConfiguration, CacheLoade
contextsFile.load();
}
@Override
public void init() {
adapter.init();
loadAll();
}
@Override
public void reload() {
init();
adapter.reload();
Set<ConfigKey<?>> toInvalidate = cache.asMap().keySet().stream().filter(k -> !(k instanceof EnduringKey)).collect(Collectors.toSet());
cache.invalidateAll(toInvalidate);
loadAll();
getPlugin().getApiProvider().getEventFactory().handleConfigReload();
getPlugin().getEventFactory().handleConfigReload();
}
@Override

View File

@ -25,6 +25,8 @@
package me.lucko.luckperms.common.config;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
/**
* Represents a key in the configuration.
*

View File

@ -54,11 +54,6 @@ public interface LuckPermsConfiguration {
*/
ContextsFile getContextsFile();
/**
* Initialises the configuration.
*/
void init();
/**
* Reloads the configuration.
*/

View File

@ -0,0 +1,39 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.adapter;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@RequiredArgsConstructor
public abstract class AbstractConfigurationAdapter implements ConfigurationAdapter {
@Getter
private final LuckPermsPlugin plugin;
}

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.config;
package me.lucko.luckperms.common.config.adapter;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -34,7 +34,7 @@ public interface ConfigurationAdapter {
LuckPermsPlugin getPlugin();
void init();
void reload();
boolean contains(String path);

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
import java.util.function.Function;

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
@AllArgsConstructor(staticName = "of")
public class BooleanKey implements ConfigKey<Boolean> {

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
@AllArgsConstructor(staticName = "of")
public class IntegerKey implements ConfigKey<Integer> {

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
@AllArgsConstructor(staticName = "of")
public class LowercaseStringKey implements ConfigKey<String> {

View File

@ -30,7 +30,7 @@ import lombok.AllArgsConstructor;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
import java.util.Map;

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
@AllArgsConstructor(staticName = "of")
public class StaticKey<T> implements ConfigKey<T> {

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
@AllArgsConstructor(staticName = "of")
public class StringKey implements ConfigKey<String> {

View File

@ -25,8 +25,6 @@
package me.lucko.luckperms.common.event;
import lombok.RequiredArgsConstructor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -38,6 +36,7 @@ import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.event.impl.EventConfigReload;
import me.lucko.luckperms.common.event.impl.EventGroupCacheLoad;
@ -75,16 +74,24 @@ import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
@RequiredArgsConstructor
public final class EventFactory {
private final LuckPermsEventBus eventBus;
public EventFactory(LuckPermsPlugin plugin, LuckPermsApiProvider apiProvider) {
this.eventBus = new LuckPermsEventBus(plugin, apiProvider);
}
public LuckPermsEventBus getEventBus() {
return eventBus;
}
private void fireEventAsync(LuckPermsEvent event) {
eventBus.fireEventAsync(event);
}

View File

@ -35,6 +35,7 @@ import me.lucko.luckperms.api.event.Cancellable;
import me.lucko.luckperms.api.event.EventBus;
import me.lucko.luckperms.api.event.EventHandler;
import me.lucko.luckperms.api.event.LuckPermsEvent;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.Map;
@ -47,6 +48,9 @@ public class LuckPermsEventBus implements EventBus {
@Getter
private final LuckPermsPlugin plugin;
private final LuckPermsApiProvider apiProvider;
private final Map<Class<? extends LuckPermsEvent>, Set<LuckPermsEventHandler<?>>> handlerMap = new ConcurrentHashMap<>();
@Override
@ -91,7 +95,7 @@ public class LuckPermsEventBus implements EventBus {
public void fireEvent(LuckPermsEvent event) {
if (event instanceof AbstractEvent) {
((AbstractEvent) event).setApi(plugin.getApiProvider());
((AbstractEvent) event).setApi(apiProvider);
}
for (Map.Entry<Class<? extends LuckPermsEvent>, Set<LuckPermsEventHandler<?>>> ent : handlerMap.entrySet()) {

View File

@ -95,7 +95,7 @@ public abstract class AbstractMessagingService implements ExtendedMessagingServi
plugin.getLog().info("[" + name + " Messaging] Received update ping with id: " + requestId.toString());
if (plugin.getApiProvider().getEventFactory().handleNetworkPreSync(false, requestId)) {
if (plugin.getEventFactory().handleNetworkPreSync(false, requestId)) {
return;
}
@ -127,7 +127,7 @@ public abstract class AbstractMessagingService implements ExtendedMessagingServi
plugin.getLog().info("[" + name + " Messaging] Received user update ping for '" + user.getFriendlyName() + "' with id: " + uuidToString(requestId));
if (plugin.getApiProvider().getEventFactory().handleNetworkPreSync(false, requestId)) {
if (plugin.getEventFactory().handleNetworkPreSync(false, requestId)) {
return;
}
@ -160,7 +160,7 @@ public abstract class AbstractMessagingService implements ExtendedMessagingServi
return;
}
plugin.getApiProvider().getEventFactory().handleLogReceive(requestId, entry.getValue());
plugin.getEventFactory().handleLogReceive(requestId, entry.getValue());
plugin.getLogDispatcher().dispatchFromRemote(entry.getValue());
if (callback != null) {
@ -197,7 +197,7 @@ public abstract class AbstractMessagingService implements ExtendedMessagingServi
UUID requestId = generatePingId();
String strId = uuidToString(requestId);
if (plugin.getApiProvider().getEventFactory().handleLogNetworkPublish(!plugin.getConfiguration().get(ConfigKeys.PUSH_LOG_ENTRIES), requestId, logEntry)) {
if (plugin.getEventFactory().handleLogNetworkPublish(!plugin.getConfiguration().get(ConfigKeys.PUSH_LOG_ENTRIES), requestId, logEntry)) {
return;
}

View File

@ -71,7 +71,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
this.refreshBuffer = new GroupRefreshBuffer(plugin, this);
this.cachedData = new GroupCachedData(this);
getPlugin().getApiProvider().getEventFactory().handleGroupCacheLoad(this, cachedData);
getPlugin().getEventFactory().handleGroupCacheLoad(this, cachedData);
// invalidate out caches when data is updated
getStateListeners().add(() -> refreshBuffer.request());
@ -121,7 +121,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
return CompletableFuture.allOf(
cachedData.reloadPermissions(),
cachedData.reloadMeta()
).thenAccept(n -> getPlugin().getApiProvider().getEventFactory().handleGroupDataRecalculate(this, cachedData));
).thenAccept(n -> getPlugin().getEventFactory().handleGroupDataRecalculate(this, cachedData));
}
private static final class GroupRefreshBuffer extends BufferedRequest<Void> {

View File

@ -514,7 +514,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -940,7 +940,7 @@ public abstract class PermissionHolder {
ImmutableSet<Node> after = ImmutableSet.copyOf(getOwnNodesSet());
for (Node r : removed) {
plugin.getApiProvider().getEventFactory().handleNodeRemove(r, this, before, after);
plugin.getEventFactory().handleNodeRemove(r, this, before, after);
}
return true;
@ -1023,7 +1023,7 @@ public abstract class PermissionHolder {
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
plugin.getEventFactory().handleNodeAdd(node, this, before, after);
return DataMutateResult.SUCCESS;
}
@ -1060,7 +1060,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeAdd(newNode, this, before, after);
plugin.getEventFactory().handleNodeAdd(newNode, this, before, after);
return Maps.immutableEntry(DataMutateResult.SUCCESS, newNode);
}
@ -1087,7 +1087,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
plugin.getEventFactory().handleNodeAdd(node, this, before, after);
return Maps.immutableEntry(DataMutateResult.SUCCESS, node);
}
}
@ -1123,7 +1123,7 @@ public abstract class PermissionHolder {
ImmutableCollection<Node> after = getTransientNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeAdd(node, this, before, after);
plugin.getEventFactory().handleNodeAdd(node, this, before, after);
return DataMutateResult.SUCCESS;
}
@ -1149,7 +1149,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
plugin.getEventFactory().handleNodeRemove(node, this, before, after);
return DataMutateResult.SUCCESS;
}
@ -1175,7 +1175,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getTransientNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeRemove(node, this, before, after);
plugin.getEventFactory().handleNodeRemove(node, this, before, after);
return DataMutateResult.SUCCESS;
}
@ -1207,7 +1207,7 @@ public abstract class PermissionHolder {
return false;
}
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1227,7 +1227,7 @@ public abstract class PermissionHolder {
return false;
}
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1250,7 +1250,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1277,7 +1277,7 @@ public abstract class PermissionHolder {
}
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1295,7 +1295,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1319,7 +1319,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1338,7 +1338,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1362,7 +1362,7 @@ public abstract class PermissionHolder {
invalidateCache();
ImmutableCollection<Node> after = getEnduringNodes().values();
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}
@ -1383,7 +1383,7 @@ public abstract class PermissionHolder {
return false;
}
plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after);
plugin.getEventFactory().handleNodeClear(this, before, after);
return true;
}

View File

@ -170,7 +170,7 @@ public class Track implements Identifiable<String> {
groups.add(group.getName());
List<String> after = ImmutableList.copyOf(groups);
plugin.getApiProvider().getEventFactory().handleTrackAddGroup(this, group.getName(), before, after);
plugin.getEventFactory().handleTrackAddGroup(this, group.getName(), before, after);
return DataMutateResult.SUCCESS;
}
@ -191,7 +191,7 @@ public class Track implements Identifiable<String> {
groups.add(position, group.getName());
List<String> after = ImmutableList.copyOf(groups);
plugin.getApiProvider().getEventFactory().handleTrackAddGroup(this, group.getName(), before, after);
plugin.getEventFactory().handleTrackAddGroup(this, group.getName(), before, after);
return DataMutateResult.SUCCESS;
}
@ -220,7 +220,7 @@ public class Track implements Identifiable<String> {
groups.remove(group);
List<String> after = ImmutableList.copyOf(groups);
plugin.getApiProvider().getEventFactory().handleTrackRemoveGroup(this, group, before, after);
plugin.getEventFactory().handleTrackRemoveGroup(this, group, before, after);
return DataMutateResult.SUCCESS;
}
@ -250,6 +250,6 @@ public class Track implements Identifiable<String> {
public void clearGroups() {
List<String> before = ImmutableList.copyOf(groups);
groups.clear();
plugin.getApiProvider().getEventFactory().handleTrackClear(this, before);
plugin.getEventFactory().handleTrackClear(this, before);
}
}

View File

@ -86,7 +86,7 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
this.cachedData = new UserCachedData(this);
getPlugin().getApiProvider().getEventFactory().handleUserCacheLoad(this, cachedData);
getPlugin().getEventFactory().handleUserCacheLoad(this, cachedData);
}
public User(UUID uuid, String name, LuckPermsPlugin plugin) {
@ -98,7 +98,7 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
this.cachedData = new UserCachedData(this);
getPlugin().getApiProvider().getEventFactory().handleUserCacheLoad(this, cachedData);
getPlugin().getEventFactory().handleUserCacheLoad(this, cachedData);
}
@Override
@ -192,7 +192,7 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
return CompletableFuture.allOf(
cachedData.reloadPermissions(),
cachedData.reloadMeta()
).thenAccept(n -> getPlugin().getApiProvider().getEventFactory().handleUserDataRecalculate(this, cachedData));
).thenAccept(n -> getPlugin().getEventFactory().handleUserDataRecalculate(this, cachedData));
}
/**

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.common.plugin;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.platform.PlatformType;
import me.lucko.luckperms.common.actionlog.LogDispatcher;
import me.lucko.luckperms.common.api.ApiProvider;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.buffers.BufferedRequest;
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
import me.lucko.luckperms.common.calculators.CalculatorFactory;
@ -39,8 +39,8 @@ import me.lucko.luckperms.common.commands.utils.CommandUtils;
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
import me.lucko.luckperms.common.contexts.ContextManager;
import me.lucko.luckperms.common.dependencies.DependencyManager;
import me.lucko.luckperms.common.event.EventFactory;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.logging.Logger;
import me.lucko.luckperms.common.managers.GroupManager;
import me.lucko.luckperms.common.managers.TrackManager;
@ -126,12 +126,19 @@ public interface LuckPermsPlugin {
*/
UuidCache getUuidCache();
/**
* Gets the event factory
*
* @return the event factory
*/
EventFactory getEventFactory();
/**
* Returns the class implementing the LuckPermsAPI on this platform.
*
* @return the api
*/
ApiProvider getApiProvider();
LuckPermsApiProvider getApiProvider();
/**
* Gets the command manager
@ -285,17 +292,6 @@ public interface LuckPermsPlugin {
*/
InputStream getResourceStream(String path);
/**
* Returns a colored string indicating the status of a player
*
* @param uuid The player's uuid
* @return a formatted status string
*/
default Message getPlayerStatus(UUID uuid) {
UUID external = getUuidCache().getExternalUUID(uuid);
return isPlayerOnline(external) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
}
/**
* Gets a player object linked to this User. The returned object must be the same type
* as the instance used in the platforms {@link ContextManager}
@ -398,13 +394,13 @@ public interface LuckPermsPlugin {
}
static void sendStartupBanner(Sender sender, LuckPermsPlugin plugin) {
default void sendStartupBanner(Sender sender) {
sender.sendMessage(CommandUtils.color("&b __ &3 __ ___ __ __ "));
sender.sendMessage(CommandUtils.color("&b | | | / ` |__/ &3|__) |__ |__) |\\/| /__` "));
sender.sendMessage(CommandUtils.color("&b |___ \\__/ \\__, | \\ &3| |___ | \\ | | .__/ "));
sender.sendMessage(CommandUtils.color(" "));
sender.sendMessage(CommandUtils.color("&2 Loading version &bv" + plugin.getVersion() + "&2 on " + plugin.getServerType().getFriendlyName() + " - " + plugin.getServerBrand()));
sender.sendMessage(CommandUtils.color("&8 Running on server version " + plugin.getServerVersion()));
sender.sendMessage(CommandUtils.color("&2 Loading version &bv" + getVersion() + "&2 on " + getServerType().getFriendlyName() + " - " + getServerBrand()));
sender.sendMessage(CommandUtils.color("&8 Running on server version " + getServerVersion()));
sender.sendMessage(CommandUtils.color(" "));
}

View File

@ -159,7 +159,7 @@ public class AbstractStorage implements Storage {
return makeFuture(() -> {
User user = dao.loadUser(uuid, username);
if (user != null) {
plugin.getApiProvider().getEventFactory().handleUserLoad(user);
plugin.getEventFactory().handleUserLoad(user);
}
return user;
});
@ -185,7 +185,7 @@ public class AbstractStorage implements Storage {
return makeFuture(() -> {
Group group = dao.createAndLoadGroup(name);
if (group != null) {
plugin.getApiProvider().getEventFactory().handleGroupCreate(group, cause);
plugin.getEventFactory().handleGroupCreate(group, cause);
}
return group;
});
@ -196,7 +196,7 @@ public class AbstractStorage implements Storage {
return makeFuture(() -> {
Optional<Group> group = dao.loadGroup(name);
if (group.isPresent()) {
plugin.getApiProvider().getEventFactory().handleGroupLoad(group.get());
plugin.getEventFactory().handleGroupLoad(group.get());
}
return group;
});
@ -206,7 +206,7 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Void> loadAllGroups() {
return makeFuture(() -> {
dao.loadAllGroups();
plugin.getApiProvider().getEventFactory().handleGroupLoadAll();
plugin.getEventFactory().handleGroupLoadAll();
});
}
@ -219,7 +219,7 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Void> deleteGroup(Group group, DeletionCause cause) {
return makeFuture(() -> {
dao.deleteGroup(group);
plugin.getApiProvider().getEventFactory().handleGroupDelete(group, cause);
plugin.getEventFactory().handleGroupDelete(group, cause);
});
}
@ -233,7 +233,7 @@ public class AbstractStorage implements Storage {
return makeFuture(() -> {
Track track = dao.createAndLoadTrack(name);
if (track != null) {
plugin.getApiProvider().getEventFactory().handleTrackCreate(track, cause);
plugin.getEventFactory().handleTrackCreate(track, cause);
}
return track;
});
@ -244,7 +244,7 @@ public class AbstractStorage implements Storage {
return makeFuture(() -> {
Optional<Track> track = dao.loadTrack(name);
if (track.isPresent()) {
plugin.getApiProvider().getEventFactory().handleTrackLoad(track.get());
plugin.getEventFactory().handleTrackLoad(track.get());
}
return track;
});
@ -254,7 +254,7 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Void> loadAllTracks() {
return makeFuture(() -> {
dao.loadAllTracks();
plugin.getApiProvider().getEventFactory().handleTrackLoadAll();
plugin.getEventFactory().handleTrackLoadAll();
});
}
@ -267,7 +267,7 @@ public class AbstractStorage implements Storage {
public CompletableFuture<Void> deleteTrack(Track track, DeletionCause cause) {
return makeFuture(() -> {
dao.deleteTrack(track);
plugin.getApiProvider().getEventFactory().handleTrackDelete(track, cause);
plugin.getEventFactory().handleTrackDelete(track, cause);
});
}

View File

@ -25,7 +25,7 @@
package me.lucko.luckperms.common.storage;
import lombok.experimental.UtilityClass;
import lombok.AllArgsConstructor;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
@ -50,10 +50,12 @@ import java.io.File;
import java.util.Map;
import java.util.Set;
@UtilityClass
@AllArgsConstructor
public class StorageFactory {
public static Set<StorageType> getRequiredTypes(LuckPermsPlugin plugin, StorageType defaultMethod) {
private final LuckPermsPlugin plugin;
public Set<StorageType> getRequiredTypes(StorageType defaultMethod) {
if (plugin.getConfiguration().get(ConfigKeys.SPLIT_STORAGE)) {
return plugin.getConfiguration().get(ConfigKeys.SPLIT_STORAGE_OPTIONS).entrySet().stream()
.map(e -> {
@ -77,7 +79,7 @@ public class StorageFactory {
}
}
public static Storage getInstance(LuckPermsPlugin plugin, StorageType defaultMethod) {
public Storage getInstance(StorageType defaultMethod) {
Storage storage;
if (plugin.getConfiguration().get(ConfigKeys.SPLIT_STORAGE)) {
plugin.getLog().info("Loading storage provider... [SPLIT STORAGE]");
@ -94,7 +96,7 @@ public class StorageFactory {
Map<StorageType, AbstractDao> backing = mappedTypes.values().stream()
.distinct()
.collect(ImmutableCollectors.toEnumMap(StorageType.class, e -> e, e -> makeDao(e, plugin)));
.collect(ImmutableCollectors.toEnumMap(StorageType.class, e -> e, this::makeDao));
storage = AbstractStorage.create(plugin, new SplitStorageDao(plugin, backing, mappedTypes));
@ -106,18 +108,18 @@ public class StorageFactory {
}
plugin.getLog().info("Loading storage provider... [" + type.name() + "]");
storage = makeInstance(type, plugin);
storage = makeInstance(type);
}
storage.init();
return storage;
}
private static Storage makeInstance(StorageType type, LuckPermsPlugin plugin) {
return AbstractStorage.create(plugin, makeDao(type, plugin));
private Storage makeInstance(StorageType type) {
return AbstractStorage.create(plugin, makeDao(type));
}
private static AbstractDao makeDao(StorageType method, LuckPermsPlugin plugin) {
private AbstractDao makeDao(StorageType method) {
switch (method) {
case MARIADB:
return new SqlDao(plugin, new MariaDbConnectionFactory(

View File

@ -54,7 +54,7 @@ public class UpdateTask implements Runnable {
*/
@Override
public void run() {
if (plugin.getApiProvider().getEventFactory().handlePreSync(false)) {
if (plugin.getEventFactory().handlePreSync(false)) {
return;
}
@ -76,6 +76,6 @@ public class UpdateTask implements Runnable {
plugin.onPostUpdate();
plugin.getApiProvider().getEventFactory().handlePostSync();
plugin.getEventFactory().handlePostSync();
}
}

View File

@ -51,7 +51,7 @@ public class LoginHelper {
cache.addToCache(u, uuid);
} else {
// No previous data for this player
plugin.getApiProvider().getEventFactory().handleUserFirstLogin(u, username);
plugin.getEventFactory().handleUserFirstLogin(u, username);
cache.addToCache(u, u);
CompletableFuture<Void> future = plugin.getStorage().noBuffer().saveUUIDData(u, username);
if (joinUuidSave) {
@ -61,7 +61,7 @@ public class LoginHelper {
} else {
String name = plugin.getStorage().noBuffer().getName(u).join();
if (name == null) {
plugin.getApiProvider().getEventFactory().handleUserFirstLogin(u, username);
plugin.getEventFactory().handleUserFirstLogin(u, username);
}
// Online mode, no cache needed. This is just for name -> uuid lookup.

View File

@ -33,8 +33,8 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.LuckPermsApi;
import me.lucko.luckperms.api.platform.PlatformType;
import me.lucko.luckperms.common.actionlog.LogDispatcher;
import me.lucko.luckperms.common.api.ApiProvider;
import me.lucko.luckperms.common.api.ApiSingletonUtils;
import me.lucko.luckperms.common.api.ApiRegistrationUtil;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.backup.DummySender;
import me.lucko.luckperms.common.buffers.BufferedRequest;
import me.lucko.luckperms.common.buffers.UpdateTaskBuffer;
@ -49,6 +49,7 @@ import me.lucko.luckperms.common.config.LuckPermsConfiguration;
import me.lucko.luckperms.common.contexts.ContextManager;
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
import me.lucko.luckperms.common.dependencies.DependencyManager;
import me.lucko.luckperms.common.event.EventFactory;
import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.NoopLocaleManager;
import me.lucko.luckperms.common.locale.SimpleLocaleManager;
@ -108,7 +109,9 @@ import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.AbstractCollection;
import java.util.Collections;
@ -145,7 +148,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
@Inject
@ConfigDir(sharedRoot = false)
private Path configDir;
private Path configDirectory;
private Scheduler spongeScheduler = Sponge.getScheduler();
@ -173,7 +176,8 @@ public class LPSpongePlugin implements LuckPermsPlugin {
private FileWatcher fileWatcher = null;
private ExtendedMessagingService messagingService = null;
private UuidCache uuidCache;
private ApiProvider apiProvider;
private LuckPermsApiProvider apiProvider;
private EventFactory eventFactory;
private me.lucko.luckperms.common.logging.Logger log;
private LuckPermsService service;
private LocaleManager localeManager;
@ -197,16 +201,17 @@ public class LPSpongePlugin implements LuckPermsPlugin {
log = new SenderLogger(this, getConsoleSender());
dependencyManager = new DependencyManager(this);
LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this);
sendStartupBanner(getConsoleSender());
verboseHandler = new VerboseHandler(scheduler.async(), getVersion());
permissionVault = new PermissionVault(scheduler.async());
logDispatcher = new LogDispatcher(this);
getLog().info("Loading configuration...");
configuration = new AbstractConfiguration(this, new SpongeConfigAdapter(this));
configuration.init();
configuration = new AbstractConfiguration(this, new SpongeConfigAdapter(this, resolveConfig("luckperms.conf")));
configuration.loadAll();
Set<StorageType> storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2);
StorageFactory storageFactory = new StorageFactory(this);
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
dependencyManager.loadStorageDependencies(storageTypes);
// register events
@ -219,7 +224,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
}
// initialise datastore
storage = StorageFactory.getInstance(this, StorageType.H2);
storage = storageFactory.getInstance(StorageType.H2);
// initialise messaging
messagingService = new SpongeMessagingFactory(this).getInstance();
@ -265,8 +270,12 @@ public class LPSpongePlugin implements LuckPermsPlugin {
}
// register with the LP API
apiProvider = new ApiProvider(this);
ApiSingletonUtils.registerProvider(apiProvider);
apiProvider = new LuckPermsApiProvider(this);
// setup event factory
eventFactory = new EventFactory(this, apiProvider);
ApiRegistrationUtil.registerProvider(apiProvider);
game.getServiceManager().setProvider(this, LuckPermsApi.class, apiProvider);
// schedule update tasks
@ -325,7 +334,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
messagingService.close();
}
ApiSingletonUtils.unregisterProvider();
ApiRegistrationUtil.unregisterProvider();
getLog().info("Shutting down internal scheduler...");
scheduler.shutdown();
@ -343,6 +352,23 @@ public class LPSpongePlugin implements LuckPermsPlugin {
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
}
private Path resolveConfig(String file) {
Path path = configDirectory.resolve(file);
if (!Files.exists(path)) {
try {
Files.createDirectories(configDirectory);
try (InputStream is = getClass().getClassLoader().getResourceAsStream(file)) {
Files.copy(is, path);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return path;
}
@Override
public Optional<ExtendedMessagingService> getMessagingService() {
return Optional.ofNullable(messagingService);
@ -354,15 +380,15 @@ public class LPSpongePlugin implements LuckPermsPlugin {
@Override
public File getDataDirectory() {
File base = configDir.toFile().getParentFile().getParentFile();
File luckPermsDir = new File(base, "luckperms");
luckPermsDir.mkdirs();
return luckPermsDir;
File serverRoot = configDirectory.toFile().getParentFile().getParentFile();
File dataDirectory = new File(serverRoot, "luckperms");
dataDirectory.mkdirs();
return dataDirectory;
}
@Override
public File getConfigDirectory() {
return configDir.toFile();
return configDirectory.toFile();
}
@Override

View File

@ -25,12 +25,11 @@
package me.lucko.luckperms.sponge;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import com.google.common.base.Splitter;
import me.lucko.luckperms.common.config.ConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.AbstractConfigurationAdapter;
import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.SimpleConfigurationNode;
@ -38,48 +37,32 @@ import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RequiredArgsConstructor
public class SpongeConfigAdapter implements ConfigurationAdapter {
@Getter
private final LPSpongePlugin plugin;
public class SpongeConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter {
private final Path path;
private ConfigurationNode root;
private Path makeFile(Path file) throws IOException {
File cfg = file.toFile();
//noinspection ResultOfMethodCallIgnored
cfg.getParentFile().mkdirs();
if (!cfg.exists()) {
try (InputStream is = plugin.getClass().getClassLoader().getResourceAsStream("luckperms.conf")) {
Files.copy(is, cfg.toPath());
}
}
return cfg.toPath();
public SpongeConfigAdapter(LuckPermsPlugin plugin, Path path) {
super(plugin);
this.path = path;
reload();
}
@Override
public void init() {
try {
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder()
.setPath(makeFile(plugin.getConfigDir().resolve("luckperms.conf")))
.build();
public void reload() {
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(path).build();
try {
root = loader.load();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

View File

@ -80,7 +80,7 @@ public class SpongeConnectionListener {
- setting up cached data. */
try {
User user = LoginHelper.loadUser(plugin, p.getUniqueId(), username, false);
plugin.getApiProvider().getEventFactory().handleUserLoginProcess(p.getUniqueId(), username, user);
plugin.getEventFactory().handleUserLoginProcess(p.getUniqueId(), username, user);
} catch (Exception ex) {
plugin.getLog().severe("Exception occured whilst loading data for " + p.getUniqueId() + " - " + p.getName());
ex.printStackTrace();