# Fly Command

Funmands:

```java
public class FlyCommand extends PaperCommand {
    public FlyCommand() {
        super("fly", "I believe I can fly!", "f");

        this.addFormat("", ctx -> {
            if (!(ctx.getExecutor() instanceof final Player player)) {
                return;
            }
            player.setAllowFlight(!player.getAllowFlight());
            player.setFlying(player.getAllowFlight());
            player.sendMessage(MiniMessage.miniMessage().deserialize("<green>You are <flying> flying.</green>",
                    TagResolver.resolver("flying",
                            Tag.selfClosingInserting(Component.text(player.isFlying() ? "now" : "no longer")))));
        });
        this.addFormat("speed speed:int", ctx -> {
            if (!(ctx.getExecutor() instanceof final Player player)) {
                return;
            }
            final int speed = ctx.get("speed");
            if (Math.round(player.getFlySpeed() * 10) == speed) {
                player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You are already at speed <speed></red>",
                        TagResolver.resolver("speed",
                                Tag.selfClosingInserting(Component.text(speed)))));
                return;
            }
            player.setFlySpeed((float) speed / 10);
            player.sendMessage(MiniMessage.miniMessage().deserialize("Your fly speed is now: <yellow><speed></yellow>.",
                    TagResolver.resolver("speed",
                            Tag.selfClosingInserting(Component.text(speed)))));
        }, preCtx -> {
            preCtx.addOptions("speed", new IntegerArgument.Options(1, 10));
            preCtx.addSuggestions("speed", sender -> {
                return IntStream.range(1, 11)
                        .mapToObj(value -> {
                            return new Suggestion(String.valueOf(value), MiniMessage.miniMessage().deserialize("A fly speed of <speed>",
                                    TagResolver.resolver("speed", Tag.selfClosingInserting(Component.text(value)))));
                        }).collect(Collectors.toSet());
            });
        });
    }
}

```

A similar command in CommandAPI:

```java
public class FlyCommandAPICommand extends CommandAPICommand {
    public FlyCommandAPICommand() {
        super("fly");
        this
                .withShortDescription("I believe I can fly!")
                .withAliases("f")
                .executesEntity((entity, commandArguments) -> {
                    if (!(entity instanceof final Player player)) {
                        return;
                    }

                    player.setAllowFlight(!player.getAllowFlight());
                    player.setFlying(player.getAllowFlight());
                    player.sendMessage(MiniMessage.miniMessage().deserialize("<green>You are <flying> flying.</green>",
                            TagResolver.resolver("flying",
                                    Tag.selfClosingInserting(Component.text(player.isFlying() ? "now" : "no longer")))));
                })
                .withSubcommand(
                        new CommandAPICommand("speed")
                                .withArguments(new IntegerArgument("speed", 1, 10).replaceSuggestions((info, builder) -> {
                                    if (!(info.sender() instanceof final Player player)) return builder.buildFuture();
                                    IntStream.range(1, 11)
                                            .filter(value -> value != player.getFlySpeed())
                                            .forEach(value -> {
                                        builder.suggest(
                                                String.valueOf(value),
                                                MessageComponentSerializer.message().serialize(
                                                        MiniMessage.miniMessage().deserialize("A fly speed of <speed>",
                                                                TagResolver.resolver("speed",
                                                                        Tag.selfClosingInserting(Component.text(value))))
                                                )
                                        );
                                    });
                                    return builder.buildFuture();
                                }))
                                .executesEntity((entity, commandArguments) -> {
                                    if (!(entity instanceof final Player player)) {
                                        return;
                                    }
                                    final int speed = (int) commandArguments.get("speed");
                                    if (Math.round(player.getFlySpeed() * 10) == speed) {
                                        player.sendMessage(MiniMessage.miniMessage().deserialize("<red>You are already at speed <speed></red>",
                                                TagResolver.resolver("speed",
                                                        Tag.selfClosingInserting(Component.text(speed)))));
                                        return;
                                    }
                                    player.setFlySpeed((float) speed / 10);
                                    player.sendMessage(MiniMessage.miniMessage().deserialize("Your fly speed is now: <yellow><speed></yellow>.",
                                            TagResolver.resolver("speed",
                                                    Tag.selfClosingInserting(Component.text(speed)))));
                                })
                );
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://slimecraft.gitbook.io/slimecraft-docs/examples/fly-command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
