Skip to content

Commit

Permalink
feat: tweaks & start of minecraft-extras docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Jan 22, 2024
1 parent b8b184b commit f38d688
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 16 deletions.
3 changes: 3 additions & 0 deletions docs/annotations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ instance of the class that you wish to parse.

## Command Methods

![Example Annotations](https://github.com/Incendo/cloud/blob/master/img/code/annotations_java_dark.png?raw=true#only-dark){ loading = lazy }
![Example Annotations](https://github.com/Incendo/cloud/blob/master/img/code/annotations_java_light.png?raw=true#only-light){ loading = lazy }

Command methods are annotated methods that are used to construct and handle commands.
The method has to be annotated with a `@Command` annotation that specifies the command
syntax.
Expand Down
Binary file added docs/assets/images/mce_help_1_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/mce_help_1_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/mce_help_2_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/mce_help_2_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 2 additions & 16 deletions docs/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,8 @@ parsing and suggestion generation asynchronously. You may customize the asynchro

### Building a command

<!-- prettier-ignore -->
!!! example
```java
Command<YourSenderType> command = manager.commandBuilder("command")
.commandDescription(commandDescription("This is an example of a command"))
.literal("literal")
.required("string", stringParser(), description("A string"))
.literal("another-literal")
.optional("integer", integerParser(), description("An integer"))
.handler(context -> {
String string = context.get("string");
int integer = context.getOrDefault("integer", 0);
// ...
})
.build();
```
![Example Builder](https://github.com/Incendo/cloud/blob/master/img/code/builder_java_dark.png?raw=true#only-dark)
![Example Builder](https://github.com/Incendo/cloud/blob/master/img/code/builder_java_light.png?raw=true#only-light)

Commands are created using a command builder.
You may either create a new builder by calling `Command.newBuilder` or through the command manager using
Expand Down
8 changes: 8 additions & 0 deletions docs/kotlin/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# cloud-kotlin

The Kotlin modules allow you to write commands using Kotlin. There is support for both
builders, and annotated command methods.

![Example Builder](https://github.com/Incendo/cloud/blob/master/img/code/builder_kotlin_dark.png?raw=true#only-dark){ loading = lazy }
![Example Builder](https://github.com/Incendo/cloud/blob/master/img/code/builder_kotlin_light.png?raw=true#only-light){ loading = lazy }
![Example Annotations](https://github.com/Incendo/cloud/blob/master/img/code/annotations_kotlin_dark.png?raw=true#only-dark){ loading = lazy }
![Example Annotations](https://github.com/Incendo/cloud/blob/master/img/code/annotations_kotlin_light.png?raw=true#only-light){ loading = lazy }

## Modules

<div class="grid cards" markdown>
Expand Down
5 changes: 5 additions & 0 deletions docs/minecraft/brigadier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cloud-brigadier

[Brigadier](https://github.com/mojang/brigadier) is Mojang's command system. Cloud integrates with Brigadier on platforms
where this is supported. Unless you want to create a platform integration it is unlikely that you will want to depend
on `cloud-brigadier` directly. Instead, you are able to interact with Brigadier through the platform integration.
17 changes: 17 additions & 0 deletions docs/minecraft/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# cloud-minecraft

## Modules

<div class="grid cards" markdown>

- [Brigadier](./brigadier.md)
- [Minecraft Extras](./minecraft-extras.md)
- [Bukkit](./bukkit.md)
- [Paper](./paper.md)
- [Velocity](./velocity.md)
- [BungeeCord](./bungee.md)
- [NeoForge](./neoforge.md)
- [Fabric](./fabric.md)
- [Sponge](./sponge.md)
- [Cloudburst](./cloudburst.md)

</div>
115 changes: 115 additions & 0 deletions docs/minecraft/minecraft-extras.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# cloud-minecraft-extras

`cloud-minecraft-extras` contains some optional utilities for the Minecraft integrations.

<div class="grid cards" markdown>

- [MinecraftHelp](#minecraft-help)
- [MinecraftExceptionHandler](#minecraft-exception-handler)
- [RichDescription](#rich-description)
- [TextColorParser](#text-color-parser)

</div>

<!-- prettier-ignore -->
!!! note
These utilities depend on [adventure](https://docs.advntr.dev/). You may need to depend on Adventure and shade it
into your project, depending on the platform you're targeting. Many Minecraft platforms, such as Paper, ship with
native implementations of Adventure, in which case you do not need to include it yourself.

## Minecraft Help

`MinecraftHelp` is an opinionated implementation of the [help system](../core/index.md#help-generation) using
Adventure components for styling and click handling.

![Minecraft Help 1](../assets/images/mce_help_1_dark.png#only-dark)
![Minecraft Help 1](../assets/images/mce_help_1_light.png#only-light)
![Minecraft Help 2](../assets/images/mce_help_2_dark.png#only-dark)
![Minecraft Help 2](../assets/images/mce_help_2_light.png#only-light)

All interactions with the Minecraft help system will take place through a `MinecraftHelp` instance.

You may create an instance with the default styling:

<!-- prettier-ignore -->
=== "Native Audience"

```java
// Assuming YourSenderType extends Audience
MinecraftHelp<YourSenderType> help = MinecraftHelp.createNative(
"helpcommand",
commandManager
);
```

=== "Other"

```java
MinecraftHelp<YourSenderType> help = MinecraftHelp.create(
"helpcommand",
commandManager,
audienceMapper // YourSenderType -> Audience
);
```

or you may override the defaults by using a builder:

<!-- prettier-ignore -->
=== "Native Audience"

```java
MinecraftHelp<YourSenderType> help = MinecraftHelp.<YourSenderType>builder()
.commandManager(commandManager)
.audienceProvider(AudienceProvider.nativeProvider())
.commandPrefix("/helpcommand")
/* other settings... */
.build();
```

=== "Other"

```java
MinecraftHelp<YourSenderType> help = MinecraftHelp.<YourSenderType>builder()
.commandManager(commandManager)
.audienceProvider(yourAudienceProvider)
.commandPrefix("/helpcommand")
/* other settings... */
.build();
```

You then want to invoke `MinecraftHelp.queryCommands(query, recipient)` in order to query the commands
and display the results to the recipient.

```java title="Example Help Command"
commandManager.command(
commandManager.commandBuilder("helpcommand")
.optional("query", greedyStringParser(), DefaultValue.constant(""))
.handler(context -> {
help.queryCommands(context.get("query"), context.sender());
})
);
```

You may choose to add suggestions to the query argument as well:

```java title="Query Suggestions"
.optional(
"query",
greedyStringParser(),
DefaultValue.constant(""),
SuggestionProvider.blocking((ctx, in) -> commandManager.createHelpHandler()
.queryRootIndex(ctx.sender())
.entries()
.stream()
.map(CommandEntry::syntax)
.map(Suggestion::simple)
.collect(Collectors.toList())
)
)
```

## Minecraft Exception Handler

## Rich Description

## Text Color Parser

0 comments on commit f38d688

Please sign in to comment.