# Console Delegate

{% hint style="info" %}
Console Delegate is the only way to prompt a player and execute the finalized command as the console.
{% endhint %}

We can think of this feature as a new way to invoke the core part of CommandPrompter, the prompting feature. Instead of intercepting a command executed by a player, we can simply call the Console Delegate command, provide a target player, and the command you want that target player to fulfill.&#x20;

<details>

<summary>Motivation</summary>

Due to how CommandPrompter works, we can't simply allow completed commands to be executed beyond the permission of the player who's calling that command. This is because CommandPrompter listens to player commands and if they have a PromptQueue argument that augments the whole PromptQueue to be dispatched as console, it leads to a very exploitable vulnerability. This essentially boils down to the fact that we cannot control what the player inputs as a command.

However, with the new console delegate command, we can instead delegate the prompting to a `target player` . Once the command is completed, it's then sent back to the console to be executed as the console, not the player.

</details>

## The Console Delegate Command

As I've mentioned before, this command can only be called from the console. However, there's still a permission (`commandprompter.consoledelegate`) associated with this command to make sure that it does not appear in the player's tab complete without that permission.

{% hint style="info" %}
Players with `OP` will be able to see the `/consoledelegate` command on their tab complete. However, CommandPrompter will not process the console delegate command if the sender instance is not `ConsoleSender`.
{% endhint %}

### Usage

The console delegate command has the following format:

```
consoledelegate <target_player> <command...>
```

The last part of this argument is a greedy argument. Therefore, everything past the first argument which is the `target player` will be combined into one string and be considered as a command. This command will then be parsed and featuresdelegated to the `target player` to be completed.

You can also use the placeholder `%target_player%` somewhere in your command to replace it with your actual target player.

### Example

```
consoledelegate CyR1en gamemode <what gamemode> %target_player%
```

Here, we are using the default `gamemode` command and we're delegating the prompt to the player `CyR1en`. Let's say the player inputted `creative`, the completed command that will be executed by the console is:

```
gamemode creative CyR1en
```

#### Example with PostCommand

We can also take advantage of CommandPrompter's feature like PostCommand.

{% code overflow="wrap" fullWidth="false" %}

```
consoledelegate CyR1en gamemode <what gamemode> %target_player% <-exa broadcast Gamemode changed to p:0 for %target_player%>
```

{% endcode %}

The command above will be executed like the first example. However, we have a post command that executes the following command:

```
broadcast Gamemode changed to creative for CyR1en
```

{% hint style="info" %}
Post Command for Console Delegate will also be executed as the console
{% endhint %}

#### Video Example

{% embed url="<https://cdn.discordapp.com/attachments/936347464791883867/1169911067279904818/2023-11-03_01-48-24.mp4?ex=65571f96&hm=68a370a744c88689f779b3269e33e1a34e6942913ed99cc454c2650ac8fa4671&is=6544aa96>" %}


---

# 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://cyr1en.gitbook.io/commandprompter/features/console-delegate.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.
