pass literal to CommandContextFactory
This commit is contained in:
parent
b8fbda94fc
commit
613ea016f1
6 changed files with 9 additions and 7 deletions
|
|
@ -28,7 +28,7 @@ public class BukkitScrowCommand<C extends BukkitCommandContext<C>> extends Comma
|
|||
public boolean execute(@NotNull CommandSender commandSender, @NotNull String commandLabel, String @NotNull [] args) {
|
||||
commandHandler.invoke(
|
||||
rootLiteral,
|
||||
commandContextFactory.createContext(commandSender),
|
||||
commandContextFactory.createContext(rootLiteral, commandSender),
|
||||
Stream.of(args).filter(str -> !str.isEmpty())
|
||||
);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package site.lab0x13.scrow.commands.bukkit;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import site.lab0x13.scrow.commands.model.literal.RootLiteral;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CommandContextFactory<C extends BukkitCommandContext<C>> {
|
||||
|
||||
C createContext(CommandSender sender);
|
||||
C createContext(RootLiteral<C> literal, CommandSender sender);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class TabCompleteListener<C extends BukkitCommandContext<C>> implements L
|
|||
ev.setHandled(true);
|
||||
ev.setCompletions(commandHandler.suggest(
|
||||
literal,
|
||||
commandContextFactory.createContext(ev.getSender()),
|
||||
commandContextFactory.createContext(literal, ev.getSender()),
|
||||
Arrays.copyOfRange(args, 1, args.length),
|
||||
ev.getBuffer().endsWith(" ")
|
||||
));
|
||||
|
|
|
|||
2
defs.bzl
2
defs.bzl
|
|
@ -1,2 +1,2 @@
|
|||
GROUP = "site.lab0x13.scrow"
|
||||
VERSION = "1.0.1"
|
||||
VERSION = "1.1.1"
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
package site.lab0x13.scrow.commands.velocity;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import site.lab0x13.scrow.commands.model.literal.RootLiteral;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CommandContextFactory<C extends VelocityCommandContext<C>> {
|
||||
|
||||
C createContext(CommandSource sender);
|
||||
C createContext(RootLiteral<C> literal, CommandSource sender);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class VelocityCommand<C extends VelocityCommandContext<C>> implements Raw
|
|||
public void execute(Invocation invocation) {
|
||||
var args = Arrays.stream(invocation.arguments().split(" "))
|
||||
.filter(a -> !a.isEmpty());
|
||||
var ctx = commandContextFactory.createContext(invocation.source());
|
||||
var ctx = commandContextFactory.createContext(rootLiteral, invocation.source());
|
||||
commandHandler.invoke(rootLiteral, ctx, args);
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ public class VelocityCommand<C extends VelocityCommandContext<C>> implements Raw
|
|||
@Override
|
||||
public List<String> suggest(Invocation invocation) {
|
||||
var args = invocation.arguments().split(" ");
|
||||
var ctx = commandContextFactory.createContext(invocation.source());
|
||||
var ctx = commandContextFactory.createContext(rootLiteral, invocation.source());
|
||||
return commandHandler.suggest(rootLiteral, ctx, args, invocation.arguments().endsWith(" "));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue