Dynamically download H2

This commit is contained in:
HaHaWTH 2024-05-23 17:55:42 +08:00
parent 99c7466b37
commit b2ea5cbef8
3 changed files with 30 additions and 10 deletions

22
pom.xml
View File

@ -279,10 +279,6 @@
</excludes> </excludes>
</artifactSet> </artifactSet>
<relocations> <relocations>
<relocation>
<pattern>org.h2</pattern>
<shadedPattern>fr.xephi.authme.libs.org.h2</shadedPattern>
</relocation>
<relocation> <relocation>
<pattern>org.apache.http</pattern> <pattern>org.apache.http</pattern>
<shadedPattern>fr.xephi.authme.libs.org.apache.http</shadedPattern> <shadedPattern>fr.xephi.authme.libs.org.apache.http</shadedPattern>
@ -341,10 +337,6 @@
<pattern>com.google.gson</pattern> <pattern>com.google.gson</pattern>
<shadedPattern>fr.xephi.authme.libs.com.google.gson</shadedPattern> <shadedPattern>fr.xephi.authme.libs.com.google.gson</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>org.h2</pattern>
<shadedPattern>fr.xephi.authme.libs.org.h2</shadedPattern>
</relocation>
<relocation> <relocation>
<pattern>org.apache.http</pattern> <pattern>org.apache.http</pattern>
<shadedPattern>fr.xephi.authme.libs.org.apache.http</shadedPattern> <shadedPattern>fr.xephi.authme.libs.org.apache.http</shadedPattern>
@ -467,6 +459,10 @@
<pattern>org.apache.commons.validator</pattern> <pattern>org.apache.commons.validator</pattern>
<shadedPattern>fr.xephi.authme.libs.org.apache.commons.validator</shadedPattern> <shadedPattern>fr.xephi.authme.libs.org.apache.commons.validator</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>com.alessiodp.libby</pattern>
<shadedPattern>fr.xephi.authme.libs.com.alessiodp.libby</shadedPattern>
</relocation>
</relocations> </relocations>
<filters> <filters>
@ -727,6 +723,14 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Libby -->
<dependency>
<groupId>com.alessiodp.libby</groupId>
<artifactId>libby-bukkit</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- Database Connection Pool --> <!-- Database Connection Pool -->
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
@ -1149,7 +1153,7 @@
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>2.2.224</version> <version>2.2.224</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -2,6 +2,7 @@ package fr.xephi.authme;
import ch.jalu.injector.Injector; import ch.jalu.injector.Injector;
import ch.jalu.injector.InjectorBuilder; import ch.jalu.injector.InjectorBuilder;
import com.alessiodp.libby.BukkitLibraryManager;
import com.github.Anon8281.universalScheduler.UniversalScheduler; import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler; import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import fr.xephi.authme.api.v3.AuthMeApi; import fr.xephi.authme.api.v3.AuthMeApi;
@ -143,6 +144,11 @@ public class AuthMe extends JavaPlugin {
return scheduler; return scheduler;
} }
/**
* The library manager
*/
public static BukkitLibraryManager libraryManager;
/** /**
* Method called when the server enables the plugin. * Method called when the server enables the plugin.
*/ */
@ -151,6 +157,7 @@ public class AuthMe extends JavaPlugin {
// Load the plugin version data from the plugin description file // Load the plugin version data from the plugin description file
loadPluginInfo(getDescription().getVersion()); loadPluginInfo(getDescription().getVersion());
scheduler = UniversalScheduler.getScheduler(this); scheduler = UniversalScheduler.getScheduler(this);
libraryManager = new BukkitLibraryManager(this);
// Set the Logger instance and log file path // Set the Logger instance and log file path
ConsoleLogger.initialize(getLogger(), new File(getDataFolder(), LOG_FILENAME)); ConsoleLogger.initialize(getLogger(), new File(getDataFolder(), LOG_FILENAME));

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.initialization; package fr.xephi.authme.initialization;
import com.alessiodp.libby.Library;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.CacheDataSource; import fr.xephi.authme.datasource.CacheDataSource;
@ -21,6 +22,8 @@ import javax.inject.Provider;
import java.io.File; import java.io.File;
import java.sql.SQLException; import java.sql.SQLException;
import static fr.xephi.authme.AuthMe.libraryManager;
/** /**
* Creates the AuthMe data source. * Creates the AuthMe data source.
*/ */
@ -78,8 +81,14 @@ public class DataSourceProvider implements Provider<DataSource> {
dataSource = new SQLite(settings, dataFolder); dataSource = new SQLite(settings, dataFolder);
break; break;
case H2: case H2:
Library h2 = Library.builder()
.groupId("com.h2database")
.artifactId("h2")
.version("2.2.224")
.build();
libraryManager.addMavenCentral();
libraryManager.loadLibrary(h2);
dataSource = new H2(settings, dataFolder); dataSource = new H2(settings, dataFolder);
logger.warning("You are using H2 database, which is still in development!\nMake sure to backup and report any issues you encounter on GitHub!");
break; break;
default: default:
throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'"); throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'");