This commit is contained in:
kento2 2026-08-06 22:05:43 +02:00
parent 2ea2eb5d1e
commit ad2717b6d2
48 changed files with 255 additions and 252 deletions

View file

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="run dev server" type="ShConfigurationType"> <configuration default="false" name="run dev server" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="bazel run //:dev-server" /> <option name="SCRIPT_TEXT" value="bazel run //dev-server:dev" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" /> <option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" /> <option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" /> <option name="SCRIPT_OPTIONS" value="" />

15
BUILD
View file

@ -1,15 +0,0 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
sh_binary(
name = "dev-server",
data = ["//core-bukkit:plugin"],
env = {
"MC_VERSION": "26.2",
"BUILT_PLUGIN": "bazel-bin/core-bukkit/plugin.jar",
},
args = [
"LuckPerms.jar=https://download.luckperms.net/1652/bukkit/loader/LuckPerms-Bukkit-5.5.65.jar",
"ViaVersion.jar=https://hangarcdn.papermc.io/plugins/ViaVersion/ViaVersion/versions/5.11.0/PAPER/ViaVersion-5.11.0.jar",
"ViaBackwards.jar=https://hangarcdn.papermc.io/plugins/ViaVersion/ViaBackwards/versions/5.11.0/PAPER/ViaBackwards-5.11.0.jar",
],
srcs = ["runDevServer.sh"],
)

View file

@ -16,7 +16,6 @@ maven.install(
"com.leakyabstractions:result-api:1.0.1.0", "com.leakyabstractions:result-api:1.0.1.0",
"org.jetbrains:annotations:26.0.2-1", "org.jetbrains:annotations:26.0.2-1",
"com.google.guava:guava:33.5.0-jre", "com.google.guava:guava:33.5.0-jre",
"org.projectlombok:lombok:1.18.46",
"org.slf4j:slf4j-api:2.0.18", "org.slf4j:slf4j-api:2.0.18",
"org.slf4j:slf4j-simple:2.0.18", "org.slf4j:slf4j-simple:2.0.18",
"net.kyori:adventure-api:5.2.0", "net.kyori:adventure-api:5.2.0",
@ -27,15 +26,15 @@ maven.install(
"org.jdbi:jdbi3-postgres:3.53.0", "org.jdbi:jdbi3-postgres:3.53.0",
"org.mongodb:bson:5.8.0", "org.mongodb:bson:5.8.0",
"io.nats:jnats:2.25.2", "io.nats:jnats:2.25.2",
"de.kentoj.scrow:kencommandapi-core:0.34-SNAPSHOT", "de.kentoj.scrow:kencommandapi-core:0.36-SNAPSHOT",
"de.kentoj.scrow:kencommandapi-bukkit:0.34-SNAPSHOT", "de.kentoj.scrow:kencommandapi-bukkit:0.36-SNAPSHOT",
"de.kentoj.scrow:kencommandapi-velocity:0.34-SNAPSHOT", "de.kentoj.scrow:kencommandapi-velocity:0.36-SNAPSHOT",
"io.papermc.paper:paper-api:[26.2.build,)", "io.papermc.paper:paper-api:[26.2.build,)",
"net.luckperms:api:5.5", "net.luckperms:api:5.5",
], ],
repositories = [ repositories = [
"https://repo.papermc.io/repository/maven-public/", "https://repo.papermc.io/repository/maven-public/",
"https://repo.lab0x13.site/snapshots", "https://git.lab0x13.site/api/packages/scrow/maven",
], ],
known_contributing_modules = ["protobuf"], known_contributing_modules = ["protobuf"],
fail_on_missing_checksum = False, # for kencommandapi fail_on_missing_checksum = False, # for kencommandapi

View file

