From feafe2af62460bc20eda01471ca4a59474b05bce Mon Sep 17 00:00:00 2001 From: kento2 Date: Wed, 3 Jun 2026 02:17:15 +0200 Subject: [PATCH] . --- .../corevelocity/CoreVelocityPlugin.java | 2 ++ .../corevelocity/command/OnlineCommand.java | 28 ++++++++++++------- .../corevelocity/privmsg/MsgCommand.java | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) 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 7fd20c7..d12b002 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 @@ -3,6 +3,7 @@ package de.kentoj.scrow.corevelocity; import com.google.inject.Inject; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.proxy.ProxyServer; +import de.kentoj.scrow.corevelocity.command.OnlineCommand; import de.kentoj.scrow.corevelocity.privmsg.LastTargetCache; import de.kentoj.scrow.corevelocity.privmsg.MsgCommand; import de.kentoj.scrow.corevelocity.privmsg.ReplyCommand; @@ -26,6 +27,7 @@ public class CoreVelocityPlugin { var lastTargetCache = new LastTargetCache(); cmds.register(new ReplyCommand(server, lastTargetCache).getRootNode()); cmds.register(new MsgCommand(server, lastTargetCache).getRootNode()); + cmds.register(new OnlineCommand(server).getRootNode()); } var registerWatchdog = new ServerRegisterWatchdog(ScrowAPI.getNats(), ScrowAPI.getServerManager(), 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 cc0b8e3..2e3ddba 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 @@ -1,27 +1,35 @@ package de.kentoj.scrow.corevelocity.command; -import com.velocitypowered.api.command.CommandManager; -import com.velocitypowered.api.command.CommandMeta; -import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.ProxyServer; +import de.kentoj.kencommandapi.VelocityCommandContext; +import de.kentoj.kencommandapi.api.nodes.CommandNode; +import de.kentoj.kencommandapi.api.processing.CommandExecutor; +import de.kentoj.scrow.velocity.ScrowAPI; +import lombok.Getter; import lombok.RequiredArgsConstructor; import net.kyori.adventure.text.Component; @RequiredArgsConstructor -public class OnlineCommand implements SimpleCommand { +public class OnlineCommand implements CommandExecutor { + + @Getter + private final CommandNode rootNode; private final ProxyServer server; + public OnlineCommand(ProxyServer server) { + this.server = server; + rootNode = ScrowAPI.getCommandApi().createNode("online"); + rootNode.setExecutor(this); + } + @Override - public void execute(Invocation invocation) { + public void execute(VelocityCommandContext ctx) { int cnt = server.getPlayerCount(); var msg = cnt != 1 ? "There are currently " + cnt + " players online" : "There is currently 1 player online"; - invocation.source().sendMessage(Component.text(msg)); - } - - public static CommandMeta commandMeta(CommandManager cmds) { - return cmds.metaBuilder("online").build(); + ctx.getPlayerSender().sendMessage(Component.text(msg)); } } diff --git a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/MsgCommand.java b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/MsgCommand.java index 0e715c0..35f9ae2 100644 --- a/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/MsgCommand.java +++ b/core-velocity-impl/src/main/java/de/kentoj/scrow/corevelocity/privmsg/MsgCommand.java @@ -28,7 +28,7 @@ public class MsgCommand implements CommandExecutor(true)); - rootNode = cmds.createNode("msg", "w"); + rootNode = cmds.createNode("msg", "w", "privmsg"); rootNode.setExecutor(this); rootNode.addArgument(targetArg); rootNode.addArgument(msgArg);