Skip to content

Commit

Permalink
Exclude Adventure in Velocity and updated DatabaseUtils usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Jun 30, 2024
1 parent e958f63 commit e0eb8b7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public interface PendingLinkRepository extends IRepository<LinkRequest> {
CompletableFuture<LinkRequest> findByJavaUsername(String javaUsername);

CompletableFuture<LinkRequest> insert(LinkRequest request);
CompletableFuture<Void> insert(LinkRequest request);

CompletableFuture<Void> delete(LinkRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

@Repository
public interface PlayerLinkRepository extends IRepository<LinkedPlayer> {

CompletableFuture<LinkedPlayer> findByBedrockIdOrJavaUniqueId(
UUID bedrockId,
UUID javaUniqueId
Expand All @@ -43,5 +42,5 @@ CompletableFuture<LinkedPlayer> findByBedrockIdOrJavaUniqueId(

CompletableFuture<Void> deleteByBedrockIdOrJavaUniqueId(UUID bedrockId, UUID javaUniqueId);

CompletableFuture<LinkedPlayer> insert(LinkedPlayer player);
CompletableFuture<Void> insert(LinkedPlayer player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import io.micronaut.context.ApplicationContext;
import java.nio.file.Path;
import org.geysermc.databaseutils.DatabaseType;
import org.geysermc.databaseutils.DatabaseUtils;
import org.geysermc.databaseutils.IRepository;
import org.geysermc.databaseutils.sql.SqlDialect;
import org.geysermc.floodgate.core.config.FloodgateConfig;
import org.geysermc.floodgate.isolation.library.LibraryManager;

Expand All @@ -13,33 +13,32 @@ private DatabaseLoader() {}

public static void load(FloodgateConfig config, LibraryManager manager, Path dataDirectory, ApplicationContext context) {
var databaseConfig = config.database();
if (databaseConfig.enabled()) {
var type = DatabaseType.byId(databaseConfig.type());
if (type == null) {
throw new IllegalStateException(
"Unable to find database type that matches: " + databaseConfig.type()
);
}

type.libraries().forEach(manager::addLibrary);
manager.apply();

//todo have a hardcoded list of driver classnames in DatabaseUtils
try {
Class.forName("org.h2.Driver", true, manager.classLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}

var databaseUtils = DatabaseUtils.builder()
.credentialsFile(dataDirectory.resolve("database-config.properties"))
.poolName("floodgate")
.dialect(SqlDialect.requireByName(config.database().type()))
.build();
context.registerSingleton(databaseUtils);
for (IRepository<?> repository : databaseUtils.start()) {
context.registerSingleton(repository);
}
if (!databaseConfig.enabled()) {
return;
}

var type = DatabaseType.byName(databaseConfig.type());
if (type == null) {
throw new IllegalStateException("Unsupported database type: " + databaseConfig.type());
}

var libraries = DatabaseTypeLibraries.byDatabaseType(type);
if (libraries == null) {
throw new IllegalStateException("Unable to find database type that matches: " + type);
}

libraries.libraries().forEach(manager::addLibrary);
manager.apply();

var databaseUtils = DatabaseUtils.builder()
.credentialsFile(dataDirectory.resolve("database-config.properties"))
.poolName("floodgate")
.type(type)
.build();

context.registerSingleton(databaseUtils);
for (IRepository<?> repository : databaseUtils.start()) {
context.registerSingleton(repository);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@

package org.geysermc.floodgate.core.database.loader;

import java.util.Locale;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.databaseutils.DatabaseType;
import org.geysermc.floodgate.isolation.library.Library;
import org.geysermc.floodgate.isolation.library.Repository;

public enum DatabaseType {
public enum DatabaseTypeLibraries {
H2(hikariCp(), library("h2", Repository.MAVEN_CENTRAL, "com.h2database", "h2", "2.2.224"));

private static final DatabaseType[] VALUES = values();
private final Set<Library> libraries;

DatabaseType(@NonNull Library... libraries) {
DatabaseTypeLibraries(@NonNull Library... libraries) {
this.libraries = Set.of(libraries);
}

Expand All @@ -61,14 +60,11 @@ static Library library(
.build();
}

public static DatabaseType byId(String id) {
id = id.toUpperCase(Locale.ROOT);
for (DatabaseType value : VALUES) {
if (value.name().equals(id)) {
return value;
}
}
return null;
public static DatabaseTypeLibraries byDatabaseType(DatabaseType type) {
return switch (type) {
case H2 -> H2;
default -> null;
};
}

public Set<Library> libraries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
import io.micronaut.http.annotation.Header;
import io.micronaut.http.client.annotation.Client;
import java.util.concurrent.CompletableFuture;
import org.geysermc.floodgate.core.util.Constants;

@Client("${http.baseUrl}/v2/link")
@Header(name = USER_AGENT, value = "${http.userAgent}")
@Client("${http.baseUrl.api}/v2/link")
@Header(name = USER_AGENT, value = Constants.USER_AGENT)
public interface GlobalLinkClient {
@Get("/bedrock/{xuid}")
@SingleResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public CompletableFuture<LinkedPlayer> addLink(
@NonNull UUID javaUniqueId,
@NonNull String javaUsername,
@NonNull UUID bedrockId) {
return linkRepository.insert(new LinkedPlayer(bedrockId, javaUniqueId, javaUsername));
//todo allow it to return self again, probably after the entity rework to interfaces?
var link = new LinkedPlayer(bedrockId, javaUniqueId, javaUsername);
return linkRepository.insert(link).thenApply(v -> link);
}

@Override
Expand All @@ -83,7 +85,8 @@ public CompletableFuture<LinkRequest> createLinkRequest(
@NonNull String javaUsername,
@NonNull String bedrockUsername,
@NonNull String code) {
return pendingLinkRepository.insert(new LinkRequest(javaUniqueId, javaUsername, bedrockUsername, code));
var linkRequest = new LinkRequest(javaUniqueId, javaUsername, bedrockUsername, code);
return pendingLinkRepository.insert(linkRequest).thenApply(v -> linkRequest);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ cloud-core = { module = "org.incendo:cloud-core", version.ref = "cloud" }
snakeyaml = { module = "org.yaml:snakeyaml", version.ref = "snakeyaml" }
bstats = { module = "org.bstats:bstats-base", version.ref = "bstats" }

adventure-api = { module = "net.kyori:adventure-api", version.ref = "adventure" }
adventure-key = { module = "net.kyori:adventure-key", version.ref = "adventure" }
adventure-text-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure" }
adventure-platform-bukkit = { module = "net.kyori:adventure-platform-bukkit", version.ref = "adventure-platform"}
adventure-platform-bungee = { module = "net.kyori:adventure-platform-bungeecord", version.ref = "adventure-platform"}
Expand Down
5 changes: 2 additions & 3 deletions velocity/base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
var log4jVersion = "2.11.2"
var gsonVersion = "2.8.8"

dependencies {
api(projects.core)
annotationProcessor(projects.core)
Expand All @@ -19,3 +16,5 @@ provided(libs.gson)
provided(libs.velocity.api)
provided(libs.velocity.proxy)
providedDependency(libs.slf4j)
providedDependency(libs.adventure.api)
providedDependency(libs.adventure.key)

0 comments on commit e0eb8b7

Please sign in to comment.