@ -9,7 +9,6 @@ java_library(
deps = [ deps = [
"//core-lib:core", "//core-lib:core",
artifact("io.papermc.paper:paper-api"), artifact("io.papermc.paper:paper-api"),
artifact("org.projectlombok:lombok"),
artifact("de.kentoj.scrow:kencommandapi-bukkit"), artifact("de.kentoj.scrow:kencommandapi-bukkit"),
], ],
exports = [ exports = [

View file

@ -2,18 +2,15 @@ package de.kentoj.scrow.bukkit;
import de.kentoj.kencommandapi.CommandAPI; import de.kentoj.kencommandapi.CommandAPI;
import de.kentoj.scrow.bukkit.minigame.MinigameManager; import de.kentoj.scrow.bukkit.minigame.MinigameManager;
import de.kentoj.scrow.bukkit.region.RegionManager;
import de.kentoj.scrowlib.economy.EconomyService;
import de.kentoj.scrowlib.friends.FriendRequestService; import de.kentoj.scrowlib.friends.FriendRequestService;
import de.kentoj.scrowlib.friends.FriendshipService; import de.kentoj.scrowlib.friends.FriendshipService;
import de.kentoj.scrowlib.economy.EconomyService;
import de.kentoj.scrowlib.player.NetworkPlayer;
import de.kentoj.scrowlib.player.NetworkPlayerFactory;
import de.kentoj.scrow.bukkit.region.RegionManager;
import de.kentoj.scrowlib.instancemanager.InstanceManager; import de.kentoj.scrowlib.instancemanager.InstanceManager;
import de.kentoj.scrowlib.messaging.MessageBroker; import de.kentoj.scrowlib.messaging.MessageBroker;
import de.kentoj.scrowlib.player.NetworkPlayer;
import de.kentoj.scrowlib.player.NetworkPlayerFactory;
import de.kentoj.scrowlib.player.PlayerPrefixProvider; import de.kentoj.scrowlib.player.PlayerPrefixProvider;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -1,10 +1,9 @@
package de.kentoj.scrow.bukkit.minigame.lobby; package de.kentoj.scrow.bukkit.minigame.lobby;
import de.kentoj.scrow.bukkit.minigame.Minigame; import de.kentoj.scrow.bukkit.minigame.Minigame;
import de.kentoj.scrow.bukkit.minigame.phaseflow.LinearPhaseFlow;
import de.kentoj.scrow.bukkit.minigame.phase.CompositePhase; import de.kentoj.scrow.bukkit.minigame.phase.CompositePhase;
import de.kentoj.scrow.bukkit.minigame.phaseflow.LinearPhaseFlow;
import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext; import de.kentoj.scrow.bukkit.minigame.phaseflow.PhaseContext;
import lombok.Getter;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockExplodeEvent;

View file

@ -6,7 +6,6 @@ import de.kentoj.scrow.bukkit.minigame.PlayerManager;
import de.kentoj.scrow.bukkit.minigame.phase.PhaseFlow; import de.kentoj.scrow.bukkit.minigame.phase.PhaseFlow;
import de.kentoj.scrow.bukkit.minigame.phase.event.PhaseListeners; import de.kentoj.scrow.bukkit.minigame.phase.event.PhaseListeners;
import de.kentoj.scrow.bukkit.minigame.phase.event.PhaseListenersImpl; import de.kentoj.scrow.bukkit.minigame.phase.event.PhaseListenersImpl;
import lombok.RequiredArgsConstructor;
public class PhaseContext<T extends Minigame> { public class PhaseContext<T extends Minigame> {
private final T game; private final T game;

View file

@ -1,8 +1,6 @@
package de.kentoj.scrow.bukkit.scheduler; package de.kentoj.scrow.bukkit.scheduler;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.Arrays; import java.util.Arrays;

View file

@ -18,8 +18,6 @@ import de.kentoj.scrowlib.player.NetworkPlayerImpl;
import de.kentoj.scrowlib.player.PlayerPrefixProvider; import de.kentoj.scrowlib.player.PlayerPrefixProvider;
import io.nats.client.Nats; import io.nats.client.Nats;
import io.nats.client.Options; import io.nats.client.Options;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -30,11 +28,13 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
@NoArgsConstructor(access = AccessLevel.NONE)
public class ScrowAPISurface { public class ScrowAPISurface {
private static final Logger log = LoggerFactory.getLogger(ScrowAPISurface.class); private static final Logger log = LoggerFactory.getLogger(ScrowAPISurface.class);
private ScrowAPISurface() {
}
public static void initScrowAPI(Plugin plugin, PlayerPrefixProvider prefixProvider) { public static void initScrowAPI(Plugin plugin, PlayerPrefixProvider prefixProvider) {
ScrowAPI.setCorePlugin(plugin); ScrowAPI.setCorePlugin(plugin);

View file

@ -9,7 +9,6 @@ import de.kentoj.kencommandapi.api.platform.MessageStyle;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
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 lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -30,7 +29,7 @@ public final class CoinsCommand {
} }
public CompletableFuture<Result<Object, String>> execute(CommandContext<Player> ctx) { public CompletableFuture<Result<Object, String>> execute(CommandContext<Player> ctx) {
var player = ctx.getSender(); var player = ctx.sender();
return Tasks.supplyAsync(() -> return Tasks.supplyAsync(() ->
ScrowAPI.economyService().getCoins(player.getUniqueId())) ScrowAPI.economyService().getCoins(player.getUniqueId()))
.<Result<Object, String>>mapSync(amount -> { .<Result<Object, String>>mapSync(amount -> {

View file

@ -9,9 +9,7 @@ import de.kentoj.kencommandapi.api.platform.MessageStyle;
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType; import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
import de.kentoj.scrow.bukkit.scheduler.Tasks; import de.kentoj.scrow.bukkit.scheduler.Tasks;
import lombok.Getter;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -26,7 +24,7 @@ public final class CoinsGetLiteral {
this.style = style; this.style = style;
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>()) playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
.withDefaultValue(CommandContext::getSender) .withDefaultValue(CommandContext::sender)
.build(); .build();
literal = Literal.<Player>builder("get") literal = Literal.<Player>builder("get")
.withPermission("command.coins.get.others") .withPermission("command.coins.get.others")
@ -40,7 +38,7 @@ public final class CoinsGetLiteral {
return Tasks.supplyAsync(() -> return Tasks.supplyAsync(() ->
ScrowAPI.economyService().getCoins(player.getUniqueId())) ScrowAPI.economyService().getCoins(player.getUniqueId()))
.<Result<Object, String>>mapSync(amount -> { .<Result<Object, String>>mapSync(amount -> {
ctx.getSender().sendMessage(style.ok(player.getName() + " has " + amount + "$")); ctx.sender().sendMessage(style.ok(player.getName() + " has " + amount + "$"));
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();
} }

View file

@ -25,7 +25,7 @@ public final class CoinsSetLiteral {
CoinsSetLiteral(MessageStyle style) { CoinsSetLiteral(MessageStyle style) {
this.style = style; this.style = style;
playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>()) playerArg = CommandArgumentSpec.builder("player", new OfflinePlayerArgumentType<Player>())
.withDefaultValue(CommandContext::getSender) .withDefaultValue(CommandContext::sender)
.build(); .build();
amountArg = CommandArgumentSpec.builder("amount", new IntegerArgumentType<Player>()) amountArg = CommandArgumentSpec.builder("amount", new IntegerArgumentType<Player>())
.build(); .build();
@ -43,7 +43,7 @@ public final class CoinsSetLiteral {
return Tasks.runAsync(() -> return Tasks.runAsync(() ->
ScrowAPI.economyService().setCoins(player.getUniqueId(), amount)) ScrowAPI.economyService().setCoins(player.getUniqueId(), amount))
.<Result<Object, String>>supplySync(() -> { .<Result<Object, String>>supplySync(() -> {
ctx.getSender().sendMessage(style.ok(player.getName() + " now has " + amount + "$")); ctx.sender().sendMessage(style.ok(player.getName() + " now has " + amount + "$"));
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();
} }

View file

@ -14,7 +14,6 @@ import de.kentoj.scrowlib.friends.FriendRequestService;
import de.kentoj.scrowlib.friends.FriendshipService; import de.kentoj.scrowlib.friends.FriendshipService;
import de.kentoj.scrowlib.friends.friendship.FriendshipImpl; import de.kentoj.scrowlib.friends.friendship.FriendshipImpl;
import de.kentoj.scrowlib.friends.request.FriendRequestImpl; import de.kentoj.scrowlib.friends.request.FriendRequestImpl;
import lombok.Getter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -43,7 +42,7 @@ public final class FriendAddLiteral {
} }
private CompletableFuture<Result<Object, String>> execute(CommandContext<Player> ctx) { private CompletableFuture<Result<Object, String>> execute(CommandContext<Player> ctx) {
var self = ctx.getSender(); var self = ctx.sender();
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 -> {

View file

@ -3,8 +3,6 @@ package de.kentoj.scrow.bukkit.command.friends;
import de.kentoj.kencommandapi.api.literal.Literal; import de.kentoj.kencommandapi.api.literal.Literal;
import de.kentoj.kencommandapi.api.literal.RootLiteral; import de.kentoj.kencommandapi.api.literal.RootLiteral;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent;

View file

@ -7,7 +7,6 @@ import de.kentoj.kencommandapi.api.literal.Literal;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
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 lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
@ -33,7 +32,7 @@ public final class FriendListLiteral {
} }
private CompletableFuture<Result<Object, String>> displayFriendList(CommandContext<Player> ctx) { private CompletableFuture<Result<Object, String>> displayFriendList(CommandContext<Player> ctx) {
var sender = ctx.getSender(); var sender = ctx.sender();
return Tasks.supplyAsync(() -> return Tasks.supplyAsync(() ->
ScrowAPI.friendshipService().getFriendships(sender.getUniqueId())) ScrowAPI.friendshipService().getFriendships(sender.getUniqueId()))
.<Result<Object, String>>mapSync(friendships -> { .<Result<Object, String>>mapSync(friendships -> {

View file

@ -9,7 +9,6 @@ import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
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 lombok.Getter;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -34,11 +33,11 @@ public final class FriendRemoveLiteral {
private CompletableFuture<Result<Object, String>> removeFriend(CommandContext<Player> ctx) { private CompletableFuture<Result<Object, String>> removeFriend(CommandContext<Player> ctx) {
var friend = ctx.getArg(playerArg); var friend = ctx.getArg(playerArg);
return Tasks.supplyAsync(() -> return Tasks.supplyAsync(() ->
ScrowAPI.friendshipService().deleteFriendship(friend.getUniqueId(), ctx.getSender().getUniqueId())) ScrowAPI.friendshipService().deleteFriendship(friend.getUniqueId(), ctx.sender().getUniqueId()))
.<Result<Object, String>>mapSync(deleted -> { .<Result<Object, String>>mapSync(deleted -> {
if (!deleted) if (!deleted)
return Results.failure("You are not friends 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() + ".")); ctx.sender().sendMessage(style.ok("You have ended the friendship with " + friend.getName() + "."));
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();
} }

View file

@ -10,8 +10,6 @@ import de.kentoj.scrow.bukkit.ScrowAPI;
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.friends.FriendRequestService; import de.kentoj.scrowlib.friends.FriendRequestService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,15 +33,14 @@ public final class FriendRequestDeclineLiteral {
} }
private CompletableFuture<Result<Object, String>> declineFriendRequest(CommandContext<Player> ctx) { private CompletableFuture<Result<Object, String>> declineFriendRequest(CommandContext<Player> ctx) {
var self = ctx.getSender();
var other = ctx.getArg(playerArg); var other = ctx.getArg(playerArg);
return Tasks.supplyAsync(() -> return Tasks.supplyAsync(() ->
requestService.deleteFriendRequest(other.getUniqueId(), self.getUniqueId())) requestService.deleteFriendRequest(other.getUniqueId(), ctx.sender().getUniqueId()))
.<Result<Object, String>>mapSync(deleted -> { .<Result<Object, String>>mapSync(deleted -> {
if (!deleted) if (!deleted)
return Results.failure("There's no incoming friend request from " + other.getName() + "."); return Results.failure("There's no incoming friend request from " + other.getName() + ".");
self.sendMessage(style.ok("Friend request declined.")); ctx.sender().sendMessage(style.ok("Friend request declined."));
ScrowAPI.getPlayer(other).sendMessage(style.ok(self.getName() + " has declined your friend request.")); ScrowAPI.getPlayer(other).sendMessage(style.ok(ctx.sender().getName() + " has declined your friend request."));
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();
} }

View file

@ -33,13 +33,13 @@ public final class FriendRequestsLiteral {
private CompletableFuture<Result<Object, String>> displayFriendRequests(CommandContext<Player> ctx) { private CompletableFuture<Result<Object, String>> displayFriendRequests(CommandContext<Player> ctx) {
return Tasks.supplyAsync(() -> return Tasks.supplyAsync(() ->
ScrowAPI.friendRequestService().getFriendRequestsTo(ctx.getSender().getUniqueId())) ScrowAPI.friendRequestService().getFriendRequestsTo(ctx.sender().getUniqueId()))
.<Result<Object, String>>mapAsync(list -> { .<Result<Object, String>>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() var requesters = list.stream()
.sorted(this::compareByAge) .sorted(this::compareByAge)
.map(fr -> Bukkit.getOfflinePlayer(fr.from()).getName()); .map(fr -> Bukkit.getOfflinePlayer(fr.from()).getName());
ctx.getSender().sendMessage(formatList(requesters.toList())); ctx.sender().sendMessage(formatList(requesters.toList()));
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();
} }

View file

@ -3,14 +3,12 @@ package de.kentoj.scrow.bukkit.command.instance;
import de.kentoj.kencommandapi.api.literal.Literal; import de.kentoj.kencommandapi.api.literal.Literal;
import de.kentoj.kencommandapi.api.literal.RootLiteral; import de.kentoj.kencommandapi.api.literal.RootLiteral;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public final class InstanceCommand { public final class InstanceCommand {
private RootLiteral<CommandSender> rootLiteral; private final RootLiteral<CommandSender> rootLiteral;
public InstanceCommand(InstanceCache instanceCache) { public InstanceCommand(InstanceCache instanceCache) {
var style = new ScrowMessageStyle("server-manager", NamedTextColor.RED); var style = new ScrowMessageStyle("server-manager", NamedTextColor.RED);

View file

@ -32,11 +32,11 @@ public final class InstanceDeployLiteral {
private CompletableFuture<Result<Object, String>> deployInstance(CommandContext<CommandSender> ctx) { private CompletableFuture<Result<Object, String>> deployInstance(CommandContext<CommandSender> ctx) {
var template = ctx.getArg(templateArg); var template = ctx.getArg(templateArg);
ctx.getSender().sendMessage(style.ok("Deploying instance... this may take a while.")); ctx.sender().sendMessage(style.ok("Deploying instance... this may take a while."));
return Tasks.supplyAsync(() -> return Tasks.supplyAsync(() ->
ScrowAPI.instanceManager().deployInstance(template)) ScrowAPI.instanceManager().deployInstance(template))
.<Result<Object, String>>mapSync(instance -> { .<Result<Object, String>>mapSync(instance -> {
ctx.getSender().sendMessage(style.ok("Deployed instance of " + template + " with handle " + instance.handle() + ".")); ctx.sender().sendMessage(style.ok("Deployed instance of " + template + " with handle " + instance.handle() + "."));
// FIXME handle unknown server // FIXME handle unknown server
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();

View file

@ -41,7 +41,7 @@ public final class InstanceDestroyLiteral {
.<Result<Object, String>>mapSync(found -> { .<Result<Object, String>>mapSync(found -> {
if (!found) if (!found)
return Results.failure("No instance with that handle found."); return Results.failure("No instance with that handle found.");
ctx.getSender().sendMessage(style.ok("Destroyed server with handle " + handle + ".")); ctx.sender().sendMessage(style.ok("Destroyed server with handle " + handle + "."));
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();
} }

View file

@ -33,7 +33,7 @@ public final class InstanceListLiteral {
msg = msg.appendNewline() msg = msg.appendNewline()
.append(Component.text(" - " + inst.handle() + " on port " + inst.port())); .append(Component.text(" - " + inst.handle() + " on port " + inst.port()));
} }
ctx.getSender().sendMessage(style.ok(msg)); ctx.sender().sendMessage(style.ok(msg));
return Results.success(new Object()); return Results.success(new Object());
}).toFuture(); }).toFuture();
} }

View file

@ -6,9 +6,7 @@ import de.kentoj.kencommandapi.api.invocation.CommandContext;
import de.kentoj.kencommandapi.api.literal.Literal; import de.kentoj.kencommandapi.api.literal.Literal;
import de.kentoj.kencommandapi.api.literal.RootLiteral; import de.kentoj.kencommandapi.api.literal.RootLiteral;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public final class LobbyCommand { public final class LobbyCommand {
@ -22,7 +20,7 @@ public final class LobbyCommand {
} }
private Result<Object, String> sendToLobby(CommandContext<Player> ctx) { private Result<Object, String> sendToLobby(CommandContext<Player> ctx) {
Bukkit.dispatchCommand(ctx.getSender(), "play lobby"); Bukkit.dispatchCommand(ctx.sender(), "play lobby");
return Results.success(new Object()); return Results.success(new Object());
} }

View file

@ -40,7 +40,7 @@ public final class PlayCommand {
return Results.failure("No instance for " + gamemode + " found."); return Results.failure("No instance for " + gamemode + " found.");
return Results.ofCallable(() -> { return Results.ofCallable(() -> {
ScrowAPI.getPlayer(ctx.getSender()).sendToInstance(instance.handle()); ScrowAPI.getPlayer(ctx.sender()).sendToInstance(instance.handle());
return new Object(); return new Object();
}).mapFailure(Exception::getMessage); }).mapFailure(Exception::getMessage);
}).toFuture(); }).toFuture();

View file

@ -1,7 +1,6 @@
package de.kentoj.scrow.bukkit.internal.player; package de.kentoj.scrow.bukkit.internal.player;
import de.kentoj.scrow.bukkit.ScrowAPI; import de.kentoj.scrow.bukkit.ScrowAPI;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;

View file

@ -5,7 +5,6 @@ import de.kentoj.scrow.bukkit.region.ChunkPos;
import de.kentoj.scrow.bukkit.region.Region; import de.kentoj.scrow.bukkit.region.Region;
import de.kentoj.scrow.bukkit.region.event.RegionJoinEvent; import de.kentoj.scrow.bukkit.region.event.RegionJoinEvent;
import de.kentoj.scrow.bukkit.region.event.RegionLeaveEvent; import de.kentoj.scrow.bukkit.region.event.RegionLeaveEvent;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;

View file

@ -1,8 +1,6 @@
package de.kentoj.scrow.bukkit.style; package de.kentoj.scrow.bukkit.style;
import de.kentoj.scrowlib.utils.ComponentUtils; import de.kentoj.scrowlib.utils.ComponentUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View file

@ -2,7 +2,11 @@ load("@rules_jvm_external//:defs.bzl", "artifact")
load("@rules_java//java:java_library.bzl", "java_library") load("@rules_java//java:java_library.bzl", "java_library")
shared_deps = [ shared_deps = [
"//third_party:common_deps", artifact("com.leakyabstractions:result-api"),
artifact("com.leakyabstractions:result"),
artifact("org.jetbrains:annotations"),
artifact("com.google.guava:guava"),
artifact("org.slf4j.slf4j:api"),
artifact("de.kentoj.scrow:kencommandapi-core"), artifact("de.kentoj.scrow:kencommandapi-core"),
artifact("net.kyori:adventure-api"), artifact("net.kyori:adventure-api"),
artifact("net.kyori:adventure-text-minimessage"), artifact("net.kyori:adventure-text-minimessage"),

View file

@ -2,7 +2,6 @@ package de.kentoj.scrowlib.friends.friendship;
import de.kentoj.scrowlib.friends.Friendship; import de.kentoj.scrowlib.friends.Friendship;
import de.kentoj.scrowlib.friends.OrderedUUIDPair; import de.kentoj.scrowlib.friends.OrderedUUIDPair;
import lombok.RequiredArgsConstructor;
import java.time.Instant; import java.time.Instant;
import java.util.UUID; import java.util.UUID;

View file

@ -2,7 +2,6 @@ package de.kentoj.scrowlib.friends.request;
import de.kentoj.scrowlib.friends.FriendRequest; import de.kentoj.scrowlib.friends.FriendRequest;
import de.kentoj.scrowlib.friends.FriendRequestService; import de.kentoj.scrowlib.friends.FriendRequestService;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.statement.StatementContext; import org.jdbi.v3.core.statement.StatementContext;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View file

@ -2,7 +2,6 @@ package de.kentoj.scrowlib.instancemanager;
import de.kentoj.scrowlib.messaging.MessageBroker; import de.kentoj.scrowlib.messaging.MessageBroker;
import de.kentoj.scrowlib.messaging.RemoteException; import de.kentoj.scrowlib.messaging.RemoteException;
import lombok.RequiredArgsConstructor;
import org.bson.Document; import org.bson.Document;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View file

@ -1,7 +1,6 @@
package de.kentoj.scrowlib.player; package de.kentoj.scrowlib.player;
import de.kentoj.scrowlib.messaging.MessageBroker; import de.kentoj.scrowlib.messaging.MessageBroker;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;

View file

@ -9,7 +9,6 @@ java_library(
deps = [ deps = [
"//core-lib:core", "//core-lib:core",
artifact("com.velocitypowered:velocity-api"), artifact("com.velocitypowered:velocity-api"),
artifact("org.projectlombok:lombok"),
artifact("de.kentoj.scrow:kencommandapi-velocity"), artifact("de.kentoj.scrow:kencommandapi-velocity"),
], ],
exports = [ exports = [
@ -17,18 +16,16 @@ java_library(
artifact("de.kentoj.scrow:kencommandapi-velocity"), artifact("de.kentoj.scrow:kencommandapi-velocity"),
artifact("org.mongodb:bson"), artifact("org.mongodb:bson"),
], ],
plugins = [ "//third_party:lombok_plugin" ],
) )
java_binary( java_binary(
name = "plugin", name = "plugin",
srcs = glob(["plugin/main/**/*.java"]), srcs = glob(["plugin/main/**/*.java"]),
main_class = "none", create_executable = False,
resources = glob(["plugin/main/resources/**"], allow_empty = True),
deps = [ deps = [
":api", ":api",
artifact("com.velocitypowered:velocity-api"), artifact("com.velocitypowered:velocity-api"),
artifact("com.google.inject:guice"),
artifact("io.nats:jnats"), artifact("io.nats:jnats"),
], ],
plugins = [ "//third_party:lombok_plugin" ],
) )

View file

@ -7,26 +7,17 @@ import de.kentoj.scrowlib.instancemanager.InstanceManager;
import de.kentoj.scrowlib.messaging.MessageBroker; import de.kentoj.scrowlib.messaging.MessageBroker;
import de.kentoj.scrowlib.player.NetworkPlayer; import de.kentoj.scrowlib.player.NetworkPlayer;
import de.kentoj.scrowlib.player.NetworkPlayerFactory; import de.kentoj.scrowlib.player.NetworkPlayerFactory;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.Jdbi;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import java.util.UUID; import java.util.UUID;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ScrowAPI { public class ScrowAPI {
@Getter
private static Jdbi jdbi; private static Jdbi jdbi;
@Getter
private static CommandAPI<CommandSource> commands; private static CommandAPI<CommandSource> commands;
@Getter
private static CommandAPI<Player> playerCommands; private static CommandAPI<Player> playerCommands;
@Getter
private static MessageBroker messageBroker; private static MessageBroker messageBroker;
@Getter
private static InstanceManager instanceManager; private static InstanceManager instanceManager;
private static NetworkPlayerFactory playerFactory; private static NetworkPlayerFactory playerFactory;
@ -39,33 +30,56 @@ public class ScrowAPI {
} }
@ApiStatus.Internal @ApiStatus.Internal
public static void setMessageBroker(MessageBroker messageBroker) { public static void initMessageBroker(MessageBroker messageBroker) {
ScrowAPI.messageBroker = messageBroker; ScrowAPI.messageBroker = messageBroker;
} }
@ApiStatus.Internal @ApiStatus.Internal
public static void setInstanceManager(InstanceManager instanceManager) { public static void initInstanceManager(InstanceManager instanceManager) {
ScrowAPI.instanceManager = instanceManager; ScrowAPI.instanceManager = instanceManager;
} }
@ApiStatus.Internal @ApiStatus.Internal
public static void setJdbi(Jdbi jdbi) { public static void initJdbi(Jdbi jdbi) {
ScrowAPI.jdbi = jdbi; ScrowAPI.jdbi = jdbi;
} }
@ApiStatus.Internal @ApiStatus.Internal
public static void setPlayerFactory(NetworkPlayerFactory playerFactory) { public static void initPlayerFactory(NetworkPlayerFactory playerFactory) {
ScrowAPI.playerFactory = playerFactory; ScrowAPI.playerFactory = playerFactory;
} }
@ApiStatus.Internal @ApiStatus.Internal
public static void setPlayerCommands(CommandAPI<Player> playerCommands) { public static void initPlayerCommands(CommandAPI<Player> playerCommands) {
ScrowAPI.playerCommands = playerCommands; ScrowAPI.playerCommands = playerCommands;
} }
@ApiStatus.Internal @ApiStatus.Internal
public static void setCommands(CommandAPI<CommandSource> commands) { public static void initCommands(CommandAPI<CommandSource> commands) {
ScrowAPI.commands = commands; ScrowAPI.commands = commands;
} }
public static Jdbi jdbi() {
return jdbi;
} }
public static CommandAPI<CommandSource> commands() {
return commands;
}
public static CommandAPI<Player> playerCommands() {
return playerCommands;
}
public static MessageBroker messageBroker() {
return messageBroker;
}
public static InstanceManager instanceManager() {
return instanceManager;
}
public static NetworkPlayerFactory playerFactory() {
return playerFactory;
}
}

View file

@ -13,18 +13,15 @@ import de.kentoj.scrow.corevelocity.privmsg.LastTargetCache;
import de.kentoj.scrow.corevelocity.privmsg.MsgCommand; import de.kentoj.scrow.corevelocity.privmsg.MsgCommand;
import de.kentoj.scrow.corevelocity.privmsg.PrivMsgHandler; import de.kentoj.scrow.corevelocity.privmsg.PrivMsgHandler;
import de.kentoj.scrow.corevelocity.privmsg.ReplyCommand; import de.kentoj.scrow.corevelocity.privmsg.ReplyCommand;
import de.kentoj.scrow.generated.BuildInfo;
import de.kentoj.scrow.velocity.ScrowAPI; import de.kentoj.scrow.velocity.ScrowAPI;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@Slf4j
@Plugin( @Plugin(
id = "corevelocity", id = "corevelocity",
name = "CoreVelocity", name = "CoreVelocity",
authors = {"gradlehater57"}, authors = {"gradlehater57"},
version = BuildInfo.VERSION // may not resolve until building for the first time version = "0"
) )
public final class CoreVelocityPlugin { public final class CoreVelocityPlugin {
@ -35,13 +32,12 @@ public final class CoreVelocityPlugin {
private void onInit(ProxyInitializeEvent __) { private void onInit(ProxyInitializeEvent __) {
ScrowAPISurface.initScrowAPI(server); ScrowAPISurface.initScrowAPI(server);
var cmds = ScrowAPI.getCommandApi();
var lastTargetCache = new LastTargetCache(); var lastTargetCache = new LastTargetCache();
var style = new ScrowMessageStyle("MSG", NamedTextColor.LIGHT_PURPLE); var style = new ScrowMessageStyle("MSG", NamedTextColor.LIGHT_PURPLE);
var privmsgHelper = new PrivMsgHandler(style); var privmsgHelper = new PrivMsgHandler(style);
cmds.register(new ReplyCommand(server, lastTargetCache, privmsgHelper, style).getRootLiteral()); ScrowAPI.playerCommands().register(new ReplyCommand(server, lastTargetCache, privmsgHelper, style).rootLiteral());
cmds.register(new MsgCommand(server, lastTargetCache, privmsgHelper, style).getRootLiteral()); ScrowAPI.playerCommands().register(new MsgCommand(server, lastTargetCache, privmsgHelper, style).rootLiteral());
cmds.register(new OnlineCommand(server).getRootLiteral()); ScrowAPI.commands().register(new OnlineCommand(server).rootLiteral());
var registerWatchdog = new ServerRegisterWatchdog(server); var registerWatchdog = new ServerRegisterWatchdog(server);
var sendPlayerWatchdog = new SendPlayerWatchdog(server); var sendPlayerWatchdog = new SendPlayerWatchdog(server);

View file

@ -1,5 +1,7 @@
package de.kentoj.scrow.corevelocity; package de.kentoj.scrow.corevelocity;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import de.kentoj.kencommandapi.CommandAPI; import de.kentoj.kencommandapi.CommandAPI;
import de.kentoj.scrow.velocity.ScrowAPI; import de.kentoj.scrow.velocity.ScrowAPI;
@ -9,20 +11,18 @@ import de.kentoj.scrowlib.messaging.NatsMessageBroker;
import de.kentoj.scrowlib.player.NetworkPlayerImpl; import de.kentoj.scrowlib.player.NetworkPlayerImpl;
import io.nats.client.Nats; import io.nats.client.Nats;
import io.nats.client.Options; import io.nats.client.Options;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.Jdbi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
@Slf4j
@NoArgsConstructor(access = AccessLevel.NONE)
public class ScrowAPISurface { public class ScrowAPISurface {
public static void initScrowAPI(ProxyServer server) { private static final Logger log = LoggerFactory.getLogger(ScrowAPISurface.class);
public static void initScrowAPI(ProxyServer server) {
var natsHost = System.getenv("HOST_NATS"); var natsHost = System.getenv("HOST_NATS");
if (natsHost != null) { if (natsHost != null) {
try { try {
@ -30,13 +30,13 @@ public class ScrowAPISurface {
.server(natsHost) .server(natsHost)
.pedantic() .pedantic()
.build(); .build();
ScrowAPI.setMessageBroker(new NatsMessageBroker(Nats.connect(options))); ScrowAPI.initMessageBroker(new NatsMessageBroker(Nats.connect(options)));
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} else { } else {
log.error("HOST_NATS not set -> Using in-memory dummy message broker"); log.error("HOST_NATS not set -> Using in-memory dummy message broker");
ScrowAPI.setMessageBroker(new InMemoyMessageBroker()); ScrowAPI.initMessageBroker(new InMemoyMessageBroker());
} }
var hostPostgres = System.getenv().get("HOST_POSTGRES"); var hostPostgres = System.getenv().get("HOST_POSTGRES");
@ -45,7 +45,7 @@ public class ScrowAPISurface {
Class.forName("org.postgresql.Driver", true, ScrowAPISurface.class.getClassLoader()); Class.forName("org.postgresql.Driver", true, ScrowAPISurface.class.getClassLoader());
var props = new Properties(); var props = new Properties();
props.setProperty("user", "postgres"); props.setProperty("user", "postgres");
ScrowAPI.setJdbi(Jdbi.create(hostPostgres, props)); ScrowAPI.initJdbi(Jdbi.create(hostPostgres, props));
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -53,9 +53,10 @@ public class ScrowAPISurface {
log.error("HOST_POSTGRES not set -> Using in-memory database"); log.error("HOST_POSTGRES not set -> Using in-memory database");
} }
ScrowAPI.setInstanceManager(new InstanceManagerImpl(ScrowAPI.getMessageBroker())); ScrowAPI.initInstanceManager(new InstanceManagerImpl(ScrowAPI.messageBroker()));
ScrowAPI.setCommandApi(new CommandAPI(server)); ScrowAPI.initCommands(new CommandAPI<>(server, CommandSource.class));
ScrowAPI.setPlayerFactory(playerId -> new NetworkPlayerImpl(ScrowAPI.getMessageBroker(), playerId)); ScrowAPI.initPlayerCommands(new CommandAPI<>(server, Player.class));
ScrowAPI.initPlayerFactory(playerId -> new NetworkPlayerImpl(ScrowAPI.messageBroker(), playerId));
} }
public static void destroyScrowAPI() { public static void destroyScrowAPI() {

View file

@ -9,30 +9,30 @@ import de.kentoj.kencommandapi.api.invocation.SyncCommandExecutor;
import de.kentoj.kencommandapi.api.literal.Literal; import de.kentoj.kencommandapi.api.literal.Literal;
import de.kentoj.kencommandapi.api.literal.RootLiteral; import de.kentoj.kencommandapi.api.literal.RootLiteral;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor public final class OnlineCommand {
public class OnlineCommand implements SyncCommandExecutor<CommandSource> {
@Getter
private final RootLiteral<CommandSource> rootLiteral; private final RootLiteral<CommandSource> rootLiteral;
private final ScrowMessageStyle style = ScrowMessageStyle.GENERIC; private final ScrowMessageStyle style = ScrowMessageStyle.GENERIC;
private final ProxyServer server; private final ProxyServer server;
public OnlineCommand(ProxyServer server) { public OnlineCommand(ProxyServer server) {
this.server = server; this.server = server;
rootLiteral = Literal.rootLiteral(ScrowMessageStyle.GENERIC, "online"); rootLiteral = Literal.<CommandSource>builder("online")
rootLiteral.setExecutor(this); .withSyncExecutor(this::executeSync)
.asRootLiteral(ScrowMessageStyle.GENERIC);
} }
@Override private Result<Object, String> executeSync(CommandContext<CommandSource> ctx) {
public Result<Object, String> executeSync(CommandContext<CommandSource> ctx) {
int cnt = server.getPlayerCount(); int cnt = server.getPlayerCount();
var msg = cnt != 1 var msg = cnt != 1
? "There are currently " + cnt + " players online." ? "There are currently " + cnt + " players online."
: "There is currently 1 player online."; : "There is currently 1 player online.";
ctx.getSender().sendMessage(style.ok(msg)); ctx.sender().sendMessage(style.ok(msg));
return Results.success(new Object()); return Results.success(new Object());
} }
public RootLiteral<CommandSource> rootLiteral() {
return rootLiteral;
}
} }

View file

@ -9,7 +9,7 @@ import org.bson.Document;
public class FriendNotifications { public class FriendNotifications {
private final MessageBroker messageBroker = ScrowAPI.getMessageBroker(); private final MessageBroker messageBroker = ScrowAPI.messageBroker();
@Subscribe @Subscribe
private void onConnect(PostLoginEvent ev) { private void onConnect(PostLoginEvent ev) {

View file

@ -3,8 +3,6 @@ package de.kentoj.scrow.corevelocity.network;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import de.kentoj.scrow.velocity.ScrowAPI; import de.kentoj.scrow.velocity.ScrowAPI;
import de.kentoj.scrowlib.messaging.MessageBroker; import de.kentoj.scrowlib.messaging.MessageBroker;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document; import org.bson.Document;
import java.util.UUID; import java.util.UUID;
@ -12,15 +10,17 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@Slf4j
@RequiredArgsConstructor
public class SendPlayerWatchdog { public class SendPlayerWatchdog {
private final ExecutorService EXECUTOR = Executors.newVirtualThreadPerTaskExecutor(); private final ExecutorService EXECUTOR = Executors.newVirtualThreadPerTaskExecutor();
private final MessageBroker messageBroker = ScrowAPI.getMessageBroker(); private final MessageBroker messageBroker = ScrowAPI.messageBroker();
private final ProxyServer server; private final ProxyServer server;
public SendPlayerWatchdog(ProxyServer server) {
this.server = server;
}
public void listen() { public void listen() {
messageBroker.handle("player.send", doc -> sendPlayer( messageBroker.handle("player.send", doc -> sendPlayer(
doc.get("playerId", UUID.class), doc.get("playerId", UUID.class),

View file

@ -4,31 +4,35 @@ import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.proxy.server.ServerInfo;
import de.kentoj.scrow.velocity.ScrowAPI; import de.kentoj.scrow.velocity.ScrowAPI;
import de.kentoj.scrowlib.messaging.MessageBroker; import de.kentoj.scrowlib.messaging.MessageBroker;
import lombok.RequiredArgsConstructor; import org.slf4j.Logger;
import lombok.extern.java.Log; import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@Log
@RequiredArgsConstructor
public class ServerRegisterWatchdog { public class ServerRegisterWatchdog {
private final MessageBroker messageBroker = ScrowAPI.getMessageBroker(); private static final Logger log = LoggerFactory.getLogger(ServerRegisterWatchdog.class);
private final MessageBroker messageBroker = ScrowAPI.messageBroker();
private final ProxyServer server; private final ProxyServer server;
public ServerRegisterWatchdog(ProxyServer server) {
this.server = server;
}
public void listen() { public void listen() {
messageBroker.subscribe("event.instance.up", doc -> { messageBroker.subscribe("event.instance.up", doc -> {
var handle = doc.getString("handle"); var handle = doc.getString("handle");
var port = doc.getInteger("port"); var port = doc.getInteger("port");
server.unregisterServer(new ServerInfo(handle, new InetSocketAddress(port))); server.unregisterServer(new ServerInfo(handle, new InetSocketAddress(port)));
log.info("registered server " + handle); log.info("registered server {}", handle);
}); });
messageBroker.subscribe("event.instance.down", doc -> { messageBroker.subscribe("event.instance.down", doc -> {
var handle = doc.getString("handle"); var handle = doc.getString("handle");
var port = doc.getInteger("port"); var port = doc.getInteger("port");
server.unregisterServer(new ServerInfo(handle, new InetSocketAddress(port))); server.unregisterServer(new ServerInfo(handle, new InetSocketAddress(port)));
log.info("unregistered server " + handle); log.info("unregistered server {}", handle);
}); });
} }
} }

View file

@ -5,13 +5,13 @@ import com.google.common.cache.CacheBuilder;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.time.Duration;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class LastTargetCache { public class LastTargetCache {
private final Cache<@NotNull UUID, @NotNull UUID> cache = CacheBuilder.newBuilder() private final Cache<@NotNull UUID, @NotNull UUID> cache = CacheBuilder.newBuilder()
.expireAfterAccess(20, TimeUnit.MINUTES) .expireAfterAccess(Duration.ofMinutes(20))
.build(); .build();
public @Nullable UUID getLastTarget(UUID uuid) { public @Nullable UUID getLastTarget(UUID uuid) {

View file

@ -5,22 +5,19 @@ import com.leakyabstractions.result.core.Results;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import de.kentoj.kencommandapi.api.argument.CommandArgument; import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
import de.kentoj.kencommandapi.api.argument.types.StringArgumentType; import de.kentoj.kencommandapi.api.argument.types.StringArgumentType;
import de.kentoj.kencommandapi.api.invocation.CommandContext; import de.kentoj.kencommandapi.api.invocation.CommandContext;
import de.kentoj.kencommandapi.api.invocation.SyncCommandExecutor;
import de.kentoj.kencommandapi.api.literal.Literal; import de.kentoj.kencommandapi.api.literal.Literal;
import de.kentoj.kencommandapi.api.literal.RootLiteral; import de.kentoj.kencommandapi.api.literal.RootLiteral;
import de.kentoj.kencommandapi.api.platform.MessageStyle; import de.kentoj.kencommandapi.api.platform.MessageStyle;
import de.kentoj.kencommandapi.type.PlayerArgumentType; import de.kentoj.kencommandapi.type.PlayerArgumentType;
import lombok.Getter;
public class MsgCommand implements SyncCommandExecutor<CommandSource> { public class MsgCommand {
@Getter private final RootLiteral<Player> rootLiteral;
private final RootLiteral<CommandSource> rootLiteral; private final CommandArgumentSpec<Player, Player> targetArg;
private final CommandArgument<CommandSource, Player> targetArg; private final CommandArgumentSpec<Player, String> msgArg;
private final CommandArgument<CommandSource, String> msgArg;
private final LastTargetCache cache; private final LastTargetCache cache;
private final PrivMsgHandler privMsgHandler; private final PrivMsgHandler privMsgHandler;
@ -29,26 +26,29 @@ public class MsgCommand implements SyncCommandExecutor<CommandSource> {
this.cache = cache; this.cache = cache;
this.privMsgHandler = helper; this.privMsgHandler = helper;
targetArg = CommandArgument.arg("target", new PlayerArgumentType(server)); targetArg = CommandArgumentSpec.builder("target", new PlayerArgumentType<Player>(server)).build();
msgArg = CommandArgument.arg("msg", new StringArgumentType<>(true)); msgArg = CommandArgumentSpec.builder("msg", new StringArgumentType<Player>(true)).build();
rootLiteral = Literal.rootLiteral(style, "msg", "w", "privmsg"); rootLiteral = Literal.<Player>builder("msg", "w", "privmsg")
rootLiteral.setExecutor(this); .withArgument(targetArg)
rootLiteral.addArgument(targetArg); .withArgument(msgArg)
rootLiteral.addArgument(msgArg); .withSyncExecutor(this::executeSync)
.asRootLiteral(style);
} }
@Override private Result<Object, String> executeSync(CommandContext<Player> ctx) {
public Result<Object, String> executeSync(CommandContext<CommandSource> ctx) {
var target = ctx.getArg(targetArg); var target = ctx.getArg(targetArg);
var msg = ctx.getArg(msgArg); var msg = ctx.getArg(msgArg);
var sender = (Player) ctx.getSender();
var isMessagingSelf = target.getUniqueId().equals(sender.getUniqueId()); var isMessagingSelf = target.getUniqueId().equals(ctx.sender().getUniqueId());
if (isMessagingSelf) return Results.failure("You can't message yourself."); if (isMessagingSelf) return Results.failure("You can't message yourself.");
cache.setLastTarget(sender.getUniqueId(), target.getUniqueId()); cache.setLastTarget(ctx.sender().getUniqueId(), target.getUniqueId());
privMsgHandler.handle(sender, target, msg); privMsgHandler.handle(ctx.sender(), target, msg);
return Results.success(new Object()); return Results.success(new Object());
} }
public RootLiteral<Player> rootLiteral() {
return rootLiteral;
}
} }

View file

@ -2,16 +2,18 @@ package de.kentoj.scrow.corevelocity.privmsg;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import de.kentoj.scrowlib.convention.ScrowMessageStyle; import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.text;
@RequiredArgsConstructor
public class PrivMsgHandler { public class PrivMsgHandler {
private final ScrowMessageStyle style; private final ScrowMessageStyle style;
public PrivMsgHandler(ScrowMessageStyle style) {
this.style = style;
}
public void handle(Player player, Player target, String msg) { public void handle(Player player, Player target, String msg) {
target.sendMessage(style.ok(text(target.getUsername() + " -> You: ").append(Component.text(msg)))); target.sendMessage(style.ok(text(target.getUsername() + " -> You: ").append(Component.text(msg))));
player.sendMessage(style.ok(text("You -> " + target.getUsername() + ": ").append(Component.text(msg)))); player.sendMessage(style.ok(text("You -> " + target.getUsername() + ": ").append(Component.text(msg))));

View file

@ -5,20 +5,18 @@ import com.leakyabstractions.result.core.Results;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import de.kentoj.kencommandapi.api.argument.CommandArgument; import de.kentoj.kencommandapi.api.argument.CommandArgumentSpec;
import de.kentoj.kencommandapi.api.argument.types.StringArgumentType; import de.kentoj.kencommandapi.api.argument.types.StringArgumentType;
import de.kentoj.kencommandapi.api.invocation.CommandContext; import de.kentoj.kencommandapi.api.invocation.CommandContext;
import de.kentoj.kencommandapi.api.invocation.SyncCommandExecutor;
import de.kentoj.kencommandapi.api.literal.Literal; import de.kentoj.kencommandapi.api.literal.Literal;
import de.kentoj.kencommandapi.api.literal.RootLiteral; import de.kentoj.kencommandapi.api.literal.RootLiteral;
import de.kentoj.kencommandapi.api.platform.MessageStyle; import de.kentoj.kencommandapi.api.platform.MessageStyle;
import lombok.Getter; import de.kentoj.kencommandapi.type.PlayerArgumentType;
public class ReplyCommand implements SyncCommandExecutor<CommandSource> { public class ReplyCommand {
@Getter private final RootLiteral<Player> rootLiteral;
private final RootLiteral<CommandSource> rootLiteral; private final CommandArgumentSpec<Player, String> msgArg;
private final CommandArgument<CommandSource, String> msgArg;
private final LastTargetCache cache; private final LastTargetCache cache;
private final ProxyServer server; private final ProxyServer server;
@ -29,16 +27,15 @@ public class ReplyCommand implements SyncCommandExecutor<CommandSource> {
this.server = server; this.server = server;
this.privMsgHandler = privMsgHandler; this.privMsgHandler = privMsgHandler;
msgArg = CommandArgument.arg("msg", new StringArgumentType<>(true)); msgArg = CommandArgumentSpec.builder("msg", new StringArgumentType<Player>(true)).build();
rootLiteral = Literal.rootLiteral(style, "reply", "r"); rootLiteral = Literal.<Player>builder("reply", "r")
rootLiteral.setExecutor(this); .withArgument(msgArg)
rootLiteral.addArgument(msgArg); .withSyncExecutor(this::executeSync)
.asRootLiteral(style);
} }
@Override private Result<Object, String> executeSync(CommandContext<Player> ctx) {
public Result<Object, String> executeSync(CommandContext<CommandSource> ctx) { var targetId = cache.getLastTarget(ctx.sender().getUniqueId());
var sender = (Player) ctx.getSender();
var targetId = cache.getLastTarget(sender.getUniqueId());
if (targetId == null) if (targetId == null)
return Results.failure("You didn't messaged anyone recently. Use /msg first"); return Results.failure("You didn't messaged anyone recently. Use /msg first");
var target = server.getPlayer(targetId).orElse(null); var target = server.getPlayer(targetId).orElse(null);
@ -46,7 +43,11 @@ public class ReplyCommand implements SyncCommandExecutor<CommandSource> {
if (target == null) if (target == null)
return Results.failure("The player you last messaged is no longer online."); return Results.failure("The player you last messaged is no longer online.");
privMsgHandler.handle(sender, target, msg); privMsgHandler.handle(ctx.sender(), target, msg);
return Results.success(new Object()); return Results.success(new Object());
} }
public RootLiteral<Player> rootLiteral() {
return rootLiteral;
}
} }

35
dev-server/BUILD Normal file
View file

@ -0,0 +1,35 @@
load(":minecraft.bzl", "dev_server", "fetch_file")
dev_server(
name = "dev",
server_jar = ":papermc",
plugins = [
":luckperms",
":viaversion",
":viabackwards",
],
local_plugins = [
"//core-bukkit:plugin",
],
)
fetch_file(
name = "papermc",
filename = "paper.jar",
url = "https://fill-data.papermc.io/v1/objects/5953a1f1deaa3572be420c3a5b18406c4b752412a78be4acab7c8b467633caed/paper-26.2-100.jar",
)
fetch_file(
name = "luckperms",
filename = "LuckPerms.jar",
url = "https://download.luckperms.net/1652/bukkit/loader/LuckPerms-Bukkit-5.5.65.jar",
)
fetch_file(
name = "viaversion",
filename = "ViaVersion.jar",
url = "https://hangarcdn.papermc.io/plugins/ViaVersion/ViaVersion/versions/5.11.0/PAPER/ViaVersion-5.11.0.jar"
)
fetch_file(
name = "viabackwards",
filename = "ViaBackwards.jar",
url = "https://hangarcdn.papermc.io/plugins/ViaVersion/ViaBackwards/versions/5.11.0/PAPER/ViaBackwards-5.11.0.jar"
)

61
dev-server/minecraft.bzl Normal file
View file

@ -0,0 +1,61 @@
def _dev_server_impl(ctx):
script = ctx.actions.declare_file(ctx.label.name + "_runner")
content = """
#!/bin/sh
set -eux
echo hi\n
cp -f '%s' server.jar
printf eula=true > eula.txt
mkdir -p plugins
rm -f plugins/*.jar
for plugin in %s
do
cp -v \"$plugin\" plugins/
done
exec java -jar server.jar --nogui %s
""" % (
ctx.file.server_jar.short_path,
" ".join([p.short_path for p in ctx.files.plugins]),
" ".join(["--add-plugin %s" % p.short_path for p in ctx.files.local_plugins]),
)
ctx.actions.write(
output = script,
content = content,
is_executable = True,
)
return DefaultInfo(
executable = script,
runfiles = ctx.runfiles(files = [ctx.file.server_jar] + ctx.files.plugins + ctx.files.local_plugins)
)
dev_server = rule(
implementation = _dev_server_impl,
executable = True,
attrs = {
"server_jar": attr.label(allow_single_file = True, mandatory = True),
"plugins": attr.label_list(),
"local_plugins": attr.label_list(),
},
)
def _fetch_plugin_impl(ctx):
out_file = ctx.actions.declare_file(ctx.attr.filename)
ctx.actions.run_shell(
outputs = [out_file],
command = "curl -Lso \"$1\" \"$2\"",
arguments = [out_file.path, ctx.attr.url],
execution_requirements = {
"requires-network": "1",
},
progress_message = "Downloading plugin %s" % ctx.attr.filename,
)
return [DefaultInfo(files = depset([out_file]))]
fetch_file = rule(
implementation = _fetch_plugin_impl,
attrs = {
"url": attr.string(mandatory = True),
"filename": attr.string(mandatory = True),
},
)

View file

@ -1,42 +0,0 @@
#!/usr/bin/env sh
set -e
test -n "$MC_VERSION" || {
>&2 echo "MC_VERSION unset"
exit 1
}
test -n "$BUILT_PLUGIN" || {
>&2 echo "BUILT_PLUGIN unset"
exit 1
}
BUILT_PLUGIN="$(realpath "$BUILD_WORKSPACE_DIRECTORY/$BUILT_PLUGIN")"
test -e "$BUILT_PLUGIN" || {
>&2 echo "$BUILT_PLUGIN does not exist"
exit 1
}
mkdir -p "$BUILD_WORKSPACE_DIRECTORY/run"
cd "$BUILD_WORKSPACE_DIRECTORY/run"
printf 'eula=true' > eula.txt
server="paper-${MC_VERSION}.jar"
test -f "$server" || {
>&2 echo "$server not found. downloading..."
url="$(curl -Ls "https://fill.papermc.io/v3/projects/paper/versions/$MC_VERSION/builds/latest" \
| jq -r '.downloads."server:default".url')"
curl -L -o "$server" "$url"
}
# shellcheck disable=SC2068
for arg in $@; do
name="$(echo "$arg" | cut -d= -f1)"
url="$(echo "$arg" | cut -d= -f2)"
plugin="plugins/$name"
test -f "$plugin" || curl -Lo "$plugin" "$url"
done
exec java -jar "$server" \
--nogui \
--add-plugin "$BUILT_PLUGIN"

23
third_party/BUILD vendored
View file

@ -1,23 +0,0 @@
load("@rules_java//java:java_plugin.bzl", "java_plugin")
load("@rules_java//java:java_library.bzl", "java_library")
load("@rules_jvm_external//:defs.bzl", "artifact")
java_plugin(
name = "lombok_plugin",
visibility = ["//visibility:public"],
deps = ["@maven//:org_projectlombok_lombok"],
processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
)
java_library(
name = "common_deps",
exports = [
"@maven//:org_projectlombok_lombok",
"@maven//:com_leakyabstractions_result_api",
"@maven//:com_leakyabstractions_result",
"@maven//:org_jetbrains_annotations",
"@maven//:com_google_guava_guava",
"@maven//:org_slf4j_slf4j_api",
],
visibility = ["//visibility:public"],
)