diff --git a/bukkit-legacy/pom.xml b/bukkit-legacy/pom.xml index 30b6dcaac..dca315330 100644 --- a/bukkit-legacy/pom.xml +++ b/bukkit-legacy/pom.xml @@ -47,26 +47,6 @@ - - org.slf4j - me.lucko.luckperms.lib.slf4j - - - com.zaxxer.hikari - me.lucko.luckperms.lib.hikari - - - com.mongodb - me.lucko.luckperms.lib.mongodb - - - org.bson - me.lucko.luckperms.lib.bson - - - org.h2 - me.lucko.luckperms.lib.h2 - com.google.common me.lucko.luckperms.lib.guava @@ -76,16 +56,8 @@ me.lucko.luckperms.lib.gson - redis.clients.jedis - me.lucko.luckperms.lib.jedis.jedis - - - redis.clients.util - me.lucko.luckperms.lib.jedis.util - - - org.apache.commons.pool2 - me.lucko.luckperms.lib.jedis.pool2 + io.github.mkremins.fanciful + me.lucko.luckperms.lib.fanciful diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 629f0039c..9507eab11 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -44,48 +44,11 @@ false - - - org.xerial:* - - io.github.mkremins.fanciful me.lucko.luckperms.lib.fanciful - - org.slf4j - me.lucko.luckperms.lib.slf4j - - - com.zaxxer.hikari - me.lucko.luckperms.lib.hikari - - - com.mongodb - me.lucko.luckperms.lib.mongodb - - - org.bson - me.lucko.luckperms.lib.bson - - - org.h2 - me.lucko.luckperms.lib.h2 - - - redis.clients.jedis - me.lucko.luckperms.lib.jedis.jedis - - - redis.clients.util - me.lucko.luckperms.lib.jedis.util - - - org.apache.commons.pool2 - me.lucko.luckperms.lib.jedis.pool2 - @@ -138,6 +101,13 @@ ${project.version} compile + + + com.zaxxer + HikariCP + 2.5.1 + provided + org.projectlombok diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 686f5f257..c17c8363c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -49,6 +49,7 @@ import me.lucko.luckperms.common.contexts.ServerCalculator; import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.Importer; +import me.lucko.luckperms.common.dependencies.DependencyManager; import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.UserManager; @@ -58,6 +59,7 @@ import me.lucko.luckperms.common.managers.impl.GenericUserManager; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; +import me.lucko.luckperms.common.storage.StorageType; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; @@ -132,6 +134,9 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { getLog().info("Loading configuration..."); configuration = new BukkitConfig(this); + Set storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2); + DependencyManager.loadDependencies(this, storageTypes); + // setup the Bukkit defaults hook defaultsProvider = new DefaultsProvider(); childPermissionProvider = new ChildPermissionProvider(); @@ -166,7 +171,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { pm.registerEvents(new BukkitListener(this), this); // initialise datastore - storage = StorageFactory.getInstance(this, "h2"); + storage = StorageFactory.getInstance(this, StorageType.H2); // initialise redis if (getConfiguration().isRedisEnabled()) { diff --git a/bungee/pom.xml b/bungee/pom.xml index 79d65ec13..51e901ec9 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -49,42 +49,6 @@ io.github.mkremins.fanciful me.lucko.luckperms.lib.fanciful - - org.slf4j - me.lucko.luckperms.lib.slf4j - - - com.zaxxer.hikari - me.lucko.luckperms.lib.hikari - - - com.mongodb - me.lucko.luckperms.lib.mongodb - - - org.bson - me.lucko.luckperms.lib.bson - - - org.h2 - me.lucko.luckperms.lib.h2 - - - org.sqlite - me.lucko.luckperms.lib.sqlite - - - redis.clients.jedis - me.lucko.luckperms.lib.jedis.jedis - - - redis.clients.util - me.lucko.luckperms.lib.jedis.util - - - org.apache.commons.pool2 - me.lucko.luckperms.lib.jedis.pool2 - @@ -130,6 +94,13 @@ ${project.version} compile + + + org.slf4j + slf4j-simple + 1.7.9 + provided + org.projectlombok diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index 54256e2c9..abef85681 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -42,6 +42,7 @@ import me.lucko.luckperms.common.contexts.ServerCalculator; import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.Importer; +import me.lucko.luckperms.common.dependencies.DependencyManager; import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.UserManager; @@ -51,6 +52,7 @@ import me.lucko.luckperms.common.managers.impl.GenericUserManager; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; +import me.lucko.luckperms.common.storage.StorageType; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; @@ -108,11 +110,14 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { getLog().info("Loading configuration..."); configuration = new BungeeConfig(this); + Set storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2); + DependencyManager.loadDependencies(this, storageTypes); + // register events getProxy().getPluginManager().registerListener(this, new BungeeListener(this)); // initialise datastore - storage = StorageFactory.getInstance(this, "h2"); + storage = StorageFactory.getInstance(this, StorageType.H2); // initialise redis if (getConfiguration().isRedisEnabled()) { diff --git a/common/pom.xml b/common/pom.xml index 720c2d10c..695c5eaba 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -30,7 +30,7 @@ me.lucko.luckperms luckperms-api ${project.version} - compile + provided @@ -39,47 +39,54 @@ 1.1.0 compile + + + mysql + mysql-connector-java + 5.1.40 + provided + com.zaxxer HikariCP 2.5.1 - compile + provided redis.clients jedis 2.8.1 - compile + provided org.xerial sqlite-jdbc 3.8.11.2 - compile + provided com.h2database h2 1.4.192 - compile + provided org.mongodb mongo-java-driver 3.3.0 - compile + provided org.slf4j slf4j-simple 1.7.9 - compile + provided diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java new file mode 100644 index 000000000..f902fac5f --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.dependencies; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum Dependency { + + MYSQL_DRIVER("https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar", "5.1.6", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"), + H2_DRIVER("https://repo1.maven.org/maven2/com/h2database/h2/1.4.193/h2-1.4.193.jar", "1.4.193", "org.h2.Driver"), + SQLITE_DRIVER("https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.15.1/sqlite-jdbc-3.15.1.jar", "3.15.1", "org.sqlite.JDBC"), + HIKARI("https://repo1.maven.org/maven2/com/zaxxer/HikariCP/2.5.1/HikariCP-2.5.1.jar", "2.5.1", "com.zaxxer.hikari.HikariDataSource"), + SLF4J_SIMPLE("https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.9/slf4j-simple-1.7.9.jar", "1.7.9", "org.slf4j.impl.SimpleLoggerFactory"), + SLF4J_API("https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.9/slf4j-api-1.7.9.jar", "1.7.9", "org.slf4j.helpers.BasicMarkerFactory"), + MONGODB_DRIVER("https://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.4.1/mongo-java-driver-3.4.1.jar", "3.4.1", "com.mongodb.Mongo"), + JEDIS("https://repo1.maven.org/maven2/redis/clients/jedis/2.9.0/jedis-2.9.0.jar", "2.9.0", "redis.clients.jedis.Jedis"), + APACHE_COMMONS_POOL("https://repo1.maven.org/maven2/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar", "2.4.1", "org.apache.commons.pool2.PoolUtils"); + + private final String url; + private final String version; + private final String testClass; + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java new file mode 100644 index 000000000..067ef19ec --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.dependencies; + +import lombok.experimental.UtilityClass; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +import me.lucko.luckperms.api.PlatformType; +import me.lucko.luckperms.common.LuckPermsPlugin; +import me.lucko.luckperms.common.storage.StorageType; + +import java.io.File; +import java.io.InputStream; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@UtilityClass +public class DependencyManager { + private static Method ADD_URL_METHOD; + static { + try { + ADD_URL_METHOD = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); + ADD_URL_METHOD.setAccessible(true); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + + private static final Map> STORAGE_DEPENDENCIES = ImmutableMap.>builder() + .put(StorageType.JSON, ImmutableList.of()) + .put(StorageType.YAML, ImmutableList.of()) + .put(StorageType.MONGODB, ImmutableList.of(Dependency.MONGODB_DRIVER)) + .put(StorageType.MYSQL, ImmutableList.of(Dependency.MYSQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI)) + .put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER)) + .put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER)) + .build(); + + public static void loadDependencies(LuckPermsPlugin plugin, Set storageTypes) { + plugin.getLog().info("Loading dependencies..."); + + List dependencies = new ArrayList<>(); + for (StorageType storageType : storageTypes) { + dependencies.addAll(STORAGE_DEPENDENCIES.get(storageType)); + } + + if (plugin.getConfiguration().isRedisEnabled()) { + dependencies.add(Dependency.APACHE_COMMONS_POOL); + dependencies.add(Dependency.JEDIS); + } + + plugin.getLog().info("Identified the following dependencies: " + dependencies.toString()); + + File data = new File(plugin.getDataFolder(), "lib"); + data.mkdirs(); + + // Download files. + List> toLoad = new ArrayList<>(); + for (Dependency dependency : dependencies) { + try { + toLoad.add(Maps.immutableEntry(dependency, downloadDependency(plugin, data, dependency))); + } catch (Throwable e) { + plugin.getLog().severe("Exception whilst downloading dependency " + dependency.name()); + e.printStackTrace(); + } + } + + // Load classes. + for (Map.Entry e : toLoad) { + try { + loadJar(plugin, e.getValue(), e.getKey().getTestClass()); + } catch (Throwable e1) { + plugin.getLog().severe("Failed to load jar for dependency " + e.getKey().name()); + e1.printStackTrace(); + } + } + } + + private static File downloadDependency(LuckPermsPlugin plugin, File libDir, Dependency dependency) throws Exception { + String name = dependency.name().toLowerCase() + "-" + dependency.getVersion() + ".jar"; + + URL url = new URL(dependency.getUrl()); + File file = new File(libDir, name); + if (file.exists()) { + return file; + } + + plugin.getLog().info("Dependency '" + name + "' could not be found. Attempting to download."); + try (InputStream in = url.openStream()) { + Files.copy(in, file.toPath()); + } + + if (!file.exists()) { + throw new IllegalStateException("File not present. - " + file.toString()); + } else { + plugin.getLog().info("Dependency '" + name + "' successfully downloaded."); + return file; + } + } + + private static void loadJar(LuckPermsPlugin plugin, File file, String baseClass) throws Exception { + URLClassLoader classLoader = (URLClassLoader) plugin.getClass().getClassLoader(); + + if (plugin.getType() != PlatformType.SPONGE) { + classLoader = (URLClassLoader) classLoader.getParent(); + } + + ADD_URL_METHOD.invoke(classLoader, file.toURI().toURL()); + classLoader.loadClass(baseClass).newInstance(); // Load a test class + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java index d59efcbad..50629d80f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java @@ -34,6 +34,7 @@ import me.lucko.luckperms.common.storage.backing.MongoDBBacking; import me.lucko.luckperms.common.storage.backing.MySQLBacking; import me.lucko.luckperms.common.storage.backing.SQLiteBacking; import me.lucko.luckperms.common.storage.backing.YAMLBacking; +import me.lucko.luckperms.common.utils.ImmutableCollectors; import java.io.File; import java.util.HashMap; @@ -43,67 +44,89 @@ import java.util.Set; @UtilityClass public class StorageFactory { - private static final Set TYPES = ImmutableSet.of("json", "yaml", "flatfile", "mongodb", "mysql", "sqlite", "h2"); - - public static Storage getInstance(LuckPermsPlugin plugin, String defaultMethod) { - Storage storage; + public static Set getRequiredTypes(LuckPermsPlugin plugin, StorageType defaultMethod) { plugin.getLog().info("Detecting storage method..."); if (plugin.getConfiguration().isSplitStorage()) { - plugin.getLog().info("Using split storage."); - - Map types = plugin.getConfiguration().getSplitStorageOptions(); + plugin.getLog().info("Loading split storage options."); + Map types = new HashMap<>(plugin.getConfiguration().getSplitStorageOptions()); types.entrySet().stream() - .filter(e -> !TYPES.contains(e.getValue().toLowerCase())) + .filter(e -> StorageType.parse(e.getValue()) == null) .forEach(e -> { plugin.getLog().severe("Storage method for " + e.getKey() + " - " + e.getValue() + " not recognised. " + "Using the default instead."); - e.setValue(defaultMethod); + e.setValue(defaultMethod.getIdentifiers().get(0)); }); Set neededTypes = new HashSet<>(); neededTypes.addAll(types.values()); + return neededTypes.stream().map(StorageType::parse).collect(ImmutableCollectors.toImmutableSet()); + } else { + String method = plugin.getConfiguration().getStorageMethod(); + StorageType type = StorageType.parse(method); + if (type == null) { + plugin.getLog().severe("Storage method '" + method + "' not recognised. Using the default instead."); + type = defaultMethod; + } + return ImmutableSet.of(type); + } + } + + public static Storage getInstance(LuckPermsPlugin plugin, StorageType defaultMethod) { + Storage storage; + + plugin.getLog().info("Initializing storage backings..."); + if (plugin.getConfiguration().isSplitStorage()) { + plugin.getLog().info("Using split storage."); + + Map types = new HashMap<>(plugin.getConfiguration().getSplitStorageOptions()); + types.entrySet().stream() + .filter(e -> StorageType.parse(e.getValue()) == null) + .forEach(e -> e.setValue(defaultMethod.getIdentifiers().get(0))); + + Set neededTypes = new HashSet<>(); + neededTypes.addAll(types.values()); + Map backing = new HashMap<>(); for (String type : neededTypes) { - backing.put(type, backingFromString(type, plugin)); + backing.put(type, makeBacking(StorageType.parse(type), plugin)); } storage = AbstractStorage.wrap(plugin, new SplitBacking(plugin, backing, types)); } else { - String storageMethod = plugin.getConfiguration().getStorageMethod().toLowerCase(); - if (!TYPES.contains(storageMethod)) { - plugin.getLog().severe("Storage method '" + storageMethod + "' not recognised. Using the default instead."); - storageMethod = defaultMethod; + String method = plugin.getConfiguration().getStorageMethod().toLowerCase(); + StorageType type = StorageType.parse(method); + if (type == null) { + type = defaultMethod; } - storage = fromString(storageMethod, plugin); - plugin.getLog().info("Using " + storage.getName() + " as storage method."); + storage = makeInstance(type, plugin); } - plugin.getLog().info("Initialising datastore..."); + plugin.getLog().info("Initialising storage provider..."); storage.init(); return storage; } - private static Storage fromString(String storageMethod, LuckPermsPlugin plugin) { - return AbstractStorage.wrap(plugin, backingFromString(storageMethod, plugin)); + private static Storage makeInstance(StorageType type, LuckPermsPlugin plugin) { + return AbstractStorage.wrap(plugin, makeBacking(type, plugin)); } - private static AbstractBacking backingFromString(String method, LuckPermsPlugin plugin) { + private static AbstractBacking makeBacking(StorageType method, LuckPermsPlugin plugin) { switch (method) { - case "mysql": + case MYSQL: return new MySQLBacking(plugin, plugin.getConfiguration().getDatabaseValues()); - case "sqlite": + case SQLITE: return new SQLiteBacking(plugin, new File(plugin.getDataFolder(), "luckperms.sqlite")); - case "h2": + case H2: return new H2Backing(plugin, new File(plugin.getDataFolder(), "luckperms.db")); - case "mongodb": + case MONGODB: return new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues()); - case "yaml": + case YAML: return new YAMLBacking(plugin, plugin.getDataFolder()); default: return new JSONBacking(plugin, plugin.getDataFolder()); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageType.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageType.java new file mode 100644 index 000000000..7249d0682 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageType.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.storage; + +import lombok.Getter; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +public enum StorageType { + + JSON("json", "flatfile"), + YAML("yaml", "yml"), + MONGODB("mongodb"), + MYSQL("mysql"), + SQLITE("sqlite"), + H2("h2"); + + @Getter + private final List identifiers; + + StorageType(String... identifiers) { + this.identifiers = ImmutableList.copyOf(identifiers); + } + + public static StorageType parse(String name) { + for (StorageType t : values()) { + for (String id : t.getIdentifiers()) { + if (id.equalsIgnoreCase(name)) { + return t; + } + } + } + return null; + } + +} diff --git a/sponge/pom.xml b/sponge/pom.xml index d9fa87f95..f04d63f69 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -56,34 +56,6 @@ io.github.mkremins.fanciful me.lucko.luckperms.lib.fanciful - - com.zaxxer.hikari - me.lucko.luckperms.lib.hikari - - - com.mongodb - me.lucko.luckperms.lib.mongodb - - - org.bson - me.lucko.luckperms.lib.bson - - - com.mysql - me.lucko.luckperms.lib.mysql - - - redis.clients.jedis - me.lucko.luckperms.lib.jedis.jedis - - - redis.clients.util - me.lucko.luckperms.lib.jedis.util - - - org.apache.commons.pool2 - me.lucko.luckperms.lib.jedis.pool2 - @@ -142,13 +114,6 @@ ${project.version} compile - - - mysql - mysql-connector-java - 5.1.40 - compile - org.projectlombok diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index 6d1f5369d..ba53fdefc 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -43,11 +43,13 @@ import me.lucko.luckperms.common.contexts.ServerCalculator; import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.Importer; +import me.lucko.luckperms.common.dependencies.DependencyManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.impl.GenericTrackManager; import me.lucko.luckperms.common.messaging.RedisMessaging; import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; +import me.lucko.luckperms.common.storage.StorageType; import me.lucko.luckperms.common.tasks.CacheHousekeepingTask; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; @@ -163,11 +165,14 @@ public class LPSpongePlugin implements LuckPermsPlugin { getLog().info("Loading configuration..."); configuration = new SpongeConfig(this); + Set storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2); + DependencyManager.loadDependencies(this, storageTypes); + // register events game.getEventManager().registerListeners(this, new SpongeListener(this)); // initialise datastore - storage = StorageFactory.getInstance(this, "h2"); + storage = StorageFactory.getInstance(this, StorageType.H2); // initialise redis if (getConfiguration().isRedisEnabled()) {