use of org.enginehub.piston.Command in project FastAsyncWorldEdit by IntellectualSites.
the class FabricPlatform method registerCommands.
@Override
public void registerCommands(CommandManager manager) {
if (server == null)
return;
net.minecraft.server.command.CommandManager mcMan = server.getCommandManager();
for (Command command : manager.getAllCommands().collect(toList())) {
CommandWrapper.register(mcMan.getDispatcher(), command);
Set<String> perms = command.getCondition().as(PermissionCondition.class).map(PermissionCondition::getPermissions).orElseGet(Collections::emptySet);
if (!perms.isEmpty()) {
perms.forEach(FabricWorldEdit.inst.getPermissionsProvider()::registerPermission);
}
}
}
use of org.enginehub.piston.Command in project FastAsyncWorldEdit by IntellectualSites.
the class ExpandCommands method register.
public static void register(CommandRegistrationHandler registration, CommandManager commandManager, CommandManagerService commandManagerService) {
// Collect the general expand command
CommandManager collect = commandManagerService.newCommandManager();
registration.register(collect, ExpandCommandsRegistration.builder(), new ExpandCommands());
Command expandBaseCommand = collect.getCommand("/expand").orElseThrow(() -> new IllegalStateException("No /expand command"));
commandManager.register("/expand", command -> {
command.condition(new PermissionCondition(ImmutableSet.of("worldedit.selection.expand")));
command.addPart(SubCommandPart.builder(Caption.of("vert"), TextComponent.of("Vertical expansion sub-command")).withCommands(ImmutableSet.of(createVertCommand(commandManager))).optional().build());
command.addParts(expandBaseCommand.getParts());
command.action(expandBaseCommand.getAction());
command.description(expandBaseCommand.getDescription());
});
}
use of org.enginehub.piston.Command in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method registerSubCommands.
private <CI> void registerSubCommands(String name, List<String> aliases, String desc, Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance, @Nonnull Consumer<CommandManager> additionalConfig) {
commandManager.register(name, cmd -> {
cmd.aliases(aliases);
cmd.description(TextComponent.of(desc));
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = commandManagerService.newCommandManager();
// FAWE start
handlerInstance.accept((handler, instance) -> this.registration.register(manager, handler, instance));
// FAWE end
additionalConfig.accept(manager);
final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList());
cmd.addPart(SubCommandPart.builder(Caption.of("worldedit.argument.action"), TextComponent.of("Sub-command to run.")).withCommands(subCommands).required().build());
cmd.condition(new SubCommandPermissionCondition.Generator(subCommands).build());
});
}
use of org.enginehub.piston.Command in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method handleCommand.
@Subscribe
public void handleCommand(CommandEvent event) {
Request.reset();
Actor actor = event.getActor();
String args = event.getArguments();
TaskManager.taskManager().taskNow(() -> {
if (!Fawe.isMainThread()) {
Thread.currentThread().setName("FAWE Thread for player: " + actor.getName());
}
int space0 = args.indexOf(' ');
String arg0 = space0 == -1 ? args : args.substring(0, space0);
Optional<Command> optional = commandManager.getCommand(arg0);
if (!optional.isPresent()) {
return;
}
Command cmd = optional.get();
PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null);
if (queued != null && !queued.isQueued()) {
handleCommandOnCurrentThread(event);
return;
} else {
actor.decline();
}
actor.runAction(() -> {
SessionKey key = actor.getSessionKey();
if (key.isActive()) {
PlatformCommandManager.this.handleCommandOnCurrentThread(event);
}
}, false, true);
}, Fawe.isMainThread());
}
use of org.enginehub.piston.Command in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method registerSubCommands.
private <CI> void registerSubCommands(String name, List<String> aliases, String desc, CommandRegistration<CI> registration, CI instance, Consumer<CommandManager> additionalConfig) {
commandManager.register(name, cmd -> {
cmd.aliases(aliases);
cmd.description(TextComponent.of(desc));
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = commandManagerService.newCommandManager();
this.registration.register(manager, registration, instance);
additionalConfig.accept(manager);
final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList());
cmd.addPart(SubCommandPart.builder(Caption.of("worldedit.argument.action"), TextComponent.of("Sub-command to run.")).withCommands(subCommands).required().build());
cmd.condition(new SubCommandPermissionCondition.Generator(subCommands).build());
});
}
Aggregations