Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
92868fe
Add database for users, add batch fetching, update tests
CitralFlo Aug 30, 2025
1a7dd18
Codestyle fixes
CitralFlo Aug 30, 2025
3c6ad2a
Resolve gemini review
CitralFlo Aug 30, 2025
7d3ee9e
Resolve @sadcenter and @Jakubk15 reviews
CitralFlo Sep 1, 2025
9414f7d
wip
Rollczi Sep 1, 2025
b3efc5f
wip2
CitralFlo Sep 13, 2025
2050371
Merge remote-tracking branch 'origin/user-manager-database' into user…
CitralFlo Sep 13, 2025
0cdf8b2
wip
CitralFlo Oct 5, 2025
11813d4
Update methods and failsafe for cache
CitralFlo Oct 6, 2025
14a95d6
Merge branch 'master' into user-manager-database
vLuckyyy Oct 23, 2025
c3aa70a
Merge branch 'master' into user-manager-database
vLuckyyy Nov 29, 2025
80730a5
Refactor `UserManager` and related classes to improve database integr…
vLuckyyy Nov 30, 2025
2e0a7e1
Remove MySQL and Testcontainers integration, refactor database config…
vLuckyyy Nov 30, 2025
5cebc63
CR
Rollczi Nov 30, 2025
5f086ae
Remove `created` and `lastLogin` fields from `User`, cleanup related …
vLuckyyy Dec 1, 2025
d42de10
Remove `IntegrationTestSpec` and `TestScheduler` utilities as they ar…
vLuckyyy Dec 1, 2025
982ce14
Add `lastSeen` and `accountCreated` fields to `User`, enhance `UserMa…
vLuckyyy Dec 6, 2025
8858585
Merge branch 'master' into user-manager-database
vLuckyyy Dec 6, 2025
c9ae250
Update `UserTable` to use `DATE_STRING` for `lastSeen` and `accountCr…
vLuckyyy Dec 6, 2025
10f2f98
Merge branch 'master' into user-manager-database
vLuckyyy Dec 6, 2025
a4cfc08
Update `UserTable` to replace `Instant` with `Date` fields and downgr…
vLuckyyy Dec 6, 2025
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: 2 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ object Versions {
// tests
const val JUNIT_BOM = "5.13.4"
const val MOCKITO_CORE = "5.19.0"
const val TEST_CONTAINERS = "1.21.3"
const val MYSQL_CONNECTOR = "8.0.33"

}
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/eternalcode-java-test.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testImplementation("org.testcontainers:junit-jupiter:${Versions.TEST_CONTAINERS}")
testImplementation("org.testcontainers:mysql:${Versions.TEST_CONTAINERS}")
testImplementation("mysql:mysql-connector-java:${Versions.MYSQL_CONNECTOR}")
testImplementation("org.mockito:mockito-core:${Versions.MOCKITO_CORE}")
testImplementation("net.kyori:adventure-platform-facet:${Versions.ADVENTURE_PLATFORM}")
testImplementation("org.spigotmc:spigot-api:${Versions.SPIGOT_API}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ protected <T> CompletableFuture<List<T>> selectAll(Class<T> type) {
return this.action(type, Dao::queryForAll);
}

protected <T> CompletableFuture<List<T>> selectBatch(Class<T> type, int offset, int limit) {
return this.action(type, dao -> dao.queryBuilder().offset((long) offset).limit((long) limit).query());
}

