This commit is contained in:
kento2 2026-07-07 21:38:52 +02:00
parent 7e5bd1bb6d
commit 5073d933d2
24 changed files with 168 additions and 111 deletions

View file

@ -1,47 +1,53 @@
package de.kentoj.scrow.corevelocity;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer;
import de.kentoj.scrow.corevelocity.command.OnlineCommand;
import de.kentoj.scrow.corevelocity.misc.OnlineCommand;
import de.kentoj.scrow.corevelocity.network.FriendNotifications;
import de.kentoj.scrow.corevelocity.network.SendPlayerWatchdog;
import de.kentoj.scrow.corevelocity.network.ServerRegisterWatchdog;
import de.kentoj.scrow.corevelocity.privmsg.LastTargetCache;
import de.kentoj.scrow.corevelocity.privmsg.MsgCommand;
import de.kentoj.scrow.corevelocity.privmsg.PrivMsgHandler;
import de.kentoj.scrow.corevelocity.privmsg.ReplyCommand;
import de.kentoj.scrow.corevelocity.network.SendPlayerWatchdog;
import de.kentoj.scrow.corevelocity.network.ServerRegisterWatchdog;
import de.kentoj.scrow.generated.BuildInfo;
import de.kentoj.scrow.velocity.ScrowAPI;
import de.kentoj.scrowlib.convention.ScrowMessageStyle;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.format.NamedTextColor;
@Slf4j
@Plugin(
id = "corevelocity",
name = "CoreVelocity",
authors = {"gradlehater57"},
version = BuildInfo.VERSION // may not resolve until building for the first time
)
@Log
public class CoreVelocityPlugin {
public final class CoreVelocityPlugin {
@Inject
public CoreVelocityPlugin(ProxyServer server) {
private ProxyServer server;
@Subscribe
private void onInit(ProxyInitializeEvent __) {
ScrowAPISurface.initScrowAPI(server);
var cmds = ScrowAPI.getCommandApi();
{
var lastTargetCache = new LastTargetCache();
var style = new ScrowMessageStyle("MSG", NamedTextColor.LIGHT_PURPLE);
var privmsgHelper = new PrivMsgHandler(style);
cmds.register(new ReplyCommand(server, lastTargetCache, privmsgHelper, style).getRootLiteral());
cmds.register(new MsgCommand(server, lastTargetCache, privmsgHelper, style).getRootLiteral());
cmds.register(new OnlineCommand(server).getRootLiteral());
}
var lastTargetCache = new LastTargetCache();
var style = new ScrowMessageStyle("MSG", NamedTextColor.LIGHT_PURPLE);
var privmsgHelper = new PrivMsgHandler(style);
cmds.register(new ReplyCommand(server, lastTargetCache, privmsgHelper, style).getRootLiteral());
cmds.register(new MsgCommand(server, lastTargetCache, privmsgHelper, style).getRootLiteral());
cmds.register(new OnlineCommand(server).getRootLiteral());
var registerWatchdog = new ServerRegisterWatchdog(server);
var sendPlayerWatchdog = new SendPlayerWatchdog(server);
registerWatchdog.listen();
sendPlayerWatchdog.listen();
server.getEventManager().register(this, new FriendNotifications());
}
}

View file

@ -45,7 +45,7 @@ public class ScrowAPISurface {
Class.forName("org.postgresql.Driver", true, ScrowAPISurface.class.getClassLoader());
var props = new Properties();
props.setProperty("user", "postgres");
ScrowAPI.setJdbi(Jdbi.create(hostPostgres));
ScrowAPI.setJdbi(Jdbi.create(hostPostgres, props));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}

View file

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

View file

@ -13,7 +13,7 @@ public class PrivMsgHandler {
private final ScrowMessageStyle style;
public void handle(Player player, Player target, String msg) {
target.sendMessage(style.ok(text(player.getUsername() + " -> You: ").append(Component.text(msg))));
player.sendMessage(style.ok(text("You -> " + player.getUsername() + ": ").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))));
}
}