use of org.enginehub.piston.CommandManager in project FastAsyncWorldEdit by IntellectualSites.
the class WorldEditListener method onPlayerCommandSend.
// FAWE end
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandSend(PlayerCommandSendEvent event) {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> Optional.of(plugin.wrapCommandSender(event.getPlayer())));
CommandManager commandManager = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().getCommandManager();
event.getCommands().removeIf(name -> commandManager.getCommand(name).filter(command -> !command.getCondition().satisfied(store)).isPresent());
}
use of org.enginehub.piston.CommandManager 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.CommandManager in project FastAsyncWorldEdit by IntellectualSites.
the class GeneralCommands method register.
public static void register(CommandRegistrationHandler registration, CommandManager commandManager, CommandManagerService commandManagerService, WorldEdit worldEdit) {
// Collect the tool commands
CommandManager collect = commandManagerService.newCommandManager();
registration.register(collect, GeneralCommandsRegistration.builder(), new GeneralCommands(worldEdit));
Set<org.enginehub.piston.Command> commands = collect.getAllCommands().collect(Collectors.toSet());
for (org.enginehub.piston.Command command : commands) {
/*FAWE start - if in FAWE, //fast will remain for now
(command.getName().equals("/fast")) {
// deprecate to `//perf`
commandManager.register(CommandUtil.deprecate(
command, "//fast duplicates //perf " +
"and will be removed in WorldEdit 8",
GeneralCommands::replaceFastForPerf
));
continue;
}
*/
commandManager.register(command);
}
}
use of org.enginehub.piston.CommandManager in project FastAsyncWorldEdit by IntellectualSites.
the class ToolCommands method register.
public static void register(CommandRegistrationHandler registration, CommandManager commandManager, CommandManagerService commandManagerService, WorldEdit worldEdit) {
// Collect the tool commands
CommandManager collect = commandManagerService.newCommandManager();
registration.register(collect, ToolCommandsRegistration.builder(), new ToolCommands(worldEdit));
// Register deprecated global commands
Set<org.enginehub.piston.Command> commands = collect.getAllCommands().collect(Collectors.toSet());
for (org.enginehub.piston.Command command : commands) {
if (command.getAliases().contains("unbind")) {
// Don't register new /tool <whatever> alias
command = command.toBuilder().aliases(Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias))).build();
}
if (command.getName().equals("stacker")) {
// Don't register /stacker
continue;
}
commandManager.register(CommandUtil.deprecate(command, "Global tool names cause conflicts " + "and will be removed in WorldEdit 8", CommandUtil.ReplacementMessageGenerator.forNewCommand(ToolCommands::asNonGlobal)));
}
// Remove aliases with / in them, since it doesn't make sense for sub-commands.
Set<org.enginehub.piston.Command> nonGlobalCommands = commands.stream().map(command -> command.toBuilder().aliases(Collections2.filter(command.getAliases(), alias -> !alias.startsWith("/"))).build()).collect(Collectors.toSet());
commandManager.register("tool", command -> {
command.addPart(SubCommandPart.builder(Caption.of("tool"), TextComponent.of("The tool to bind")).withCommands(nonGlobalCommands).required().build());
command.description(TextComponent.of("Binds a tool to the item in your hand"));
command.condition(new SubCommandPermissionCondition.Generator(nonGlobalCommands).build());
});
}
use of org.enginehub.piston.CommandManager in project FastAsyncWorldEdit by IntellectualSites.
the class PaintBrushCommands method register.
public static void register(CommandManagerService service, CommandManager commandManager, CommandRegistrationHandler registration) {
commandManager.register("paint", builder -> {
builder.description(Caption.of("worldedit.brush.paint.description"));
builder.action(org.enginehub.piston.Command.Action.NULL_ACTION);
CommandManager manager = service.newCommandManager();
registration.register(manager, PaintBrushCommandsRegistration.builder(), new PaintBrushCommands());
builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.paint")));
builder.addParts(REGION_FACTORY, RADIUS, DENSITY);
builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), Caption.of("worldedit.brush.paint.type")).withCommands(manager.getAllCommands().collect(Collectors.toList())).required().build());
});
}
Aggregations