use LiteralMeta instead of permission-less literal-names for subLiterals
This commit is contained in:
parent
5fd408e69e
commit
f18ce1c429
13 changed files with 68 additions and 40 deletions
|
|
@ -10,11 +10,13 @@ public class ScrowCommands<C extends VelocityCommandContext<C>> implements IScro
|
|||
private final ProxyServer server;
|
||||
private final CommandContextFactory<C> commandContextFactory;
|
||||
private final CommandHandler<C> commandHandler;
|
||||
private final VelocityPlatform<C> platformAdapter;
|
||||
|
||||
public ScrowCommands(ProxyServer server, CommandContextFactory<C> commandContextFactory) {
|
||||
this.server = server;
|
||||
this.commandContextFactory = commandContextFactory;
|
||||
this.commandHandler = new CommandHandler<C>(new VelocityPlatform<>());
|
||||
this.platformAdapter = new VelocityPlatform<>();
|
||||
this.commandHandler = new CommandHandler<>(platformAdapter);
|
||||
}
|
||||
|
||||
public void register(RootLiteral<C> rootNode) {
|
||||
|
|
@ -22,6 +24,6 @@ public class ScrowCommands<C extends VelocityCommandContext<C>> implements IScro
|
|||
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));
|
||||
cm.register(meta, new VelocityCommand<>(commandHandler, commandContextFactory, platformAdapter, rootNode));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package site.lab0x13.scrow.commands.velocity;
|
|||
|
||||
import com.velocitypowered.api.command.RawCommand;
|
||||
import site.lab0x13.scrow.commands.CommandHandler;
|
||||
import site.lab0x13.scrow.commands.PlatformAdapter;
|
||||
import site.lab0x13.scrow.commands.model.literal.RootLiteral;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -11,11 +12,13 @@ public class VelocityCommand<C extends VelocityCommandContext<C>> implements Raw
|
|||
|
||||
private final CommandHandler<C> commandHandler;
|
||||
private final CommandContextFactory<C> commandContextFactory;
|
||||
private final PlatformAdapter platformAdapter;
|
||||
private final RootLiteral<C> rootLiteral;
|
||||
|
||||
public VelocityCommand(CommandHandler<C> commandHandler, CommandContextFactory<C> commandContextFactory, RootLiteral<C> rootLiteral) {
|
||||
public VelocityCommand(CommandHandler<C> commandHandler, CommandContextFactory<C> commandContextFactory, PlatformAdapter platformAdapter, RootLiteral<C> rootLiteral) {
|
||||
this.commandHandler = commandHandler;
|
||||
this.commandContextFactory = commandContextFactory;
|
||||
this.platformAdapter = platformAdapter;
|
||||
this.rootLiteral = rootLiteral;
|
||||
}
|
||||
|
||||
|
|
@ -29,8 +32,7 @@ public class VelocityCommand<C extends VelocityCommandContext<C>> implements Raw
|
|||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation ctx) {
|
||||
if (rootLiteral.permission() == null) return true;
|
||||
return ctx.source().hasPermission(rootLiteral.permission());
|
||||
return platformAdapter.checkPermission(ctx, rootLiteral.permission());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package site.lab0x13.scrow.commands.velocity;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import site.lab0x13.scrow.commands.PlatformAdapter;
|
||||
|
||||
public class VelocityPlatform<C extends VelocityCommandContext<C>> implements PlatformAdapter<C> {
|
||||
@Override
|
||||
public boolean checkPermission(C ctx, String permission) {
|
||||
public boolean checkPermission(C ctx, @Nullable String permission) {
|
||||
if (permission == null)
|
||||
return true;
|
||||
return ctx.sender().hasPermission(permission);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue