Skip to content
Merged
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
34 changes: 32 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
`java-library`
id("xyz.srnyx.gradle-galaxy") version "ac4875a"
id("com.gradleup.shadow") version "9.5.1"
id("me.modmuss50.mod-publish-plugin") version "bf05e3d"
id("me.modmuss50.mod-publish-plugin") version "675051c"
id("io.papermc.hangar-publish-plugin") version "0.1.4"
id("net.kyori.blossom") version "2.2.0"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.4.1" // For Blossom
Expand Down Expand Up @@ -168,12 +168,42 @@ val runtimeLibraries = listOf(
version = "0.10.2",
relocations = listOf(Relocation("org.reflections")),
dependencies = listOf("javassist")),
RuntimeLibrary(
name = "hikaricp",
repositories = listOf(Repository.MAVEN_CENTRAL.url),
group = "com.zaxxer",
artifact = "HikariCP",
version = "7.1.0",
relocations = listOf(Relocation("com.zaxxer.hikari"))),
RuntimeLibrary(
name = "reactive_streams",
repositories = listOf(Repository.MAVEN_CENTRAL.url),
group = "org.reactivestreams",
artifact = "reactive-streams",
version = "1.0.4",
relocations = listOf(Relocation("org.reactivestreams"))),
RuntimeLibrary(
name = "r2dbc_spi",
repositories = listOf(Repository.MAVEN_CENTRAL.url),
group = "io.r2dbc",
artifact = "r2dbc-spi",
version = "1.0.0.RELEASE",
relocations = listOf(Relocation("io.r2dbc")),
dependencies = listOf("reactive_streams")),
RuntimeLibrary(
name = "jooq",
repositories = listOf(Repository.MAVEN_CENTRAL.url),
group = "org.jooq",
artifact = "jooq",
version = "3.19.36", // Keep on 3.19.x for Java 17 support (https://www.jooq.org/download/support-matrix-jdk#oss)
relocations = listOf(Relocation("org.jooq")),
dependencies = listOf("r2dbc_spi")),
RuntimeLibrary(
name = "h2",
repositories = listOf(Repository.MAVEN_CENTRAL.url),
group = "com.h2database",
artifact = "h2",
version = "2.2.224", // Don't update to keep support for Java 8
version = "2.4.240",
relocations = listOf(Relocation("org.h2"))),
RuntimeLibrary(
name = "postgresql",
Expand Down
36 changes: 14 additions & 22 deletions src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import xyz.srnyx.annoyingapi.message.MessagesProvider;
import xyz.srnyx.annoyingapi.options.AnnoyingOptions;
import xyz.srnyx.annoyingapi.scheduler.AnnoyingScheduler;
import xyz.srnyx.annoyingapi.stats.StatsHelper;
import xyz.srnyx.annoyingapi.stats.loader.BStatsLoader;
import xyz.srnyx.annoyingapi.stats.loader.FastStatsLoader;
import xyz.srnyx.annoyingapi.stats.provider.BStatsProvider;
Expand All @@ -37,7 +36,7 @@
import xyz.srnyx.annoyingapi.storage.ConnectionException;
import xyz.srnyx.annoyingapi.storage.DataManager;
import xyz.srnyx.annoyingapi.storage.StorageConfig;
import xyz.srnyx.annoyingapi.storage.dialects.sql.SQLDialect;
import xyz.srnyx.annoyingapi.storage.dialects.SQLDialect;
import xyz.srnyx.annoyingapi.dependency.AnnoyingDependency;
import xyz.srnyx.annoyingapi.dependency.AnnoyingDownload;
import xyz.srnyx.annoyingapi.events.AdvancedPlayerMoveEvent;
Expand All @@ -56,7 +55,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.LogRecord;
Expand Down Expand Up @@ -94,10 +92,6 @@ public void log(@NotNull LogRecord logRecord) {
* Loader for OkaeriConfig configs
*/
@NotNull public final ConfigLoader configLoader;
/**
* Helper for stats providers (bStats, FastStats, etc.)
*/
@NotNull public final StatsHelper statsHelper = new StatsHelper(this);
/**
* The {@link DataManager} for the plugin
*/
Expand Down Expand Up @@ -217,11 +211,7 @@ public final void onDisable() {
// Save cache
if (dataManager.storageConfig.cache.getSaveOn().contains(StorageConfig.Cache.SaveOn.DISABLE)) dataManager.dialect.saveCache();
// Close connection (if SQL)
if (dataManager.dialect instanceof SQLDialect) try {
((SQLDialect) dataManager.dialect).connection.close();
} catch (final SQLException e) {
log(Level.SEVERE, "&cFailed to close the database connection", e);
}
if (dataManager.dialect instanceof SQLDialect sqlDialect) sqlDialect.dataSource.close();
}

// Stats loaders
Expand Down Expand Up @@ -619,11 +609,7 @@ public void loadDataManger(@Nullable StorageConfig storageConfig, boolean saveCa
// Save cache
if (saveCache) dataManager.dialect.saveCache();
// Close previous connection
if (dataManager.dialect instanceof SQLDialect) try {
((SQLDialect) dataManager.dialect).connection.close();
} catch (final SQLException e) {
log(Level.SEVERE, "&cFailed to close the database connection, it's recommended to restart the server!", e);
}
if (dataManager.dialect instanceof SQLDialect sqlDialect) sqlDialect.dataSource.close();
// Stop cache saving task
if (dataManager.cacheSavingTask != null) dataManager.cacheSavingTask.cancel();
}
Expand Down Expand Up @@ -651,15 +637,21 @@ public void loadDataManger(@Nullable StorageConfig storageConfig, boolean saveCa

// Attempt database migration
dataManager = dataManager.attemptDatabaseMigration();

// Create tables/columns
if (dataManager.dialect instanceof SQLDialect) {
final Map<String, Set<String>> tablesCopy = new HashMap<>(options.dataOptions.tables);
if (dataManager.dialect instanceof final SQLDialect sqlDialect) {
final Map<String, Set<String>> tables = new HashMap<>(options.dataOptions.tables);

// Remove entities table if it has no custom columns
final Set<String> entitiesTable = tablesCopy.get(EntityData.TABLE_NAME);
if (entitiesTable != null && entitiesTable.size() == 1) tablesCopy.remove(EntityData.TABLE_NAME);
final Set<String> entitiesTable = tables.get(EntityData.TABLE_NAME);
if (entitiesTable != null && entitiesTable.size() == 1) tables.remove(EntityData.TABLE_NAME);

sqlDialect.createTablesKeys(tables);

((SQLDialect) dataManager.dialect).createTablesKeys(tablesCopy);
// Warm up jOOQ (see warmup docs)
tables.keySet().stream()
.findFirst()
.ifPresent(table -> scheduler.attemptAsync(() -> sqlDialect.warmup(table)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import eu.okaeri.configs.migrate.builtin.NamedMigration;
import xyz.srnyx.annoyingapi.storage.StorageMethod;

import java.util.Objects;

import static eu.okaeri.configs.migrate.ConfigMigrationDsl.*;


Expand All @@ -15,7 +13,7 @@ public S0002_Remote_connection_null_port() {
not(exists("remote_connection.port")),
(config, view) -> {
final StorageMethod method = view.getOr("remote_connection.method", StorageMethod.class, StorageMethod.H2);
view.set("remote_connection.port", Objects.requireNonNullElse(method.defaultPort, 3306));
view.set("remote_connection.port", method.sqlInfo != null && method.sqlInfo.defaultPort() != null ? method.sqlInfo.defaultPort() : 3306);
return true;
}));
}
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/xyz/srnyx/annoyingapi/options/DataOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DataOptions extends Stringable {
/**
* Options for {@link EntityData entity data management}
*/
@NotNull public Entities entities = new Entities();
@Deprecated @NotNull public Entities entities = new Entities();

/**
* Sets {@link #enabled}
Expand All @@ -55,6 +55,7 @@ public DataOptions enabled(boolean enabled) {
/**
* Adds all the specified tables to {@link #tables}
* <br>All tables and columns will be converted to lowercase
* <br><i>Also sets {@link #enabled} to true</i>
*
* @param tables the tables to add
*
Expand All @@ -66,12 +67,13 @@ public DataOptions tables(@NotNull Map<String, Collection<String>> tables) {
.collect(HashMap::new, (map, entry) -> map.put(entry.getKey().toLowerCase(), entry.getValue().stream()
.map(String::toLowerCase)
.collect(HashSet::new, HashSet::add, HashSet::addAll)), HashMap::putAll));
return this;
return enabled(true);
}

/**
* Adds the specified table to {@link #tables}
* <br>The table and all columns will be converted to lowercase
* <br><i>Also sets {@link #enabled} to true</i>
*
* @param table the table to add
* @param columns the columns to add for the table
Expand All @@ -83,12 +85,13 @@ public DataOptions table(@NotNull String table, @NotNull Collection<String> colu
this.tables.put(table.toLowerCase(), columns.stream()
.map(String::toLowerCase)
.collect(HashSet::new, HashSet::add, HashSet::addAll));
return this;
return enabled(true);
}

/**
* Adds the specified table to {@link #tables}
* <br>The table and all columns will be converted to lowercase
* <br><i>Also sets {@link #enabled} to true</i>
*
* @param table the table to add
* @param columns the columns to add for the table
Expand All @@ -102,6 +105,7 @@ public DataOptions table(@NotNull String table, @NotNull String... columns) {

/**
* Adds the specified columns to the {@link EntityData#TABLE_NAME} table
* <br><i>Also sets {@link #enabled} to true</i>
*
* @param columns the columns to add
*
Expand All @@ -112,11 +116,12 @@ public DataOptions entityDataColumns(@NotNull Collection<String> columns) {
final Set<String> entityDataColumns = tables.get(EntityData.TABLE_NAME);
if (entityDataColumns == null) return table(EntityData.TABLE_NAME, new HashSet<>(columns));
entityDataColumns.addAll(columns);
return this;
return enabled(true);
}

/**
* Adds the specified columns to the {@link EntityData#TABLE_NAME} table
* <br><i>Also sets {@link #enabled} to true</i>
*
* @param columns the columns to add
*
Expand Down Expand Up @@ -147,7 +152,7 @@ public DataOptions useCacheDefault(boolean useCacheDefault) {
*
* @return this {@link DataOptions} instance for chaining
*/
@NotNull
@Deprecated @NotNull
public DataOptions entities(@NotNull Entities entities) {
this.entities = entities;
return this;
Expand All @@ -160,7 +165,7 @@ public DataOptions entities(@NotNull Entities entities) {
*
* @return this {@link DataOptions} instance for chaining
*/
@NotNull
@Deprecated @NotNull
public DataOptions entities(@NotNull Consumer<Entities> consumer) {
consumer.accept(entities);
return this;
Expand Down Expand Up @@ -196,7 +201,7 @@ public static DataOptions load(@NotNull ConfigurationSection section) {
/**
* Options for {@link EntityData entity data management}
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public static class Entities extends Stringable {
/**
* The path to the folder (inside {@code plugins/PLUGIN/data/}) where the entity data files will be stored
Expand Down
43 changes: 0 additions & 43 deletions src/main/java/xyz/srnyx/annoyingapi/stats/StatsHelper.java

This file was deleted.

Loading