implement velocity api surface
This commit is contained in:
parent
62151736bd
commit
51a5ddbb8b
3 changed files with 25 additions and 4 deletions
|
|
@ -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))
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue