This commit is contained in:
kento2 2026-07-05 03:06:15 +02:00
parent ea6ae529cc
commit 7040a6ce1e
20 changed files with 135 additions and 83 deletions

29
.idea/workspace.xml generated
View file

@ -5,38 +5,25 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="56c685a1-f609-4ffd-a951-849beb2a7f8d" name="Changes" comment="currently refactoring a lot"> <list default="true" id="56c685a1-f609-4ffd-a951-849beb2a7f8d" name="Changes" comment="currently refactoring a lot">
<change beforePath="$PROJECT_DIR$/../build-logic/convention/src/main/kotlin/de/kentoj/scrow/BaseDependenciesConvention.kt" beforeDir="false" afterPath="$PROJECT_DIR$/../build-logic/convention/src/main/kotlin/de/kentoj/scrow/BaseDependenciesConvention.kt" afterDir="false" /> <change afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/cache/InstanceCache.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../build-logic/convention/src/main/kotlin/de/kentoj/scrow/DatabaseConvention.kt" beforeDir="false" afterPath="$PROJECT_DIR$/../build-logic/convention/src/main/kotlin/de/kentoj/scrow/DatabaseConvention.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-api/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-api/build.gradle.kts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-api/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-api/build.gradle.kts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/OrderedUUIDPair.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/friends/OrderedUUIDPair.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/scheduler/TaskImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/scheduler/TaskImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/build.gradle.kts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/build.gradle.kts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsGetLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsGetLiteral.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/PostgresFriendshipService.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/friendship/PostgresFriendshipService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/PostgresFriendRequestService.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/request/PostgresFriendRequestService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDeployLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDeployLiteral.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/playermanager/PlayerManagerImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/playermanager/PlayerManagerImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/LobbyCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/LobbyCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/PlayCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/PlayCommand.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/PlayCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/PlayCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-lib/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-lib/build.gradle.kts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-lib/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-lib/build.gradle.kts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-lib/src/main/java/de/kentoj/scrowlib/convention/ScrowMessageStyle.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-lib/src/main/java/de/kentoj/scrowlib/convention/ScrowMessageStyle.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-lib/src/main/java/de/kentoj/scrowlib/instancemanager/InstanceManagerImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-lib/src/main/java/de/kentoj/scrowlib/instancemanager/InstanceManagerImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-lib/src/main/java/de/kentoj/scrowlib/messaging/MessageBroker.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-lib/src/main/java/de/kentoj/scrowlib/messaging/MessageBroker.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-api/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-api/build.gradle.kts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-velocity-api/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-api/build.gradle.kts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-api/src/main/java/de/kentoj/scrow/velocity/ScrowAPI.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-api/src/main/java/de/kentoj/scrow/velocity/ScrowAPI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/build.gradle.kts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-velocity-impl/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/build.gradle.kts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/CoreVelocityPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/CoreVelocityPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/command/OnlineCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/command/OnlineCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/MsgCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/MsgCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/PrivMsgHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/PrivMsgHandler.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/ReplyCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/ReplyCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/server/SendPlayerWatchdog.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/server/SendPlayerWatchdog.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/server/ServerRegisterWatchdog.java" beforeDir="false" afterPath="$PROJECT_DIR$/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/server/ServerRegisterWatchdog.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

View file

@ -1,8 +1,9 @@
TODO TODO
- cleanup nats - /friend add command is behaving weird: silent return no error
- timeout/error handling with reactive - improve error handling in Task ig
- try with InMemory db and debug postgres implementation
- logging in general, log some exceptions to game chat - logging in general, log some exceptions to game chat
- djb's multilogd for logging(?) - sleep
environment environment
----------- -----------

View file

