implement velocity api surface
Some checks failed
/ test (push) Has been cancelled
/ deploy (push) Has been cancelled

This commit is contained in:
kento2 2026-08-29 01:42:52 +02:00
parent 62151736bd
commit 51a5ddbb8b
3 changed files with 25 additions and 4 deletions

View file

@ -40,7 +40,6 @@ public class ScrowCommands<C extends BukkitCommandContext<C>> implements IScrowC
new BukkitScrowCommand<>(commandHandler, commandContextFactory, rootLiteral)); new BukkitScrowCommand<>(commandHandler, commandContextFactory, rootLiteral));
} }
@Override
public @Nullable RootLiteral<C> getRootLiteral(String name) { public @Nullable RootLiteral<C> getRootLiteral(String name) {
return rootLiterals.stream() return rootLiterals.stream()
.filter(literal -> literal.names().contains(name)) .filter(literal -> literal.names().contains(name))

View file

@ -1,12 +1,9 @@
package site.lab0x13.scrow.commands; package site.lab0x13.scrow.commands;
import org.jetbrains.annotations.Nullable;
import site.lab0x13.scrow.commands.model.CommandContext; import site.lab0x13.scrow.commands.model.CommandContext;
import site.lab0x13.scrow.commands.model.literal.RootLiteral; import site.lab0x13.scrow.commands.model.literal.RootLiteral;
public interface IScrowCommands<C extends CommandContext<C>> { public interface IScrowCommands<C extends CommandContext<C>> {
void register(RootLiteral<C> rootLiteral); void register(RootLiteral<C> rootLiteral);
@Nullable RootLiteral<C> getRootLiteral(String name);
} }

View file

@ -0,0 +1,25 @@
import com.velocitypowered.api.proxy.ProxyServer;
import site.lab0x13.scrow.commands.CommandHandler;
import site.lab0x13.scrow.commands.IScrowCommands;
import site.lab0x13.scrow.commands.model.literal.RootLiteral;
public class ScrowCommands<C extends VelocityCommandContext<C>> implements IScrowCommands<C> {
private final ProxyServer server;
private final CommandContextFactory<C> commandContextFactory;
private final CommandHandler<C> commandHandler;
public ScrowCommands(ProxyServer server, CommandContextFactory<C> commandContextFactory, CommandHandler<C> commandHandler) {
this.server = server;
this.commandContextFactory = commandContextFactory;
this.commandHandler = commandHandler;
}
public void register(RootLiteral<C> rootNode) {
var cm = server.getCommandManager();
var meta = cm.metaBuilder(rootNode.names().getFirst())
.aliases(rootNode.names().stream().skip(1).toArray(String[]::new))
.build();
cm.register(meta, new VelocityCommand<>(commandHandler, commandContextFactory, rootNode));
}
}