protected <T, ID, R> CompletableFuture<R> action(
Class<T> type,
ThrowingFunction<Dao<T, ID>, R, SQLException> action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DatabaseConfig extends OkaeriConfig implements DatabaseSettings {
@Comment({"Type of the database driver (e.g., SQLITE, H2, MYSQL, MARIADB, POSTGRESQL).", "Determines the "
+ "database type "
+ "to be used."})
public DatabaseDriverType databaseType = DatabaseDriverType.SQLITE;
public DatabaseDriverType databaseType = DatabaseDriverType.MYSQL;

@Comment({"Hostname of the database server.", "For local databases, this is usually 'localhost'."})
public String hostname = "localhost";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public enum DatabaseDriverType {
MARIADB(MARIADB_DRIVER, MARIADB_JDBC_URL),
POSTGRESQL(POSTGRESQL_DRIVER, POSTGRESQL_JDBC_URL),
H2(H2_DRIVER, H2_JDBC_URL),
SQLITE(SQLITE_DRIVER, SQLITE_JDBC_URL);
SQLITE(SQLITE_DRIVER, SQLITE_JDBC_URL),

H2_TEST(H2_DRIVER, "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=MYSQL");

private final String driver;
private final String urlFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void connect() {
settings.database(),
String.valueOf(settings.ssl())
);
case H2_TEST -> type.formatUrl();
};

this.dataSource.setJdbcUrl(jdbcUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.user.User;
import com.eternalcode.core.user.UserManager;
import java.util.Optional;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -56,7 +57,8 @@ void onAfkSwitch(AfkSwitchEvent event) {
return;
}

User user = this.userManager.getOrCreate(playerUUID, player.getName());
Optional<User> optionalUser = this.userManager.getUser(playerUUID);
User user = optionalUser.get();
Translation translation = this.translationManager.getMessages(user.getUniqueId());

Component component = this.miniMessage.deserialize(translation.afk().afkKickReason());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Controller;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.user.User;
import com.eternalcode.core.user.UserManager;
import com.eternalcode.commons.adventure.AdventureUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand All @@ -16,8 +14,6 @@
import org.bukkit.event.player.PlayerLoginEvent;
import panda.utilities.text.Joiner;

import java.util.Optional;

@PermissionDocs(
name = "Bypass Full Server",
description = "This feature allows you to bypass the full server, example for vip rank.",
Expand All @@ -29,13 +25,11 @@ class FullServerBypassController implements Listener {
static final String SLOT_BYPASS = "eternalcore.slot.bypass";

private final TranslationManager translationManager;
private final UserManager userManager;
private final MiniMessage miniMessage;

@Inject
FullServerBypassController(TranslationManager translationManager, UserManager userManager, MiniMessage miniMessage) {
FullServerBypassController(TranslationManager translationManager, MiniMessage miniMessage) {
this.translationManager = translationManager;
this.userManager = userManager;
this.miniMessage = miniMessage;
}

Expand All @@ -50,26 +44,16 @@ void onLogin(PlayerLoginEvent event) {
return;
}

String serverFullMessage = this.getServerFullMessage(player);
String serverFullMessage = this.getServerFullMessage();
Component serverFullMessageComponent = this.miniMessage.deserialize(serverFullMessage);

event.disallow(PlayerLoginEvent.Result.KICK_FULL, AdventureUtil.SECTION_SERIALIZER.serialize(serverFullMessageComponent));
}
}

private String getServerFullMessage(Player player) {
Optional<User> userOption = this.userManager.getUser(player.getUniqueId());

if (userOption.isEmpty()) {
return Joiner.on("\n")
.join(this.translationManager.getMessages().player().fullServerSlots())
.toString();
}

User user = userOption.get();

private String getServerFullMessage() {
return Joiner.on("\n")
.join(this.translationManager.getMessages(user.getUniqueId()).player().fullServerSlots())
.join(this.translationManager.getMessages().player().fullServerSlots())
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import com.google.common.cache.CacheBuilder;
import java.time.Duration;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Server;
import org.bukkit.entity.Player;

@Service
Expand All @@ -27,6 +27,7 @@ class MsgServiceImpl implements MsgService {
private final MsgPresenter presenter;
private final EventCaller eventCaller;
private final MsgToggleService msgToggleService;
private final Server server;

private final Cache<UUID, UUID> replies = CacheBuilder.newBuilder()
.expireAfterWrite(Duration.ofHours(1))
Expand All @@ -40,7 +41,7 @@ class MsgServiceImpl implements MsgService {
IgnoreService ignoreService,
UserManager userManager,
EventCaller eventCaller,
MsgToggleService msgToggleService
MsgToggleService msgToggleService, Server server
) {
this.noticeService = noticeService;
this.ignoreService = ignoreService;
Expand All @@ -49,15 +50,10 @@ class MsgServiceImpl implements MsgService {
this.msgToggleService = msgToggleService;

this.presenter = new MsgPresenter(noticeService);
this.server = server;
}

void privateMessage(User sender, User target, String message) {
if (target.getClientSettings().isOffline()) {
this.noticeService.player(sender.getUniqueId(), translation -> translation.argument().offlinePlayer());

return;
}

UUID uniqueId = target.getUniqueId();

this.msgToggleService.getState(uniqueId).thenAccept(msgState -> {
Expand Down Expand Up @@ -89,17 +85,14 @@ void reply(User sender, String message) {
return;
}

Optional<User> targetOption = this.userManager.getUser(uuid);

if (targetOption.isEmpty()) {
Player target = this.server.getPlayer(uuid);
if (target == null) {
this.noticeService.player(sender.getUniqueId(), translation -> translation.argument().offlinePlayer());

return;
}

User target = targetOption.get();

this.privateMessage(sender, target, message);
this.privateMessage(sender, toUser(target), message);
}

@Override
Expand All @@ -119,12 +112,18 @@ public boolean isSpy(UUID player) {

@Override
public void reply(Player sender, String message) {
this.reply(this.userManager.getOrCreate(sender.getUniqueId(), sender.getName()), message);
this.reply(toUser(sender), message);
}

@Override
public void sendMessage(Player sender, Player target, String message) {
User user = this.userManager.getOrCreate(target.getUniqueId(), target.getName());
this.privateMessage(this.userManager.getOrCreate(sender.getUniqueId(), sender.getName()), user, message);
User user = toUser(target);
this.privateMessage(toUser(sender), user, message);
}

private User toUser(Player target) {
return this.userManager.getUser(target.getUniqueId()).get();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
import com.eternalcode.core.user.UserManager;
import dev.rollczi.litecommands.argument.Argument;
import dev.rollczi.litecommands.argument.parser.ParseResult;
import static dev.rollczi.litecommands.argument.parser.ParseResult.failure;
import static dev.rollczi.litecommands.argument.parser.ParseResult.success;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.suggestion.SuggestionContext;
import dev.rollczi.litecommands.suggestion.SuggestionResult;
import java.util.regex.Pattern;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;

@LiteArgument(type = User.class)
class UserArgument extends AbstractViewerArgument<User> {

private static final Pattern USERNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_]{1,16}$");

private final Server server;
private final UserManager userManager;

Expand All @@ -28,18 +33,22 @@ class UserArgument extends AbstractViewerArgument<User> {
this.userManager = userManager;
}

@Override
public ParseResult<User> parse(Invocation<CommandSender> invocation, String argument, Translation translation) {
return ParseResult.completableFuture(this.userManager.getUserFromRepository(argument), maybeUser -> maybeUser.map(user -> success(user))
.orElse(failure(translation.argument().offlinePlayer())));
}

@Override
protected boolean match(Invocation<CommandSender> invocation, Argument<User> context, String argument) {
return USERNAME_PATTERN.matcher(argument).matches();
}

@Override
public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<User> argument, SuggestionContext context) {
return this.server.getOnlinePlayers().stream()
.map(HumanEntity::getName)
.collect(SuggestionResult.collector());
}

@Override
public ParseResult<User> parse(Invocation<CommandSender> invocation, String argument, Translation translation) {
return this.userManager.getUser(argument)
.map(ParseResult::success)
.orElseGet(() -> ParseResult.failure(translation.argument().offlinePlayer()));
}

}

This file was deleted.

This file was deleted.

Loading