# Pre-Context

Since a **context** is only created **after** a command is executed, you can't take full advantage of Brigadier's features like command requirements (who can see a command; it will say command not found and display red if the requirements are not met), or argument suggestions. That's where the pre-context comes in.

> A pre-context allows you to execute logic **before** your command is executed.

```java
addFormat("int:foo", context -> {
            if (!(context.getSender() instanceof final Player player)) {
                return;
            }
            final int foo = context.get("foo");
            final CommandSender sender = context.getSender();
            sender.sendMessage(player.getName());
            sender.sendMessage(Component.text(foo));
        }, pre -> {
            pre.setPredicate(sender -> sender.hasPermission("foo.bar.baz"));
            pre.addSuggestion("foo", sender -> IntStream.range(1, 10).mapToObj(value -> {
                return new Suggestion(String.valueOf(value));
            }).toList());
        });
```

The above code does the following:

* Add a requirement for the sender to have the permission "foo.bar.baz"
* Return a list of suggestions from an IntStream that will be showed as suggestions for this argument


---

# 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/deep-dive/context/pre-context.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.
