diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..cf247ce
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 44f08f3..59049e3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,37 +5,27 @@
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
@@ -43,8 +33,9 @@
-
+
+
@@ -75,6 +66,9 @@
+
+
+
@@ -104,22 +98,22 @@
-
+
-
+
-
+
-
+
@@ -162,15 +156,21 @@
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
@@ -229,10 +253,54 @@
false
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+ false
+
+
+
+
+
+
@@ -251,72 +319,6 @@
false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- true
- false
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- true
- false
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- true
- false
- false
-
-
@@ -331,10 +333,10 @@
-
-
-
-
+
+
+
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8296765
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+all:
+ ./gradlew build
+
+install:
+ cp core-bukkit-impl/build/libs/core-bukkit-impl-all.jar /var/scrow/ /var/scrow/
diff --git a/core-bukkit-api/build.gradle.kts b/core-bukkit-api/build.gradle.kts
index 1057536..033c45a 100644
--- a/core-bukkit-api/build.gradle.kts
+++ b/core-bukkit-api/build.gradle.kts
@@ -18,15 +18,14 @@ repositories {
dependencies {
api(project(":core-lib"))
- api("io.papermc.paper:paper-api:1.21.11-rc3-R0.1-SNAPSHOT")
+ compileOnly("io.papermc.paper:paper-api:1.21.11-rc3-R0.1-SNAPSHOT")
// 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.23")
+ api("de.kentoj.scrow:kencommandapi-core:0.28")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-bukkit
- api("de.kentoj.scrow:kencommandapi-bukkit:0.23")
+ api("de.kentoj.scrow:kencommandapi-bukkit:0.28")
}
publishing {
diff --git a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java
index cca3405..4050735 100644
--- a/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java
+++ b/core-bukkit-api/src/main/java/de/kentoj/scrow/bukkit/ScrowAPI.java
@@ -7,6 +7,7 @@ import de.kentoj.scrow.bukkit.misc.EconomyService;
import de.kentoj.scrow.bukkit.misc.PlayerManager;
import de.kentoj.scrow.bukkit.region.RegionManager;
import de.kentoj.scrowlib.instancemanager.InstanceManager;
+import de.kentoj.scrowlib.messaging.MessageBroker;
import io.nats.client.Connection;
import lombok.AccessLevel;
import lombok.Getter;
@@ -33,7 +34,7 @@ public class ScrowAPI {
@Getter
private static FriendRequestService friendRequestService;
@Getter
- private static Connection nats;
+ private static MessageBroker messageBroker;
@Getter
private static InstanceManager instanceManager;
@Getter
@@ -64,8 +65,8 @@ public class ScrowAPI {
}
@ApiStatus.Internal
- public static void setNats(Connection nats) {
- ScrowAPI.nats = nats;
+ public static void setMessageBroker(MessageBroker messageBroker) {
+ ScrowAPI.messageBroker = messageBroker;
}
@ApiStatus.Internal
diff --git a/core-bukkit-impl/build.gradle.kts b/core-bukkit-impl/build.gradle.kts
index ee8669b..070114d 100644
--- a/core-bukkit-impl/build.gradle.kts
+++ b/core-bukkit-impl/build.gradle.kts
@@ -18,10 +18,17 @@ repositories {
}
dependencies {
+ compileOnly("io.papermc.paper:paper-api:1.21.11-rc3-R0.1-SNAPSHOT")
implementation(project(":core-bukkit-api"))
+ // https://mvnrepository.com/artifact/org.mongodb/bson
+ implementation("org.mongodb:bson:5.8.0")
+ // 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.23")
+ implementation("de.kentoj.scrow:kencommandapi-core:0.28")
+ // http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-bukkit
+ implementation("de.kentoj.scrow:kencommandapi-bukkit:0.28")
}
tasks {
@@ -37,9 +44,7 @@ tasks {
tasks.processResources {
filesMatching("plugin.yml") {
expand(
- mapOf(
- "version" to project.version.toString()
- )
+ mapOf("version" to project.version.toString())
)
}
}
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java
index 4c465c1..260a5f0 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/CoreImplPlugin.java
@@ -9,6 +9,7 @@ import de.kentoj.scrow.bukkit.server.LobbyCommand;
import de.kentoj.scrow.bukkit.server.PlayCommand;
import org.bukkit.plugin.java.JavaPlugin;
+import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@@ -34,12 +35,12 @@ public class CoreImplPlugin extends JavaPlugin {
new RegionTask(new RegionPlayerTracker()).runTaskTimer(this, 10, 10);
- registerServer();
+ // TODO/FIXME
+ //registerServer();
}
private void registerServer() {
- var opts = new OpenOption[]{StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE, StandardOpenOption.WRITE};
- try (var file = FileChannel.open(Path.of("/proc/self/fd/3"), opts)) {
+ try (var file = FileChannel.open(Path.of("/proc/self/fd/4"), StandardOpenOption.WRITE)) {
//noinspection ResultOfMethodCallIgnored
file.write(ByteBuffer.wrap(new byte[]{'\n'}));
} catch (IOException e) {
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java
index bc94557..9ad8344 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/ScrowAPISurface.java
@@ -7,8 +7,10 @@ import de.kentoj.scrow.bukkit.friends.friendship.InMemoryFriendshipService;
import de.kentoj.scrow.bukkit.friends.friendship.PostgresFriendshipService;
import de.kentoj.scrow.bukkit.friends.request.InMemoryFriendRequestService;
import de.kentoj.scrow.bukkit.friends.request.PostgresFriendRequestService;
+import de.kentoj.scrow.bukkit.playermanager.PlayerManagerImpl;
import de.kentoj.scrow.bukkit.region.RegionManagerImpl;
import de.kentoj.scrowlib.instancemanager.InstanceManagerImpl;
+import de.kentoj.scrowlib.messaging.MessageBroker;
import de.kentoj.scrowlib.utils.EnvUtils;
import io.nats.client.Nats;
import io.nats.client.Options;
@@ -31,7 +33,7 @@ public class ScrowAPISurface {
.server(natsHost)
.pedantic()
.build();
- ScrowAPI.setNats(Nats.connect(options));
+ ScrowAPI.setMessageBroker(new MessageBroker(Nats.connect(options)));
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
@@ -40,9 +42,10 @@ public class ScrowAPISurface {
ScrowAPI.setJdbi(Jdbi.create(EnvUtils.envOrThrow("HOST_POSTGRES")));
}
+ ScrowAPI.setPlayerManager(new PlayerManagerImpl());
ScrowAPI.setRegionManager(new RegionManagerImpl());
ScrowAPI.setCommandApi(new CommandAPI(plugin));
- ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.getNats()));
+ ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.getMessageBroker()));
ScrowAPI.setEconomyService(ScrowAPI.getJdbi() != null ?
new PostgresEconomyService() : new InMemoryEconomyService());
ScrowAPI.setFriendRequestService(ScrowAPI.getJdbi() != null ?
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsCommand.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsCommand.java
index 2711cce..a9ae259 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsCommand.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsCommand.java
@@ -13,7 +13,6 @@ import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
-import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -29,6 +28,7 @@ public class CoinsCommand implements CommandExecutor {
style = ScrowMessageStyle.GENERIC;
rootNode = CommandNode.rootNode(style, "coins", "bal", "balance");
rootNode.setPermission("command.coins.get.self");
+ rootNode.setExecutor(this);
var setLiteral = new CoinsSetLiteral(style).getLiteral();
setLiteral.setPermission("command.coins.set");
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsGetLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsGetLiteral.java
index 3c5dd08..ee4c0e1 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsGetLiteral.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/economy/command/CoinsGetLiteral.java
@@ -30,7 +30,7 @@ public class CoinsGetLiteral implements CommandExecutor {
playerArg = CommandArgument.arg("player", OfflinePlayerArgumentType.getInstance());
playerArg.setDefaultValueProvider(sender -> (OfflinePlayer) sender);
- literal = CommandNode.node("set");
+ literal = CommandNode.node("get");
literal.addArgument(playerArg);
literal.setExecutor(this);
}
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java
index ab5c154..601147d 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendAddLiteral.java
@@ -74,9 +74,9 @@ public class FriendAddLiteral implements CommandExecutor {
.saveFriendship(new FriendshipImpl(self.getUniqueId(), other.getUniqueId(), Instant.now()))
)))
.runSync(() -> {
- self.sendMessage(style.ok("You are now friends with " + other.getName()));
+ self.sendMessage(style.ok("You are now friends with " + other.getName() + "."));
if (other.getPlayer() != null)
- other.getPlayer().sendMessage(style.ok("You are now friends with " + self.getName()));
+ other.getPlayer().sendMessage(style.ok("You are now friends with " + self.getName() + "."));
});
}
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java
index 8b3d0b0..6bc6b30 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRemoveLiteral.java
@@ -39,8 +39,8 @@ public class FriendRemoveLiteral implements CommandExecutor {
ScrowAPI.getFriendshipService().deleteFriendship(friend.getUniqueId(), player.getUniqueId()))
.>mapSync(deleted -> {
if (!deleted)
- return Results.failure("You are not friends with " + friend.getName());
- ctx.getSender().sendMessage(style.ok("You have ended the friendship with " + friend.getName()));
+ return Results.failure("You are not friends with " + friend.getName() + ".");
+ ctx.getSender().sendMessage(style.ok("You have ended the friendship with " + friend.getName() + "."));
return Results.success(new Object());
}).toFuture();
}
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java
index 0eb2602..62948d1 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/friends/command/FriendRequestsLiteral.java
@@ -30,7 +30,7 @@ public class FriendRequestsLiteral implements CommandExecutor {
public FriendRequestsLiteral(ScrowMessageStyle style) {
this.style = style;
- literal = CommandNode.node("requests", "list-requests");
+ literal = CommandNode.node("requests");
literal.setExecutor(this);
}
@@ -40,7 +40,7 @@ public class FriendRequestsLiteral implements CommandExecutor {
return Tasks.supplyAsync(() ->
ScrowAPI.getFriendRequestService().getFriendRequestsTo(sender.getUniqueId()))
.>mapAsync(list -> {
- if (list.isEmpty()) return Results.failure("You have no friend requests");
+ if (list.isEmpty()) return Results.failure("You have no friend requests.");
var requesters = list.stream().sorted(this::compareByAge).map(fr -> Bukkit.getOfflinePlayer(fr.getFrom()).getName());
sender.sendMessage(formatList(requesters.toList()));
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDeployLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDeployLiteral.java
index 06c46ab..30b3c73 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDeployLiteral.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDeployLiteral.java
@@ -35,11 +35,11 @@ public class InstanceDeployLiteral implements CommandExecutor {
@Override
public CompletableFuture> execute(CommandContext ctx) {
var template = ctx.getArg(templateArg);
- ctx.getSender().sendMessage(style.ok("Deploying instance... this may take a while"));
+ ctx.getSender().sendMessage(style.ok("Deploying instance... this may take a while."));
return Tasks.supplyAsync(() ->
ScrowAPI.getInstanceManager().deployInstance(template))
.>mapSync(instance -> {
- ctx.getSender().sendMessage(style.ok("Deployed instance of " + template + " with handle " + instance.getHandle()));
+ ctx.getSender().sendMessage(style.ok("Deployed instance of " + template + " with handle " + instance.getHandle() + "."));
// FIXME handle unknown server
return Results.success(new Object());
}).toFuture();
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java
index fc2063c..02de206 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/instancemanager/command/InstanceDestroyLiteral.java
@@ -44,8 +44,8 @@ public class InstanceDestroyLiteral implements CommandExecutor {
return Tasks.supplyAsync(() -> ScrowAPI.getInstanceManager().destroyInstance(handle))
.>mapSync(found -> {
if (!found)
- return Results.failure("No instance with that handle found");
- ctx.getSender().sendMessage(style.ok("Destroyed server with handle " + handle));
+ return Results.failure("No instance with that handle found.");
+ ctx.getSender().sendMessage(style.ok("Destroyed server with handle " + handle + "."));
return Results.success(new Object());
}).toFuture();
}
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/playermanager/PlayerManagerImpl.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/playermanager/PlayerManagerImpl.java
index 27434a5..d2f501e 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/playermanager/PlayerManagerImpl.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/playermanager/PlayerManagerImpl.java
@@ -1,5 +1,6 @@
package de.kentoj.scrow.bukkit.playermanager;
+import de.kentoj.scrow.bukkit.ScrowAPI;
import de.kentoj.scrow.bukkit.misc.PlayerManager;
import de.kentoj.scrowlib.messaging.MessageBroker;
import de.kentoj.scrowlib.utils.ResultUtils;
@@ -11,7 +12,7 @@ import java.util.UUID;
@RequiredArgsConstructor
public class PlayerManagerImpl implements PlayerManager {
- private final MessageBroker messageBroker;
+ private final MessageBroker messageBroker = ScrowAPI.getMessageBroker();
@Override
public void sendPlayer(UUID playerId, String instanceHandle) {
diff --git a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/PlayCommand.java b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/PlayCommand.java
index fd217a1..28e7833 100644
--- a/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/PlayCommand.java
+++ b/core-bukkit-impl/src/main/java/de/kentoj/scrow/bukkit/server/PlayCommand.java
@@ -44,7 +44,7 @@ public class PlayCommand implements CommandExecutor {
.findFirst()
.orElse(null);
if (instance == null)
- return Results.failure("No instance for " + gamemode + " found");
+ return Results.failure("No instance for " + gamemode + " found.");
return Results.ofCallable(() -> {
ScrowAPI.getPlayerManager().sendPlayer(player.getUniqueId(), instance.getHandle());
diff --git a/core-lib/build.gradle.kts b/core-lib/build.gradle.kts
index 29e0c68..8eaf8dd 100644
--- a/core-lib/build.gradle.kts
+++ b/core-lib/build.gradle.kts
@@ -15,15 +15,15 @@ repositories {
dependencies {
// https://mvnrepository.com/artifact/io.nats/jnats
- implementation("io.nats:jnats:2.25.2")
api("io.nats:jnats:2.25.2")
// https://mvnrepository.com/artifact/org.mongodb/bson
- implementation("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
- api("de.kentoj.scrow:kencommandapi-core:0.23")
+ api("de.kentoj.scrow:kencommandapi-core:0.28")
+
+ compileOnly("net.kyori:adventure-api:5.2.0")
}
publishing {
diff --git a/core-lib/src/main/java/de/kentoj/scrowlib/convention/ScrowMessageStyle.java b/core-lib/src/main/java/de/kentoj/scrowlib/convention/ScrowMessageStyle.java
index 3776bb7..9f4e2f3 100644
--- a/core-lib/src/main/java/de/kentoj/scrowlib/convention/ScrowMessageStyle.java
+++ b/core-lib/src/main/java/de/kentoj/scrowlib/convention/ScrowMessageStyle.java
@@ -7,11 +7,9 @@ import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
-import java.util.List;
-
public class ScrowMessageStyle implements MessageStyle {
- public static ScrowMessageStyle GENERIC = new ScrowMessageStyle("Scrow", NamedTextColor.WHITE);
+ public static ScrowMessageStyle GENERIC = new ScrowMessageStyle("Scrow", TextColor.color(0xe5377f));
@Getter
private final Component prefix;
@@ -24,8 +22,7 @@ public class ScrowMessageStyle implements MessageStyle {
this.prefixText = prefixText;
this.prefixColor = prefixColor;
this.prefix = Component.text(prefixText)
- .color(prefixColor)
- .decorate(TextDecoration.BOLD);
+ .color(prefixColor);
}
@Override
diff --git a/core-lib/src/main/java/de/kentoj/scrowlib/instancemanager/InstanceManagerImpl.java b/core-lib/src/main/java/de/kentoj/scrowlib/instancemanager/InstanceManagerImpl.java
index 67608c6..96ed135 100644
--- a/core-lib/src/main/java/de/kentoj/scrowlib/instancemanager/InstanceManagerImpl.java
+++ b/core-lib/src/main/java/de/kentoj/scrowlib/instancemanager/InstanceManagerImpl.java
@@ -1,7 +1,7 @@
package de.kentoj.scrowlib.instancemanager;
import de.kentoj.scrowlib.messaging.MessageBroker;
-import io.nats.client.Connection;
+import lombok.RequiredArgsConstructor;
import org.bson.Document;
import org.jspecify.annotations.Nullable;
@@ -9,14 +9,11 @@ import java.util.List;
import static de.kentoj.scrowlib.utils.ResultUtils.unwrap;
+@RequiredArgsConstructor
public class InstanceManagerImpl implements InstanceManager {
private final MessageBroker messageBroker;
- public InstanceManagerImpl(Connection natsCon) {
- messageBroker = new MessageBroker(natsCon);
- }
-
@Override
public ServerInstance deployInstance(String template) {
var result = messageBroker.request("instance.deploy", new Document("template", template));
diff --git a/core-lib/src/main/java/de/kentoj/scrowlib/messaging/MessageBroker.java b/core-lib/src/main/java/de/kentoj/scrowlib/messaging/MessageBroker.java
index 72a8458..9f272a8 100644
--- a/core-lib/src/main/java/de/kentoj/scrowlib/messaging/MessageBroker.java
+++ b/core-lib/src/main/java/de/kentoj/scrowlib/messaging/MessageBroker.java
@@ -8,6 +8,7 @@ import org.bson.Document;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.function.Consumer;
@Slf4j
public class MessageBroker {
@@ -26,6 +27,15 @@ public class MessageBroker {
nats.publish(subject, ResultRepository.toBytes(result));
}
+ /**
+ * subscribes to a subject, handler may run asynchronously
+ */
+ public void subscribe(String subject, Consumer handler) {
+ dispatcher.subscribe(subject, msg -> {
+ executor.submit(() -> handler.accept(DocumentRepository.fromMessage(msg)));
+ });
+ }
+
public void handle(String subject, RequestHandler handler) {
dispatcher.subscribe(subject, msg -> {
if (msg.getReplyTo() == null) {
diff --git a/core-velocity-api/build.gradle.kts b/core-velocity-api/build.gradle.kts
index 3f20c57..95137c0 100644
--- a/core-velocity-api/build.gradle.kts
+++ b/core-velocity-api/build.gradle.kts
@@ -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.23")
+ api("de.kentoj.scrow:kencommandapi-core:0.28")
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-velocity
- api("de.kentoj.scrow:kencommandapi-velocity:0.23")
+ api("de.kentoj.scrow:kencommandapi-velocity:0.28")
}
publishing {
diff --git a/core-velocity-api/src/main/java/de/kentoj/scrow/velocity/ScrowAPI.java b/core-velocity-api/src/main/java/de/kentoj/scrow/velocity/ScrowAPI.java
index c59ae8e..e4096f5 100644
--- a/core-velocity-api/src/main/java/de/kentoj/scrow/velocity/ScrowAPI.java
+++ b/core-velocity-api/src/main/java/de/kentoj/scrow/velocity/ScrowAPI.java
@@ -2,7 +2,7 @@ package de.kentoj.scrow.velocity;
import de.kentoj.kencommandapi.CommandAPI;
import de.kentoj.scrowlib.instancemanager.InstanceManager;
-import io.nats.client.Connection;
+import de.kentoj.scrowlib.messaging.MessageBroker;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -17,7 +17,7 @@ public class ScrowAPI {
@Getter
private static CommandAPI commandApi;
@Getter
- private static Connection nats;
+ private static MessageBroker messageBroker;
@Getter
private static InstanceManager instanceManager;
@@ -27,8 +27,8 @@ public class ScrowAPI {
}
@ApiStatus.Internal
- public static void setNats(Connection nats) {
- ScrowAPI.nats = nats;
+ public static void setMessageBroker(MessageBroker messageBroker) {
+ ScrowAPI.messageBroker = messageBroker;
}
@ApiStatus.Internal
diff --git a/core-velocity-impl/build.gradle.kts b/core-velocity-impl/build.gradle.kts
index 7744f3a..28e32e6 100644
--- a/core-velocity-impl/build.gradle.kts
+++ b/core-velocity-impl/build.gradle.kts
@@ -17,7 +17,9 @@ repositories {
}
dependencies {
- implementation(project(":core-velocity-api"))
+ implementation(project(":core-velocity-api")) {
+ isTransitive = true
+ }
// https://docs.papermc.io/velocity/dev/creating-your-first-plugin/
annotationProcessor("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
@@ -25,6 +27,10 @@ dependencies {
implementation("com.github.ben-manes.caffeine:caffeine:3.2.4")
}
+tasks.build {
+ dependsOn("shadowJar")
+}
+
val generateBuildInfo by tasks.registering {
val outputDir = layout.buildDirectory.dir("generated/sources/buildInfo")
outputs.dir(outputDir)
diff --git a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/CoreVelocityPlugin.java b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/CoreVelocityPlugin.java
index 5ad2d34..b5dbfbc 100644
--- a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/CoreVelocityPlugin.java
+++ b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/CoreVelocityPlugin.java
@@ -23,7 +23,6 @@ import net.kyori.adventure.text.format.NamedTextColor;
)
@Log
public class CoreVelocityPlugin {
-
@Inject
public CoreVelocityPlugin(ProxyServer server) {
ScrowAPISurface.initScrowAPI(server, true);
@@ -38,8 +37,8 @@ public class CoreVelocityPlugin {
cmds.register(new OnlineCommand(server).getRootNode());
}
- var registerWatchdog = new ServerRegisterWatchdog(ScrowAPI.getNats(), server);
- var sendPlayerWatchdog = new SendPlayerWatchdog(ScrowAPI.getNats(), server);
+ var registerWatchdog = new ServerRegisterWatchdog(ScrowAPI.getMessageBroker(), server);
+ var sendPlayerWatchdog = new SendPlayerWatchdog(ScrowAPI.getMessageBroker(), server);
registerWatchdog.listen();
sendPlayerWatchdog.listen();
}
diff --git a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java
index 17209f2..46a83c2 100644
--- a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java
+++ b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/ScrowAPISurface.java
@@ -4,6 +4,7 @@ import com.velocitypowered.api.proxy.ProxyServer;
import de.kentoj.kencommandapi.CommandAPI;
import de.kentoj.scrow.velocity.ScrowAPI;
import de.kentoj.scrowlib.instancemanager.InstanceManagerImpl;
+import de.kentoj.scrowlib.messaging.MessageBroker;
import de.kentoj.scrowlib.utils.EnvUtils;
import io.nats.client.Nats;
import io.nats.client.Options;
@@ -23,7 +24,7 @@ public class ScrowAPISurface {
.server(natsHost)
.pedantic()
.build();
- ScrowAPI.setNats(Nats.connect(options));
+ ScrowAPI.setMessageBroker(new MessageBroker(Nats.connect(options)));
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
@@ -32,7 +33,7 @@ public class ScrowAPISurface {
ScrowAPI.setJdbi(Jdbi.create(EnvUtils.envOrThrow("HOST_POSTGRES")));
}
- ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.getNats()));
+ ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.getMessageBroker()));
ScrowAPI.setCommandApi(new CommandAPI(server));
}
diff --git a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/command/OnlineCommand.java b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/command/OnlineCommand.java
index 9cf0050..2cac603 100644
--- a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/command/OnlineCommand.java
+++ b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/command/OnlineCommand.java
@@ -8,18 +8,16 @@ import de.kentoj.kencommandapi.api.invocation.CommandContext;
import de.kentoj.kencommandapi.api.invocation.SyncCommandExecutor;
import de.kentoj.kencommandapi.api.node.CommandNode;
import de.kentoj.kencommandapi.api.node.RootCommandNode;
-import de.kentoj.kencommandapi.api.platform.MessageStyle;
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import net.kyori.adventure.text.Component;
@RequiredArgsConstructor
public class OnlineCommand implements SyncCommandExecutor {
@Getter
private final RootCommandNode rootNode;
-
+ private final ScrowMessageStyle style = ScrowMessageStyle.GENERIC;
private final ProxyServer server;
public OnlineCommand(ProxyServer server) {
@@ -32,9 +30,9 @@ public class OnlineCommand implements SyncCommandExecutor {
public Result