.
This commit is contained in:
parent
ea6ae529cc
commit
7040a6ce1e
20 changed files with 135 additions and 83 deletions
29
.idea/workspace.xml
generated
29
.idea/workspace.xml
generated
|
|
@ -5,38 +5,25 @@
|
|||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<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 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 afterPath="$PROJECT_DIR$/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/cache/InstanceCache.java" 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
TODO
|
||||
- cleanup nats
|
||||
- timeout/error handling with reactive
|
||||
- /friend add command is behaving weird: silent return no error
|
||||
- improve error handling in Task ig
|
||||
- try with InMemory db and debug postgres implementation
|
||||
- logging in general, log some exceptions to game chat
|
||||
- djb's multilogd for logging(?)
|
||||
- sleep
|
||||
|
||||
environment
|
||||
-----------
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ dependencies {
|
|||
// https://mvnrepository.com/artifact/io.nats/jnats
|
||||
api("io.nats:jnats:2.25.2")
|
||||
// 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
|
||||
api("de.kentoj.scrow:kencommandapi-bukkit:0.28")
|
||||
api("de.kentoj.scrow:kencommandapi-bukkit:0.30")
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package de.kentoj.scrow.bukkit.friends;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -11,7 +10,6 @@ public class OrderedUUIDPair {
|
|||
private final UUID second;
|
||||
|
||||
public OrderedUUIDPair(UUID uuid1, UUID uuid2) {
|
||||
Preconditions.checkArgument(uuid1 != uuid2, "UUIDPair may consist of identical UUIDs");
|
||||
if (uuid1.compareTo(uuid2) < 0) {
|
||||
this.first = uuid1;
|
||||
this.second = uuid2;
|
||||
|
|
|
|||
|
|
@ -1,22 +1,16 @@
|
|||
package de.kentoj.scrow.bukkit.scheduler;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
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
|
||||
* blocks until the subtask returns.
|
||||
|
|
@ -34,7 +28,14 @@ public class TaskImpl<T> implements Task<T> {
|
|||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,9 +26,11 @@ dependencies {
|
|||
// https://mvnrepository.com/artifact/io.nats/jnats
|
||||
implementation("io.nats:jnats:2.25.2")
|
||||
// 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
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -2,33 +2,30 @@ package de.kentoj.scrow.bukkit;
|
|||
|
||||
import de.kentoj.scrow.bukkit.economy.command.CoinsCommand;
|
||||
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.region.RegionPlayerTracker;
|
||||
import de.kentoj.scrow.bukkit.region.RegionTask;
|
||||
import de.kentoj.scrow.bukkit.server.LobbyCommand;
|
||||
import de.kentoj.scrow.bukkit.server.PlayCommand;
|
||||
import de.kentoj.scrow.bukkit.instancemanager.command.LobbyCommand;
|
||||
import de.kentoj.scrow.bukkit.instancemanager.command.PlayCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
public class CoreImplPlugin extends JavaPlugin {
|
||||
|
||||
public static boolean ENABLE_DATABASE = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
ScrowAPISurface.initScrowAPI(this, ENABLE_DATABASE);
|
||||
|
||||
ScrowAPISurface.initScrowAPI(this, true);
|
||||
{
|
||||
ScrowAPI.getCommandApi().register(new CoinsCommand().getRootNode());
|
||||
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 LobbyCommand().getRootNode());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,13 @@ import io.nats.client.Options;
|
|||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jdbi.v3.core.ConnectionFactory;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class ScrowAPISurface {
|
||||
|
|
@ -39,7 +43,14 @@ public class ScrowAPISurface {
|
|||
}
|
||||
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ public class FriendAddLiteral implements CommandExecutor<CommandSender> {
|
|||
var self = (Player) ctx.getSender();
|
||||
var other = ctx.getArg(playerArg);
|
||||
return Tasks.supplyAsync(() -> findAction(self, other)
|
||||
.mapSuccess(action -> {
|
||||
if (action == AddAction.SEND_REQUEST) sendRequest(self, other);
|
||||
else if (action == AddAction.ACCEPT_REQUEST) acceptRequest(self, other);
|
||||
return new Object();
|
||||
})
|
||||
).toFuture();
|
||||
.mapSuccess(action -> {
|
||||
if (action == AddAction.SEND_REQUEST) sendRequest(self, other);
|
||||
else if (action == AddAction.ACCEPT_REQUEST) acceptRequest(self, other);
|
||||
return new Object();
|
||||
}))
|
||||
.toFuture();
|
||||
}
|
||||
|
||||
private void sendRequest(Player self, OfflinePlayer other) {
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ public class PostgresFriendshipService implements FriendshipService {
|
|||
jdbi = ScrowAPI.getJdbi();
|
||||
jdbi.useHandle(h -> h.execute("""
|
||||
CREATE TABLE IF NOT EXISTS friendships (
|
||||
first_uuid UUID NOT NULL,
|
||||
second_uuid UUID NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
first_uuid UUID NOT NULL,
|
||||
second_uuid UUID NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
PRIMARY KEY (first_uuid, second_uuid),
|
||||
CONSTRAINT friendship_no_self_friendship
|
||||
CHECK (first_uuid <> second_uuid)
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ public class PostgresFriendRequestService implements FriendRequestService {
|
|||
jdbi = ScrowAPI.getJdbi();
|
||||
|
||||
jdbi.useHandle(h -> h.execute("""
|
||||
CREATE TABLE IF NOT EXISTS friend-requests (
|
||||
CREATE TABLE IF NOT EXISTS friendrequests (
|
||||
from_uuid UUID NOT NULL,
|
||||
to_uuid UUID NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
PRIMARY KEY (first_uuid, second_uuid),
|
||||
CONSTRAINT friendship_no_self_friendship
|
||||
CHECK (first_uuid <> second_uuid)
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
PRIMARY KEY (from_uuid, to_uuid),
|
||||
CONSTRAINT friendship_no_self_request
|
||||
CHECK (from_uuid <> to_uuid)
|
||||
)
|
||||
"""));
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
|
|||
public @Nullable FriendRequest getFriendRequest(UUID from, UUID to) {
|
||||
return jdbi.withHandle(h -> h.createQuery("""
|
||||
SELECT *
|
||||
FROM friend-requests
|
||||
FROM friendrequests
|
||||
WHERE from_uuid = :from AND to_uuid = :to
|
||||
""")
|
||||
.bind("from", from)
|
||||
|
|
@ -53,11 +53,12 @@ public class PostgresFriendRequestService implements FriendRequestService {
|
|||
@Override
|
||||
public boolean saveFriendRequest(FriendRequest friendRequest) {
|
||||
return jdbi.withHandle(h -> h.createUpdate("""
|
||||
INSERT INTO friend-requests (from_uuid, to_uuid, created_at)
|
||||
VALUES (:from, :to, :created_at)
|
||||
INSERT INTO friendrequests (from_uuid, to_uuid, created_at)
|
||||
VALUES (:from, :to, :createdAt)
|
||||
""")
|
||||
.bind("from", friendRequest.getFrom())
|
||||
.bind("to", friendRequest.getTo())
|
||||
.bind("createdAt", friendRequest.getCreatedAt())
|
||||
.execute() > 0);
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
|
|||
public List<FriendRequest> getFriendRequestsTo(UUID playerId) {
|
||||
return jdbi.withHandle(h -> h.createQuery("""
|
||||
SELECT *
|
||||
FROM friend-requests
|
||||
FROM friendrequests
|
||||
WHERE to_uuid = :to
|
||||
""")
|
||||
.bind("to", playerId)
|
||||
|
|
@ -77,7 +78,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
|
|||
public List<FriendRequest> getFriendRequestsFrom(UUID playerId) {
|
||||
return jdbi.withHandle(h -> h.createQuery("""
|
||||
SELECT *
|
||||
FROM friend-requests
|
||||
FROM friendrequests
|
||||
WHERE from_uuid = :from
|
||||
""")
|
||||
.bind("from", playerId)
|
||||
|
|
@ -89,7 +90,7 @@ public class PostgresFriendRequestService implements FriendRequestService {
|
|||
public boolean deleteFriendRequest(UUID from, UUID to) {
|
||||
return jdbi.withHandle(h -> h.createUpdate("""
|
||||
DELETE
|
||||
FROM friend-requests
|
||||
FROM friendrequests
|
||||
WHERE from_uuid = :from AND to_uuid = :to
|
||||
""")
|
||||
.bind("from", from)
|
||||
|
|
|
|||
44
core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/cache/InstanceCache.java
vendored
Normal file
44
core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/cache/InstanceCache.java
vendored
Normal 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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package de.kentoj.scrow.bukkit.instancemanager.command;
|
|||
|
||||
import de.kentoj.kencommandapi.api.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.node.RootCommandNode;
|
||||
import de.kentoj.scrow.bukkit.instancemanager.cache.InstanceCache;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
|
@ -10,12 +11,12 @@ import org.bukkit.command.CommandSender;
|
|||
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class InstanceCommand {
|
||||
public static RootCommandNode<CommandSender> create() {
|
||||
public static RootCommandNode<CommandSender> create(InstanceCache instanceCache) {
|
||||
var style = new ScrowMessageStyle("server-manager", NamedTextColor.RED);
|
||||
RootCommandNode<CommandSender> rootNode = CommandNode.rootNode(style, "instance", "server-manager");
|
||||
rootNode.addLiteral(new InstanceListLiteral(style).getNode());
|
||||
rootNode.addLiteral(new InstanceDeployLiteral(style).getLiteral());
|
||||
rootNode.addLiteral(new InstanceDestroyLiteral(style).getLiteral());
|
||||
rootNode.addLiteral(new InstanceDestroyLiteral(instanceCache, style).getLiteral());
|
||||
return rootNode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import de.kentoj.kencommandapi.api.invocation.CommandContext;
|
|||
import de.kentoj.kencommandapi.api.invocation.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.node.CommandNode;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.instancemanager.cache.InstanceCache;
|
||||
import de.kentoj.scrow.bukkit.scheduler.Tasks;
|
||||
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
|
||||
import de.kentoj.scrowlib.instancemanager.ServerInstance;
|
||||
|
|
@ -23,16 +24,13 @@ public class InstanceDestroyLiteral implements CommandExecutor<CommandSender> {
|
|||
private final CommandArgument<CommandSender, String> handleArg;
|
||||
private final ScrowMessageStyle style;
|
||||
|
||||
public InstanceDestroyLiteral(ScrowMessageStyle style) {
|
||||
public InstanceDestroyLiteral(InstanceCache cache, ScrowMessageStyle style) {
|
||||
this.style = style;
|
||||
|
||||
handleArg = CommandArgument.arg("handle", new StringArgumentType<>());
|
||||
handleArg.setSuggestionProvider(ctx ->
|
||||
Tasks.supplyAsync(() -> ScrowAPI.getInstanceManager().getInstances().stream()
|
||||
.map(ServerInstance::getHandle)
|
||||
.toList())
|
||||
.toFuture());
|
||||
|
||||
handleArg.setSuggestionProvider(ctx -> cache.getInstances().stream()
|
||||
.map(ServerInstance::getHandle)
|
||||
.toList());
|
||||
literal = CommandNode.node("destroy");
|
||||
literal.addArgument(handleArg);
|
||||
literal.setExecutor(this);
|
||||
|
|
|
|||
|
|
@ -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.core.Results;
|
||||
|
|
@ -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.core.Results;
|
||||
|
|
@ -21,7 +21,7 @@ dependencies {
|
|||
api("org.mongodb:bson:5.8.0")
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ dependencies {
|
|||
api("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
|
||||
|
||||
// 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
|
||||
api("de.kentoj.scrow:kencommandapi-velocity:0.28")
|
||||
api("de.kentoj.scrow:kencommandapi-velocity:0.30")
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ dependencies {
|
|||
|
||||
// https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
|
|||
import org.jdbi.v3.core.Jdbi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class ScrowAPISurface {
|
||||
|
|
@ -30,7 +31,14 @@ public class ScrowAPISurface {
|
|||
}
|
||||
|
||||
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()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue