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 API/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.5-R0.1-SNAPSHOT")
compileOnly(files("../libs/zMenu-1.1.1.2.jar"))

implementation("fr.maxlego08.sarah:sarah:1.23")
implementation("fr.maxlego08.sarah:sarah:1.24")
implementation("com.tcoded:FoliaLib:0.5.1")
implementation("fr.mrmicky:fastboard:2.1.5")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum StorageType {
JSON,
MYSQL,
MARIADB,
POSTGRESQL,
SQLITE,
HIKARICP,

Expand Down
2 changes: 2 additions & 0 deletions DiscordBot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {
implementation("org.yaml:snakeyaml:2.3")
implementation("net.dv8tion:JDA:5.2.0")
implementation("mysql:mysql-connector-java:8.0.33")
implementation("org.mariadb.jdbc:mariadb-java-client:3.5.6")
implementation("org.postgresql:postgresql:42.7.3")
implementation(project(":API"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
import fr.maxlego08.sarah.DatabaseConfiguration;
import fr.maxlego08.sarah.database.DatabaseType;

import java.util.Locale;

public record DiscordDatabaseConfiguration(String tablePrefix, String user, String password, int port, String host,
String database, boolean debug) {
String database, boolean debug, String type) {

public DatabaseConfiguration toDatabaseConfiguration() {
return new DatabaseConfiguration(tablePrefix, user, password, port, host, database, debug, DatabaseType.MYSQL);
return new DatabaseConfiguration(tablePrefix, user, password, port, host, database, debug, getDatabaseType());
}

private DatabaseType getDatabaseType() {
String value = type == null || type.isBlank() ? "MYSQL" : type;
return switch (value.toUpperCase(Locale.ROOT)) {
case "MARIADB" -> DatabaseType.MARIADB;
case "POSTGRESQL" -> DatabaseType.POSTGRESQL;
default -> DatabaseType.MYSQL;
};
}
}
6 changes: 4 additions & 2 deletions DiscordBot/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ bot-token: "DISCORD-TOKEN"
guild-id: 511516467615760405

database-configuration:
# Database type. Valid values: MYSQL, MARIADB, POSTGRESQL
type: MYSQL
# The prefix that will be applied to all tables, if you have several plugins with the same database you must have one.
# It is advisable not to change this value
tablePrefix: "zessentials_"
# 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 @@ -64,4 +66,4 @@ link:
# author:
# name: "Author Name"
# url: "https://authorwebsite.net" # Optional
# iconUrl: "https://groupez.dev/storage/images/users/0/0/0/1.png"
# iconUrl: "https://groupez.dev/storage/images/users/0/0/0/1.png"
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ allprojects {
// compileOnly("fr.maxlego08.menu:zmenu-api:1.1.0.0")
compileOnly(files("libs/zMenu-1.1.1.2.jar"))

compileOnly("fr.maxlego08.sarah:sarah:1.23")
compileOnly("fr.maxlego08.sarah:sarah:1.24")
compileOnly("com.tcoded:FoliaLib:0.5.1")
compileOnly("fr.mrmicky:fastboard:2.1.5")
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/fr/maxlego08/essentials/MainConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ public void load() {
configuration.getString("database-configuration.tablePrefix", configuration.getString("database-configuration.table-prefix")),
configuration.getString("database-configuration.user"),
configuration.getString("database-configuration.password"),
configuration.getInt("database-configuration.port", 3306),
configuration.getInt("database-configuration.port", this.storageType == StorageType.POSTGRESQL ? 5432 : 3306),
configuration.getString("database-configuration.host"),
configuration.getString("database-configuration.database"),
configuration.getBoolean("database-configuration.debug"),
DatabaseType.MYSQL
getDatabaseType()
);

final ConfigurationSection nearDirSection = configuration.getConfigurationSection("near-direction-replacements");
Expand Down Expand Up @@ -184,6 +184,15 @@ public void load() {
}
}

private DatabaseType getDatabaseType() {
return switch (this.storageType) {
case SQLITE -> DatabaseType.SQLITE;
case MARIADB -> DatabaseType.MARIADB;
case POSTGRESQL -> DatabaseType.POSTGRESQL;
default -> DatabaseType.MYSQL;
};
}

private void loadReplacePlaceholders() {

YamlConfiguration configuration = (YamlConfiguration) this.plugin.getConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ZStorageManager(EssentialsPlugin plugin) {
this.plugin = plugin;
StorageType storageType = plugin.getConfiguration().getStorageType();
this.iStorage = switch (storageType) {
case HIKARICP, SQLITE, MYSQL, MARIADB -> new SqlStorage(plugin, storageType);
case HIKARICP, SQLITE, MYSQL, MARIADB, POSTGRESQL -> new SqlStorage(plugin, storageType);
default -> new JsonStorage(plugin);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import fr.maxlego08.sarah.DatabaseConnection;
import fr.maxlego08.sarah.conditions.JoinCondition;
import fr.maxlego08.sarah.database.DatabaseType;
import fr.maxlego08.sarah.dialect.SqlDialect;
import fr.maxlego08.sarah.dialect.SqlDialects;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -55,7 +59,8 @@ public void upsert(User user) {
* We will execute an UPDATE query with a LEFT JOIN
*/
public void clearExpiredSanctions() {
if (this.connection.getDatabaseConfiguration().getDatabaseType() == DatabaseType.SQLITE) {
DatabaseType databaseType = this.connection.getDatabaseConfiguration().getDatabaseType();
if (databaseType == DatabaseType.SQLITE) {

// TODO - Update Sarah SQLITE for left join
plugin.getLogger().warning("Attention, SQLITE does not allow to execute all sql queries, the query that allows to delete inactive sanctions is currently not working.");
Expand All @@ -73,6 +78,9 @@ public void clearExpiredSanctions() {
});
});*/

} else if (databaseType == DatabaseType.POSTGRESQL) {
clearExpiredSanctionsWithSubQuery("ban_sanction_id");
clearExpiredSanctionsWithSubQuery("mute_sanction_id");
} else {
// Removes ban sanctions
update(table -> {
Expand All @@ -89,6 +97,28 @@ public void clearExpiredSanctions() {
}
}

private void clearExpiredSanctionsWithSubQuery(String sanctionColumn) {
SqlDialect dialect = SqlDialects.from(this.connection.getDatabaseConfiguration().getDatabaseType());
String usersTable = dialect.quoteTableReference(getTableName());
String sanctionsTable = dialect.quoteTableReference(this.connection.getDatabaseConfiguration().getTablePrefix() + "sanctions");
String column = dialect.quoteIdentifier(sanctionColumn);
String idColumn = dialect.quoteIdentifier("id");
String expiredAtColumn = dialect.quoteIdentifier("expired_at");

String sql = "UPDATE " + usersTable +
" SET " + column + " = NULL" +
" WHERE " + column + " IN (" +
"SELECT " + idColumn + " FROM " + sanctionsTable + " WHERE " + expiredAtColumn + " < ?" +
")";

try (var connection = getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
statement.executeUpdate();
} catch (SQLException exception) {
exception.printStackTrace();
}
}

/**
* Updates the ban sanction ID for a specified user.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ public void processBatchs() {
String database = globalDatabaseConfiguration.getDatabase();
boolean debug = globalDatabaseConfiguration.isDebug();

return new DatabaseConfiguration(tablePrefix, user, password, port, host, database, debug, storageType == StorageType.SQLITE ? DatabaseType.SQLITE : storageType == StorageType.MARIADB ? DatabaseType.MARIADB : DatabaseType.MYSQL);
DatabaseType databaseType = switch (storageType) {
case SQLITE -> DatabaseType.SQLITE;
case MARIADB -> DatabaseType.MARIADB;
case POSTGRESQL -> DatabaseType.POSTGRESQL;
default -> DatabaseType.MYSQL;
};

return new DatabaseConfiguration(tablePrefix, user, password, port, host, database, debug, databaseType);
}

@Override
Expand Down
12 changes: 7 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ enable-debug: false

# Storage:
# SQLITE - For the launch of the plugin only.
# MYSQL - Allows creating a simple connection to the database, only for small servers.
# HIKARICP - HikariCP is a fast and lightweight JDBC connection pool. It optimizes database connections, ensuring quick acquisition and low latency. This improves performance and reliability, making it ideal for high-demand applications.
# MYSQL - RECOMMENDED
# MARIADB - RECOMMENDED
# POSTGRESQL - RECOMMENDED
# HIKARICP - Legacy MySQL HikariCP storage type, kept for backward compatibility.
#
# We advise you to use MYSQL or HIKARICP, 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 MYSQL, MARIADB, 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 @@ -38,7 +40,7 @@ database-configuration:
table-prefix: "zessentials_"
# 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 @@ -299,4 +301,4 @@ blacklist-uuids:
# - TELEPORT_REQUEST_DISABLE: Disables receiving teleport requests from other players
default-options:
- option: WORLDEDIT_INVENTORY
value: true
value: true
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ softdepend:
api-version: '1.20'
libraries:
- 'org.mariadb.jdbc:mariadb-java-client:3.5.6'
- 'org.postgresql:postgresql:42.7.3'