This commit is contained in:
kento2 2026-06-03 02:17:15 +02:00
parent 0cda14e3cc
commit feafe2af62
3 changed files with 21 additions and 11 deletions

View file

@ -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);

View file

@ -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<CommandSource, VelocityCommandContext> {
@Getter
private final CommandNode<CommandSource, VelocityCommandContext> 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));
}
}

View file

@ -28,7 +28,7 @@ public class MsgCommand implements CommandExecutor<CommandSource, VelocityComman
var cmds = ScrowAPI.getCommandApi();
targetArg = cmds.createArgument("target", new PlayerArgumentType(server));
msgArg = cmds.createArgument("msg", new StringArgumentType<>(true));
rootNode = cmds.createNode("msg", "w");
rootNode = cmds.createNode("msg", "w", "privmsg");
rootNode.setExecutor(this);
rootNode.addArgument(targetArg);
rootNode.addArgument(msgArg);