From 7696910d119cdca1075bd4f5df91fd695fb34281 Mon Sep 17 00:00:00 2001 From: hamdan <94024788+hmdnnrmn@users.noreply.github.com> Date: Tue, 26 May 2026 12:13:02 +0000 Subject: [PATCH 1/2] feat: add postgresql storage support --- build.gradle.kts | 2 +- .../menu/storage/ZStorageManager.java | 26 ++++++++++++++++--- src/main/resources/config.yml | 7 ++--- src/main/resources/plugin.yml | 3 ++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b664e832..c8d119ab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -108,7 +108,7 @@ allprojects { } compileOnly("me.clip:placeholderapi:2.11.6") - implementation("fr.maxlego08.sarah:sarah:1.22") + implementation("fr.maxlego08.sarah:sarah:1.24") implementation("fr.traqueur.currencies:currenciesapi:1.0.13") implementation("com.tcoded:FoliaLib:0.5.1") diff --git a/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java b/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java index 24a8c4f7..93d87675 100644 --- a/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java +++ b/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -67,11 +68,20 @@ public void loadDatabase() { } Logger logger = JULogger.from(this.plugin.getLogger()); + DatabaseType databaseType = this.getDatabaseType(storageType); + if (databaseType == null) { + this.plugin.getLogger().severe("Invalid storage-type: '" + storageType + "'. Valid values: SQLITE, MYSQL, MARIADB, POSTGRESQL, NONE"); + this.isEnable = false; + Bukkit.getPluginManager().disablePlugin(this.plugin); + return; + } + DatabaseConnection databaseConnection; - if (storageType.equalsIgnoreCase("SQLITE")) { - databaseConnection = new SqliteConnection(new DatabaseConfiguration(prefix, user, password, port, host, dataBase, enableDebug, DatabaseType.SQLITE), this.plugin.getDataFolder(), logger); + DatabaseConfiguration databaseConfiguration = new DatabaseConfiguration(prefix, user, password, port, host, dataBase, enableDebug, databaseType); + if (databaseType == DatabaseType.SQLITE) { + databaseConnection = new SqliteConnection(databaseConfiguration, this.plugin.getDataFolder(), logger); } else { - databaseConnection = new HikariDatabaseConnection(new DatabaseConfiguration(prefix, user, password, port, host, dataBase, enableDebug, storageType.equalsIgnoreCase("MYSQL") ? DatabaseType.MYSQL : DatabaseType.MARIADB), logger); + databaseConnection = new HikariDatabaseConnection(databaseConfiguration, logger); } this.requestHelper = new RequestHelper(databaseConnection, logger); @@ -90,6 +100,16 @@ public void loadDatabase() { this.startBatchTask(this.plugin.getConfig().getInt("batch-task", 10)); } + private DatabaseType getDatabaseType(String storageType) { + return switch (storageType.toUpperCase(Locale.ROOT)) { + case "SQLITE" -> DatabaseType.SQLITE; + case "MYSQL" -> DatabaseType.MYSQL; + case "MARIADB" -> DatabaseType.MARIADB; + case "POSTGRESQL" -> DatabaseType.POSTGRESQL; + default -> null; + }; + } + private void startBatchTask(int seconds) { if (seconds <= 0) return; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d1bd45fb..7f284ebc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -34,9 +34,10 @@ skip-update-check: false # SQLITE - For the launch of the plugin only. # MYSQL - RECOMMENDED # MARIADB - RECOMMENDED +# POSTGRESQL - RECOMMENDED # NONE - If you do not need a database, you can disable it. # -# We advise you to use MARIADB or MYSQL, the SQLITE storage is only there to install the plugin and do some tests, not all features are available with SQLITE yet. +# We advise you to use MARIADB, MYSQL, or POSTGRESQL, the SQLITE storage is only there to install the plugin and do some tests, not all features are available with SQLITE yet. # The plugin will work, but some features like sanctions update when launching the plugin will not work. # This will be fixed in future plugin updates storage-type: SQLITE @@ -49,7 +50,7 @@ database-configuration: table-prefix: "zmenu_" # IP Address of the machine the database is hosted on host: 192.168.10.10 - # Port of the database, by default, MYSQL's port is 3306 + # Port of the database, by default, MYSQL and MARIADB use 3306, POSTGRESQL uses 5432 port: 3306 # Database username user: homestead @@ -201,4 +202,4 @@ enable-download-command: false # Time in seconds for clean the OfflinePlayer cache # OfflinePlayer is a variable that represents an offline player -cache-offline-player: 300 \ No newline at end of file +cache-offline-player: 300 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ac3e8483..41409607 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -30,4 +30,5 @@ loadbefore: - SuperiorSkyblock2 libraries: - org.mariadb.jdbc:mariadb-java-client:3.5.6 - - net.kyori:adventure-text-minimessage:4.26.1 \ No newline at end of file + - org.postgresql:postgresql:42.7.3 + - net.kyori:adventure-text-minimessage:4.26.1 From d24f437a573108582bdcce9e2105b24e18c53d6f Mon Sep 17 00:00:00 2001 From: hamdan Date: Sat, 30 May 2026 14:21:54 +0800 Subject: [PATCH 2/2] fix: address review feedback on plugin disable and null storage-type --- src/main/java/fr/maxlego08/menu/ZMenuPlugin.java | 1 + src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/maxlego08/menu/ZMenuPlugin.java b/src/main/java/fr/maxlego08/menu/ZMenuPlugin.java index e8516c43..d6fa1eff 100644 --- a/src/main/java/fr/maxlego08/menu/ZMenuPlugin.java +++ b/src/main/java/fr/maxlego08/menu/ZMenuPlugin.java @@ -159,6 +159,7 @@ public void onEnable() { this.storageManager.loadDatabase(); + if (!this.isEnabled()) return; this.addListener(this.storageManager); this.loadMeta(); diff --git a/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java b/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java index 93d87675..5b971c89 100644 --- a/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java +++ b/src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java @@ -61,7 +61,7 @@ public void loadDatabase() { boolean enableDebug = globalDatabaseConfiguration.isDebug(); String storageType = this.plugin.getConfig().getString("storage-type", "SQLITE"); - if (storageType.equalsIgnoreCase("NONE")) { + if (storageType == null || storageType.equalsIgnoreCase("NONE")) { this.plugin.getLogger().info("You are not using a database."); this.isEnable = false; return;