@ -23,9 +23,9 @@ dependencies {
// https://mvnrepository.com/artifact/io.nats/jnats // https://mvnrepository.com/artifact/io.nats/jnats
api("io.nats:jnats:2.25.2") api("io.nats:jnats:2.25.2")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core
api("de.kentoj.scrow:kencommandapi-core:0.28") api("de.kentoj.scrow:kencommandapi-core:0.30")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-bukkit // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-bukkit
api("de.kentoj.scrow:kencommandapi-bukkit:0.28") api("de.kentoj.scrow:kencommandapi-bukkit:0.30")
} }
publishing { publishing {

View file

@ -1,6 +1,5 @@
package de.kentoj.scrow.bukkit.friends; package de.kentoj.scrow.bukkit.friends;
import com.google.common.base.Preconditions;
import lombok.Getter; import lombok.Getter;
import java.util.UUID; import java.util.UUID;
@ -11,7 +10,6 @@ public class OrderedUUIDPair {
private final UUID second; private final UUID second;
public OrderedUUIDPair(UUID uuid1, UUID uuid2) { public OrderedUUIDPair(UUID uuid1, UUID uuid2) {
Preconditions.checkArgument(uuid1 != uuid2, "UUIDPair may consist of identical UUIDs");
if (uuid1.compareTo(uuid2) < 0) { if (uuid1.compareTo(uuid2) < 0) {
this.first = uuid1; this.first = uuid1;
this.second = uuid2; this.second = uuid2;

View file

@ -1,22 +1,16 @@
package de.kentoj.scrow.bukkit.scheduler; package de.kentoj.scrow.bukkit.scheduler;
import com.google.common.base.Preconditions;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
import static com.google.common.base.Preconditions.*;
/** /**
* A Task runs entirely async, when sync is used, a subtask is run on the main thread and the async thread * A Task runs entirely async, when sync is used, a subtask is run on the main thread and the async thread
* blocks until the subtask returns. * blocks until the subtask returns.
@ -34,7 +28,14 @@ public class TaskImpl<T> implements Task<T> {
@Override @Override
public CompletableFuture<T> toFuture() { public CompletableFuture<T> toFuture() {
return CompletableFuture.supplyAsync(() -> state().getValue(), EXECUTOR); return CompletableFuture.supplyAsync(() -> {
try {
return state().getValue();
} catch (Exception ex) {
log.error("failed completing future", ex);
throw new CompletionException(ex);
}
}, EXECUTOR);
} }
/** /**

View file

@ -26,9 +26,11 @@ dependencies {
// https://mvnrepository.com/artifact/io.nats/jnats // https://mvnrepository.com/artifact/io.nats/jnats
implementation("io.nats:jnats:2.25.2") implementation("io.nats:jnats:2.25.2")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core
implementation("de.kentoj.scrow:kencommandapi-core:0.28") implementation("de.kentoj.scrow:kencommandapi-core:0.30")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-bukkit // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-bukkit
implementation("de.kentoj.scrow:kencommandapi-bukkit:0.28") implementation("de.kentoj.scrow:kencommandapi-bukkit:0.30")
// https://mvnrepository.com/artifact/org.postgresql/postgresql
implementation("org.postgresql:postgresql:42.7.12")
} }
tasks { tasks {

View file

@ -2,33 +2,30 @@ package de.kentoj.scrow.bukkit;
import de.kentoj.scrow.bukkit.economy.command.CoinsCommand; import de.kentoj.scrow.bukkit.economy.command.CoinsCommand;
import de.kentoj.scrow.bukkit.friends.command.FriendCommand; import de.kentoj.scrow.bukkit.friends.command.FriendCommand;
import de.kentoj.scrow.bukkit.instancemanager.cache.InstanceCache;
import de.kentoj.scrow.bukkit.instancemanager.command.InstanceCommand; import de.kentoj.scrow.bukkit.instancemanager.command.InstanceCommand;
import de.kentoj.scrow.bukkit.region.RegionPlayerTracker; import de.kentoj.scrow.bukkit.region.RegionPlayerTracker;
import de.kentoj.scrow.bukkit.region.RegionTask; import de.kentoj.scrow.bukkit.region.RegionTask;
import de.kentoj.scrow.bukkit.server.LobbyCommand; import de.kentoj.scrow.bukkit.instancemanager.command.LobbyCommand;
import de.kentoj.scrow.bukkit.server.PlayCommand; import de.kentoj.scrow.bukkit.instancemanager.command.PlayCommand;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.FileDescriptor;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.file.OpenOption;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
public class CoreImplPlugin extends JavaPlugin { public class CoreImplPlugin extends JavaPlugin {
public static boolean ENABLE_DATABASE = false;
@Override @Override
public void onEnable() { public void onEnable() {
ScrowAPISurface.initScrowAPI(this, ENABLE_DATABASE); ScrowAPISurface.initScrowAPI(this, true);
{ {
ScrowAPI.getCommandApi().register(new CoinsCommand().getRootNode()); ScrowAPI.getCommandApi().register(new CoinsCommand().getRootNode());
ScrowAPI.getCommandApi().register(FriendCommand.create()); ScrowAPI.getCommandApi().register(FriendCommand.create());
ScrowAPI.getCommandApi().register(InstanceCommand.create()); var instanceCache = new InstanceCache();
ScrowAPI.getCommandApi().register(InstanceCommand.create(instanceCache));
ScrowAPI.getCommandApi().register(new PlayCommand().getRootNode()); ScrowAPI.getCommandApi().register(new PlayCommand().getRootNode());
ScrowAPI.getCommandApi().register(new LobbyCommand().getRootNode()); ScrowAPI.getCommandApi().register(new LobbyCommand().getRootNode());
} }

View file

@ -17,9 +17,13 @@ import io.nats.client.Options;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jdbi.v3.core.ConnectionFactory;
import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.Jdbi;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
@NoArgsConstructor(access = AccessLevel.NONE) @NoArgsConstructor(access = AccessLevel.NONE)
public class ScrowAPISurface { public class ScrowAPISurface {
@ -39,7 +43,14 @@ public class ScrowAPISurface {
} }
if (enableDatabase) { if (enableDatabase) {
ScrowAPI.setJdbi(Jdbi.create(EnvUtils.envOrThrow("HOST_POSTGRES"))); try {
Class.forName("org.postgresql.Driver", true, ScrowAPISurface.class.getClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
var props = new Properties();
props.setProperty("user", "postgres");
ScrowAPI.setJdbi(Jdbi.create(EnvUtils.envOrThrow("HOST_POSTGRES"), props));
} }
ScrowAPI.setPlayerManager(new PlayerManagerImpl()); ScrowAPI.setPlayerManager(new PlayerManagerImpl());

View file

@ -45,12 +45,12 @@ public class FriendAddLiteral implements CommandExecutor<CommandSender> {
var self = (Player) ctx.getSender(); var self = (Player) ctx.getSender();
var other = ctx.getArg(playerArg); var other = ctx.getArg(playerArg);
return Tasks.supplyAsync(() -> findAction(self, other) return Tasks.supplyAsync(() -> findAction(self, other)
.mapSuccess(action -> { .mapSuccess(action -> {
if (action == AddAction.SEND_REQUEST) sendRequest(self, other); if (action == AddAction.SEND_REQUEST) sendRequest(self, other);
else if (action == AddAction.ACCEPT_REQUEST) acceptRequest(self, other); else if (action == AddAction.ACCEPT_REQUEST) acceptRequest(self, other);
return new Object(); return new Object();
}) }))
).toFuture(); .toFuture();
} }
private void sendRequest(Player self, OfflinePlayer other) { private void sendRequest(Player self, OfflinePlayer other) {

View file

@ -27,9 +27,9 @@ public class PostgresFriendshipService implements FriendshipService {
jdbi = ScrowAPI.getJdbi(); jdbi = ScrowAPI.getJdbi();
jdbi.useHandle(h -> h.execute(""" jdbi.useHandle(h -> h.execute("""
CREATE TABLE IF NOT EXISTS friendships ( CREATE TABLE IF NOT EXISTS friendships (
first_uuid UUID NOT NULL, first_uuid UUID NOT NULL,
second_uuid UUID NOT NULL, second_uuid UUID NOT NULL,
created_at TIMESTAMPTZ NOT NULL, created_at TIMESTAMPTZ NOT NULL,
PRIMARY KEY (first_uuid, second_uuid), PRIMARY KEY (first_uuid, second_uuid),
CONSTRAINT friendship_no_self_friendship CONSTRAINT friendship_no_self_friendship
CHECK (first_uuid <> second_uuid) CHECK (first_uuid <> second_uuid)

View file

@ -25,13 +25,13 @@ public class PostgresFriendRequestService implements FriendRequestService {
jdbi = ScrowAPI.getJdbi(); jdbi = ScrowAPI.getJdbi();
jdbi.useHandle(h -> h.execute(""" jdbi.useHandle(h -> h.execute("""
CREATE TABLE IF NOT EXISTS friend-requests ( CREATE TABLE IF NOT EXISTS friendrequests (
from_uuid UUID NOT NULL, from_uuid UUID NOT NULL,
to_uuid UUID NOT NULL, to_uuid UUID NOT NULL,
created_at TIMESTAMPTZ NOT NULL, created_at TIMESTAMPTZ NOT NULL,
PRIMARY KEY (first_uuid, second_uuid), PRIMARY KEY (from_uuid, to_uuid),
CONSTRAINT friendship_no_self_friendship CONSTRAINT friendship_no_self_request
CHECK (first_uuid <> second_uuid) CHECK (from_uuid <> to_uuid)
) )
""")); """));
} }
@ -40,7 +40,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
public @Nullable FriendRequest getFriendRequest(UUID from, UUID to) { public @Nullable FriendRequest getFriendRequest(UUID from, UUID to) {
return jdbi.withHandle(h -> h.createQuery(""" return jdbi.withHandle(h -> h.createQuery("""
SELECT * SELECT *
FROM friend-requests FROM friendrequests
WHERE from_uuid = :from AND to_uuid = :to WHERE from_uuid = :from AND to_uuid = :to
""") """)
.bind("from", from) .bind("from", from)
@ -53,11 +53,12 @@ public class PostgresFriendRequestService implements FriendRequestService {
@Override @Override
public boolean saveFriendRequest(FriendRequest friendRequest) { public boolean saveFriendRequest(FriendRequest friendRequest) {
return jdbi.withHandle(h -> h.createUpdate(""" return jdbi.withHandle(h -> h.createUpdate("""
INSERT INTO friend-requests (from_uuid, to_uuid, created_at) INSERT INTO friendrequests (from_uuid, to_uuid, created_at)
VALUES (:from, :to, :created_at) VALUES (:from, :to, :createdAt)
""") """)
.bind("from", friendRequest.getFrom()) .bind("from", friendRequest.getFrom())
.bind("to", friendRequest.getTo()) .bind("to", friendRequest.getTo())
.bind("createdAt", friendRequest.getCreatedAt())
.execute() > 0); .execute() > 0);
} }
@ -65,7 +66,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
public List<FriendRequest> getFriendRequestsTo(UUID playerId) { public List<FriendRequest> getFriendRequestsTo(UUID playerId) {
return jdbi.withHandle(h -> h.createQuery(""" return jdbi.withHandle(h -> h.createQuery("""
SELECT * SELECT *
FROM friend-requests FROM friendrequests
WHERE to_uuid = :to WHERE to_uuid = :to
""") """)
.bind("to", playerId) .bind("to", playerId)
@ -77,7 +78,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
public List<FriendRequest> getFriendRequestsFrom(UUID playerId) { public List<FriendRequest> getFriendRequestsFrom(UUID playerId) {
return jdbi.withHandle(h -> h.createQuery(""" return jdbi.withHandle(h -> h.createQuery("""
SELECT * SELECT *
FROM friend-requests FROM friendrequests
WHERE from_uuid = :from WHERE from_uuid = :from
""") """)
.bind("from", playerId) .bind("from", playerId)
@ -89,7 +90,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
public boolean deleteFriendRequest(UUID from, UUID to) { public boolean deleteFriendRequest(UUID from, UUID to) {
return jdbi.withHandle(h -> h.createUpdate(""" return jdbi.withHandle(h -> h.createUpdate("""
DELETE DELETE
FROM friend-requests FROM friendrequests
WHERE from_uuid = :from AND to_uuid = :to WHERE from_uuid = :from AND to_uuid = :to
""") """)
.bind("from", from) .bind("from", from)

View file

@ -0,0 +1,44 @@
package de.kentoj.scrow.bukkit.instancemanager.cache;
import de.kentoj.scrow.bukkit.ScrowAPI;
import de.kentoj.scrowlib.instancemanager.ServerInstance;
import de.kentoj.scrowlib.messaging.MessageBroker;
import org.bson.Document;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public class InstanceCache {
private final MessageBroker messageBroker = ScrowAPI.getMessageBroker();
private final ConcurrentMap<String, ServerInstance> cache = new ConcurrentHashMap<>();
public InstanceCache() {
messageBroker.subscribe("event.instance.up", doc -> {
var inst = toInstance(doc);
cache.put(inst.getHandle(), inst);
});
messageBroker.subscribe("event.instance.down", doc -> {
cache.remove(doc.getString("handle"));
});
}
public Collection<ServerInstance> getInstances() {
return cache.values();
}
public @Nullable ServerInstance getInstance(String handle) {
return cache.get(handle);
}
private ServerInstance toInstance(Document doc) {
return new ServerInstance(
doc.getString("handle"),
doc.getString("template"),
doc.getInteger("port")
);
}
}

View file

@ -2,6 +2,7 @@ package de.kentoj.scrow.bukkit.instancemanager.command;
import de.kentoj.kencommandapi.api.node.CommandNode; import de.kentoj.kencommandapi.api.node.CommandNode;
import de.kentoj.kencommandapi.api.node.RootCommandNode; import de.kentoj.kencommandapi.api.node.RootCommandNode;
import de.kentoj.scrow.bukkit.instancemanager.cache.InstanceCache;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -10,12 +11,12 @@ import org.bukkit.command.CommandSender;
@NoArgsConstructor(access = AccessLevel.NONE) @NoArgsConstructor(access = AccessLevel.NONE)
public class InstanceCommand { public class InstanceCommand {
public static RootCommandNode<CommandSender> create() { public static RootCommandNode<CommandSender> create(InstanceCache instanceCache) {
var style = new ScrowMessageStyle("server-manager", NamedTextColor.RED); var style = new ScrowMessageStyle("server-manager", NamedTextColor.RED);
RootCommandNode<CommandSender> rootNode = CommandNode.rootNode(style, "instance", "server-manager"); RootCommandNode<CommandSender> rootNode = CommandNode.rootNode(style, "instance", "server-manager");
rootNode.addLiteral(new InstanceListLiteral(style).getNode()); rootNode.addLiteral(new InstanceListLiteral(style).getNode());
rootNode.addLiteral(new InstanceDeployLiteral(style).getLiteral()); rootNode.addLiteral(new InstanceDeployLiteral(style).getLiteral());
rootNode.addLiteral(new InstanceDestroyLiteral(style).getLiteral()); rootNode.addLiteral(new InstanceDestroyLiteral(instanceCache, style).getLiteral());
return rootNode; return rootNode;
} }
} }

View file

@ -8,6 +8,7 @@ import de.kentoj.kencommandapi.api.invocation.CommandContext;
import de.kentoj.kencommandapi.api.invocation.CommandExecutor; import de.kentoj.kencommandapi.api.invocation.CommandExecutor;
import de.kentoj.kencommandapi.api.node.CommandNode; import de.kentoj.kencommandapi.api.node.CommandNode;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
import de.kentoj.scrow.bukkit.instancemanager.cache.InstanceCache;
import de.kentoj.scrow.bukkit.scheduler.Tasks; import de.kentoj.scrow.bukkit.scheduler.Tasks;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import de.kentoj.scrowlib.instancemanager.ServerInstance; import de.kentoj.scrowlib.instancemanager.ServerInstance;
@ -23,16 +24,13 @@ public class InstanceDestroyLiteral implements CommandExecutor<CommandSender> {
private final CommandArgument<CommandSender, String> handleArg; private final CommandArgument<CommandSender, String> handleArg;
private final ScrowMessageStyle style; private final ScrowMessageStyle style;
public InstanceDestroyLiteral(ScrowMessageStyle style) { public InstanceDestroyLiteral(InstanceCache cache, ScrowMessageStyle style) {
this.style = style; this.style = style;
handleArg = CommandArgument.arg("handle", new StringArgumentType<>()); handleArg = CommandArgument.arg("handle", new StringArgumentType<>());
handleArg.setSuggestionProvider(ctx -> handleArg.setSuggestionProvider(ctx -> cache.getInstances().stream()
Tasks.supplyAsync(() -> ScrowAPI.getInstanceManager().getInstances().stream() .map(ServerInstance::getHandle)
.map(ServerInstance::getHandle) .toList());
.toList())
.toFuture());
literal = CommandNode.node("destroy"); literal = CommandNode.node("destroy");
literal.addArgument(handleArg); literal.addArgument(handleArg);
literal.setExecutor(this); literal.setExecutor(this);

View file

@ -1,4 +1,4 @@
package de.kentoj.scrow.bukkit.server; package de.kentoj.scrow.bukkit.instancemanager.command;
import com.leakyabstractions.result.api.Result; import com.leakyabstractions.result.api.Result;
import com.leakyabstractions.result.core.Results; import com.leakyabstractions.result.core.Results;

View file

@ -1,4 +1,4 @@
package de.kentoj.scrow.bukkit.server; package de.kentoj.scrow.bukkit.instancemanager.command;
import com.leakyabstractions.result.api.Result; import com.leakyabstractions.result.api.Result;
import com.leakyabstractions.result.core.Results; import com.leakyabstractions.result.core.Results;

View file

@ -21,7 +21,7 @@ dependencies {
api("org.mongodb:bson:5.8.0") api("org.mongodb:bson:5.8.0")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core
api("de.kentoj.scrow:kencommandapi-core:0.28") api("de.kentoj.scrow:kencommandapi-core:0.30")
compileOnly("net.kyori:adventure-api:5.2.0") compileOnly("net.kyori:adventure-api:5.2.0")
} }

View file

@ -24,9 +24,9 @@ dependencies {
api("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT") api("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-core
api("de.kentoj.scrow:kencommandapi-core:0.28") api("de.kentoj.scrow:kencommandapi-core:0.30")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-velocity // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-velocity
api("de.kentoj.scrow:kencommandapi-velocity:0.28") api("de.kentoj.scrow:kencommandapi-velocity:0.30")
} }
publishing { publishing {

View file

@ -25,6 +25,9 @@ dependencies {
// https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine // https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine
implementation("com.github.ben-manes.caffeine:caffeine:3.2.4") implementation("com.github.ben-manes.caffeine:caffeine:3.2.4")
// https://mvnrepository.com/artifact/org.postgresql/postgresql
implementation("org.postgresql:postgresql:42.7.12")
} }
tasks.build { tasks.build {

View file

@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.Jdbi;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
@NoArgsConstructor(access = AccessLevel.NONE) @NoArgsConstructor(access = AccessLevel.NONE)
public class ScrowAPISurface { public class ScrowAPISurface {
@ -30,7 +31,14 @@ public class ScrowAPISurface {
} }
if (enableDatabase) { if (enableDatabase) {
ScrowAPI.setJdbi(Jdbi.create(EnvUtils.envOrThrow("HOST_POSTGRES"))); try {
Class.forName("org.postgresql.Driver", true, ScrowAPISurface.class.getClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
var props = new Properties();
props.setProperty("user", "postgres");
ScrowAPI.setJdbi(Jdbi.create(EnvUtils.envOrThrow("HOST_POSTGRES"), props));
} }
ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.getMessageBroker())); ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.getMessageBroker()));