Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions src/main/java/fr/maxlego08/menu/ZMenuPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void onEnable() {


this.storageManager.loadDatabase();
if (!this.isEnabled()) return;
this.addListener(this.storageManager);

this.loadMeta();
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -60,18 +61,27 @@ 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;
}

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);
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
cache-offline-player: 300
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ loadbefore:
- SuperiorSkyblock2
libraries:
- org.mariadb.jdbc:mariadb-java-client:3.5.6
- net.kyori:adventure-text-minimessage:4.26.1
- org.postgresql:postgresql:42.7.3
- net.kyori:adventure-text-minimessage:4.26.1