Adjust SQLite initialization to use jdbc properties, change runtime library downloading to use libby

This commit is contained in:
William committed 2022-06-08 23:20:19 +01:00
1 parent 8a7bb11c10
commit 2112b0f5e0
10 files changed
+68 -28

No files matched your search

+3
View File
@@ -9,6 +9,8 @@ version "$ext.plugin_version+${versionMetadata()}"
ext {
set 'version', version.toString()
set 'jedis_version', jedis_version.toString()
set 'sqlite_driver_version', sqlite_driver_version.toString()
}
import org.apache.tools.ant.filters.ReplaceTokens
@@ -27,6 +29,7 @@ allprojects {
mavenCentral()
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url 'https://repo.minebench.de/' }
maven { url 'https://repo.alessiodp.com/releases/' }
maven { url 'https://jitpack.io' }
}
+8 -7
View File
@@ -1,14 +1,14 @@
dependencies {
implementation project(path: ':common')
implementation 'commons-io:commons-io:2.11.0'
implementation 'de.themoep:minedown:1.7.1-SNAPSHOT'
implementation 'dev.dejvokep:boosted-yaml:1.2'
implementation 'io.papermc:paperlib:1.0.7'
implementation 'redis.clients:jedis:4.2.3'
implementation 'net.byteflux:libby-bukkit:1.1.5'
compileOnly 'redis.clients:jedis:' + jedis_version
compileOnly 'commons-io:commons-io:2.11.0'
compileOnly 'de.themoep:minedown:1.7.1-SNAPSHOT'
compileOnly 'dev.dejvokep:boosted-yaml:1.2'
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'org.jetbrains:annotations:23.0.0'
}
shadowJar {
@@ -19,7 +19,8 @@ shadowJar {
relocate 'org.intellij', 'net.william278.huskhomes.libraries'
relocate 'com.zaxxer', 'net.william278.huskhomes.libraries'
relocate 'org.slf4j', 'net.william278.huskhomes.libraries.slf4j'
relocate 'org.xerial', 'net.william278.huskhomes.libraries'
relocate 'com.google', 'net.william278.huskhomes.libraries'
relocate 'net.byteflux.libby', 'net.william278.huskhomes.libraries.libby'
relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib'
relocate 'com.google.code', 'net.william278.huskhomes.libraries'
}
@@ -6,6 +6,8 @@ import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import net.byteflux.libby.BukkitLibraryManager;
import net.byteflux.libby.Library;
import net.william278.huskhomes.cache.Cache;
import net.william278.huskhomes.command.*;
import net.william278.huskhomes.config.Locales;
@@ -37,6 +39,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -89,7 +92,19 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
@Override
public void onLoad() {
// Set the instance
instance = this;
// Load runtime libraries
getLogger().log(Level.INFO, "Loading runtime libraries...");
final BukkitLibraryManager libraryManager = new BukkitLibraryManager(this);
final Library[] libraries = new Library[]{
Library.builder().groupId("redis{}clients").artifactId("jedis").version("4.2.3").id("jedis").build(),
Library.builder().groupId("org{}xerial").artifactId("sqlite-jdbc").version("3.36.0.3").id("sqlite-jdbc").build()
}; // todo fetch these versions from gradle properties the proper way
libraryManager.addMavenCentral();
Arrays.stream(libraries).forEach(libraryManager::loadLibrary);
getLogger().log(Level.INFO, "Successfully loaded runtime libraries.");
}
@Override
@@ -103,6 +118,7 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
// Initialize the network messenger
if (getSettings().getBooleanValue(Settings.ConfigOption.ENABLE_PROXY_MODE)) {
getLogger().log(Level.INFO, "Initializing the network messenger...");
networkMessenger = switch (settings.getStringValue(Settings.ConfigOption.MESSENGER_TYPE).toUpperCase()) {
case "PLUGIN_MESSAGE", "PLUGINMESSAGE" -> new PluginMessenger();
case "REDIS", "JEDIS" -> new RedisMessenger();
@@ -114,10 +130,13 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
return;
}
networkMessenger.initialize(this);
getLogger().log(Level.INFO, "Successfully initialized the network messenger.");
}
// Initialize the database
database = switch (settings.getStringValue(Settings.ConfigOption.DATA_STORAGE_TYPE).toUpperCase()) {
getLogger().log(Level.INFO, "Initializing database...");
final String databaseType = settings.getStringValue(Settings.ConfigOption.DATA_STORAGE_TYPE);
database = switch (databaseType.toUpperCase()) {
case "MYSQL" -> new MySqlDatabase(settings, logger, resourceReader);
case "SQLITE" -> new SqLiteDatabase(settings, logger, resourceReader);
default -> null;
@@ -128,9 +147,15 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
return;
}
database.initialize().thenRun(() -> {
getLogger().log(Level.INFO, "Successfully initialized the " + databaseType + " database.");
// Initialize the cache
getLogger().log(Level.INFO, "Initializing the system cache...");
cache = new Cache();
cache.initialize(database);
getLogger().log(Level.INFO, "Successfully initialized the system cache.");
}).thenRun(() -> {
// Prepare the teleport manager
this.teleportManager = new BukkitTeleportManager(this);
@@ -139,15 +164,18 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
this.savedPositionManager = new SavedPositionManager(database, cache);
// Register commands - todo add all here
getLogger().log(Level.INFO, "Registering commands...");
final CommandBase[] commands = new CommandBase[]{
new HomeCommand(this), new SetHomeCommand(this),
new HomeListCommand(this), new BackCommand(this)};
for (CommandBase commandBase : commands) {
final PluginCommand pluginCommand = getCommand(commandBase.command);
if (pluginCommand != null) {
getLogger().log(Level.INFO, "Registered /" + commandBase.command);
new BukkitCommand(commandBase, this).register(pluginCommand);
}
}
getLogger().log(Level.INFO, "Successfully registered " + commands.length + " commands.");
// Register listener
getServer().getPluginManager().registerEvents(new BukkitEventProcessor(this), this);
@@ -224,6 +252,7 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
// Load from the plugin config
public void loadConfigData() {
try {
getLogger().log(Level.INFO, "Loading configuration data...");
settings = Settings.load(YamlDocument.create(new File(getDataFolder(), "config.yml"),
Objects.requireNonNull(resourceReader.getResource("config.yml")),
GeneralSettings.builder().setUseDefaults(false).build(),
@@ -234,6 +263,7 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
"messages-" + settings.getStringValue(Settings.ConfigOption.LANGUAGE) + ".yml"),
Objects.requireNonNull(resourceReader.getResource(
"languages/" + settings.getStringValue(Settings.ConfigOption.LANGUAGE) + ".yml"))));
getLogger().log(Level.INFO, "Successfully loaded configuration data.");
} catch (IOException | NullPointerException e) {
getLoggingAdapter().log(Level.SEVERE, "Failed to load data from the config", e);
}
@@ -145,7 +145,7 @@ public class PluginMessenger extends NetworkMessenger implements PluginMessageLi
@Override
@SuppressWarnings("UnstableApiUsage")
public void onPluginMessageReceived(@NotNull String channel, @NotNull org.bukkit.entity.Player player,
byte @NotNull [] messageBytes) {
@NotNull byte[] messageBytes) {
if (!channel.equals(BUNGEE_PLUGIN_CHANNEL_NAME)) {
return;
}
@@ -139,7 +139,7 @@ public class BukkitPlayer implements Player {
/**
* Send a Bukkit plugin message
*/
public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, byte @NotNull [] message) {
public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, @NotNull byte[] message) {
bukkitPlayer.sendPluginMessage(source, channel, message);
}
}
+8 -10
View File
@@ -1,12 +1,13 @@
dependencies {
compileOnly 'commons-io:commons-io:2.11.0'
compileOnly 'dev.dejvokep:boosted-yaml:1.2'
compileOnly 'de.themoep:minedown:1.7.1-SNAPSHOT'
compileOnly 'redis.clients:jedis:4.2.3'
implementation 'commons-io:commons-io:2.11.0'
implementation 'dev.dejvokep:boosted-yaml:1.2'
implementation 'de.themoep:minedown:1.7.1-SNAPSHOT'
implementation 'com.zaxxer:HikariCP:5.0.1'
implementation 'org.xerial:sqlite-jdbc:3.36.0.3'
implementation 'com.google.code.gson:gson:2.9.0'
compileOnly 'redis.clients:jedis:' + jedis_version
compileOnly 'org.xerial:sqlite-jdbc:' + sqlite_driver_version
compileOnly 'org.jetbrains:annotations:23.0.0'
}
shadowJar {
@@ -17,8 +18,5 @@ shadowJar {
relocate 'org.intellij', 'net.william278.huskhomes.libraries'
relocate 'com.zaxxer', 'net.william278.huskhomes.libraries'
relocate 'org.slf4j', 'net.william278.huskhomes.libraries.slf4j'
relocate 'org.xerial', 'net.william278.huskhomes.libraries'
relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib'
relocate 'com.google.code', 'net.william278.huskhomes.libraries'
relocate 'redis.clients', 'net.william278.huskhomes.libraries.jedis'
relocate 'com.google', 'net.william278.huskhomes.libraries'
}
@@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
/**
* A cache used to hold persistently used data
@@ -10,6 +10,7 @@ import net.william278.huskhomes.util.Logger;
import net.william278.huskhomes.util.ResourceReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.sqlite.SQLiteConfig;
import java.io.File;
import java.io.IOException;
@@ -66,11 +67,20 @@ public class SqLiteDatabase extends Database {
}
// Establish the connection using the JDBC SQLite driver
connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath());
Class.forName("org.sqlite.JDBC");
SQLiteConfig config = new SQLiteConfig();
config.enforceForeignKeys(true);
config.setEncoding(SQLiteConfig.Encoding.UTF8);
config.setSynchronous(SQLiteConfig.SynchronousMode.FULL);
connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath(), config.toProperties());
} catch (IOException e) {
getLogger().log(Level.SEVERE, "An exception occurred creating the database file", e);
} catch (SQLException e) {
getLogger().log(Level.SEVERE, "An SQL exception occurred initializing the SQLite database", e);
} catch (ClassNotFoundException e) {
getLogger().log(Level.SEVERE, "Failed to load the necessary SQLite driver", e);
}
}
@@ -1,9 +1,3 @@
/* Ensure data gets correctly encoded in UTF-8 */
PRAGMA encoding = 'UTF-8';
/* Ensure foreign key constraints are enforced */
PRAGMA foreign_keys = ON;
/* Create the positions table if it does not exist */
CREATE TABLE IF NOT EXISTS `%positions_table%`
(
+4 -1
View File
@@ -4,4 +4,7 @@ org.gradle.daemon=true
javaVersion=16
plugin_version=3.0
plugin_archive=huskhomes
plugin_archive=huskhomes
jedis_version=4.2.3
sqlite_driver_version=3.36.0.3