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>
</artifactSet>
<relocations>
<relocation>
<pattern>org.h2</pattern>
<shadedPattern>fr.xephi.authme.libs.org.h2</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>fr.xephi.authme.libs.org.apache.http</shadedPattern>
@ -341,10 +337,6 @@
<pattern>com.google.gson</pattern>
<shadedPattern>fr.xephi.authme.libs.com.google.gson</shadedPattern>
</relocation>
<relocation>
<pattern>org.h2</pattern>
<shadedPattern>fr.xephi.authme.libs.org.h2</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>fr.xephi.authme.libs.org.apache.http</shadedPattern>
@ -467,6 +459,10 @@
<pattern>org.apache.commons.validator</pattern>
<shadedPattern>fr.xephi.authme.libs.org.apache.commons.validator</shadedPattern>
</relocation>
<relocation>
<pattern>com.alessiodp.libby</pattern>
<shadedPattern>fr.xephi.authme.libs.com.alessiodp.libby</shadedPattern>
</relocation>
</relocations>
<filters>
@ -727,6 +723,14 @@
<scope>provided</scope>
</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 -->
<dependency>
<groupId>com.zaxxer</groupId>
@ -1149,7 +1153,7 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -2,6 +2,7 @@ package fr.xephi.authme;
import ch.jalu.injector.Injector;
import ch.jalu.injector.InjectorBuilder;
import com.alessiodp.libby.BukkitLibraryManager;
import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import fr.xephi.authme.api.v3.AuthMeApi;
@ -143,6 +144,11 @@ public class AuthMe extends JavaPlugin {
return scheduler;
}
/**
* The library manager
*/
public static BukkitLibraryManager libraryManager;
/**
* 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
loadPluginInfo(getDescription().getVersion());
scheduler = UniversalScheduler.getScheduler(this);
libraryManager = new BukkitLibraryManager(this);
// Set the Logger instance and log file path
ConsoleLogger.initialize(getLogger(), new File(getDataFolder(), LOG_FILENAME));

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.initialization;
import com.alessiodp.libby.Library;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.CacheDataSource;
@ -21,6 +22,8 @@ import javax.inject.Provider;
import java.io.File;
import java.sql.SQLException;
import static fr.xephi.authme.AuthMe.libraryManager;
/**
* Creates the AuthMe data source.
*/
@ -78,8 +81,14 @@ public class DataSourceProvider implements Provider<DataSource> {
dataSource = new SQLite(settings, dataFolder);
break;
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);
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;
default:
throw new UnsupportedOperationException("Unknown data source type '" + dataSourceType + "'");