Skip to content

Commit

Permalink
feat: import external docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Jan 22, 2024
1 parent cadf525 commit d8439e6
Show file tree
Hide file tree
Showing 13 changed files with 527 additions and 8 deletions.
Binary file added docs/assets/images/spring/cli.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/spring/completions.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/spring/descriptions.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/spring/help.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/spring/native.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ and `CommandManager#registerCommandPostProcessor`.

Incendo maintains some processors that you may depend on in your projects:

- [cloud-processors-confirmation](https://github.com/Incendo/cloud-processors/tree/master/cloud-processors-confirmation)
- [cloud-processors-cooldown](https://github.com/Incendo/cloud-processors/tree/master/cloud-processors-cooldown)
- [cloud-processors-requirements](https://github.com/Incendo/cloud-processors/tree/master/cloud-processors-requirements)
- [cloud-processors-confirmation](../processors/confirmation.md)
- [cloud-processors-cooldown](../processors/cooldown.md)
- [cloud-processors-requirements](../processors/requirements.md)

#### Exception handling

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ They are written for the Bukkit Minecraft API but the examples are not specific
- [:material-language-kotlin: Kotlin Support](kotlin/index.md)
- [:material-minecraft: Minecraft Integrations](minecraft/index.md)
- [:simple-discord: Discord Integrations](discord/index.md)
- [:material-factory: Postprocessors](https://github.com/Incendo/cloud-processors)
- [:material-factory: Postprocessors](processors/index.md)

</div>

Expand Down
95 changes: 95 additions & 0 deletions docs/processors/confirmation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# cloud-processors-confirmation

Postprocessor that adds the ability to require an extra confirmation before executing commands.

## Installation

Snapshots are available on the Sonatype Snapshots Repository:

```xml
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

<dependency>
<groupId>org.incendo</groupId>
<artifactId>cloud-processors-confirmation</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
```

## Usage

You have to create an instance of `ConfirmationManager`, which accepts a `ConfirmationConfiguration`:

```java
ConfirmationManager<YourSenderType> confirmationManager
= ConfirmationManager.of(configuration);
```

The configuration is created using a builder:

```java
ConfirmationConfiguration.<YourSenderType>builder()
.cache(cache)
.noPendingCommandNotifier(...)
.confirmationRequiredNotifier(...)
.build();
```

The notifiers are consumers that are invoked when different events take place. See the JavaDoc for more information.

The cache is an instance of `CloudCache`, the default implementations are:

- `GuavaCache`: Cache that wraps a Guava cache.
- `CaffeineCache`: Cache that wraps a Caffeine cache.
- `SimpleCache`: Cache that wraps a weak hashmap. This is not recommended to use as it may grow indefinitely and offers very
little control.

You then need to register the postprocessor to the command manager:

```java
commandManager.registerCommandPostProcessor(
confirmationManager.createPostProcessor()
);
```

Commands that have the confirmation meta key will now require confirmation before they can be executed.
You may pass a predicate to the configuration that accepts a command context and determines whether the confirmation
should be bypassed. This allows you to use permissions, flags and other methods to conditionally disable the confirmation
requirement.

You'll likely want to create a confirmation command, which can be done using the command execution handler returned by
the confirmation manager:

```java
commandManager.command(
commandManager.commandBuilder("confirm")
.handler(confirmationManager.createExecutionHandler())
);
```

### Builders

To indicate that a command requires confirmation you need to apply the `ConfirmationManager.META_CONFIRMATION_REQUIRED`
meta to the command. You may either to do this by manually applying it:

```java
commandBuilder.meta(ConfirmationManager.META_CONFIRMATION_REQUIRED, true)
```

or by decorating the builder using the confirmation manager:

```java
commandBuilder.apply(confirmationManager)
```

### Annotations

The module ships with a builder modifier that enables the use of the `@Confirmation` annotation. To install this, you
simply do:

```java
ConfirmationBuilderModifier.install(annotationParser);
```
127 changes: 127 additions & 0 deletions docs/processors/cooldown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# cloud-processors-cooldown

Postprocessor that adds command cooldowns.

## Installation

Snapshots are available on the Sonatype Snapshots Repository:

```xml
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

<dependency>
<groupId>org.incendo</groupId>
<artifactId>cloud-processors-cooldown</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
```

## Usage

The cooldown system is managed by a `CooldownManager`, so the first step is to create an instance of that:

```java
CooldownManager<YourSenderType> cooldownManager = CooldownManager.of(
configuration
);
```

The configuration is an instance of `CooldownConfiguration`. Refer to the JavaDocs for information about specific options,
but an example would be:

```java
CooldownConfiguration.<YourSenderType>builder()
.repository(CooldownRepository.forMap(new HashMap<>()))
.addActiveCooldownListener(...)
.addCooldownCreationListener(...)
.cooldownNotifier(notifier)
.build();
```

The listeners are invoked when different events take place. The active cooldown listener in particular may be used to
inform the command sender that their command execution got blocked due to an active cooldown.

The repository stores active cooldowns for a command sender in the form of cooldown profiles.
The cooldowns are grouped by their `CooldownGroup`, by default a unique group will be created per command.
You may create a named group by using `CooldownGroup.named(name)`. Commands that use the same cooldown group
will have their cooldowns shared by the command sender.

You may create a repository from a map, `CloudCache` or even implement your own. If you want to persist the cooldowns
across multiple temporary sessions then you may use a mapping repository to store the cooldown profiles for a persistent key,
rather than the potentially temporary command sender objects:

```java
CooldownRepository repository = CooldownRepository.mapping(
sender -> sender.uuid(),
CooldownRepository.forMap(new HashMap<UUID, CooldownProfile>())
);
```

You may also customize how the cooldown profiles are created by passing a `CooldownProfileFactory` to the `CooldownConfiguration`.

If you want to have the cooldowns automatically removed from the repository to prevent unused profiles from taking up memory you
may register a `ScheduledCleanupCreationListener`:

```java
CooldownRepository repository = CooldownRepository.forMap(new HashMap<>());
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
CooldownConfiguration configuration = CooldownConfiguration.<YourSenderType>builder()
// ...
.repository(repository)
.addCreationListener(new ScheduledCleanupCreationListener(executorService, repository))
.build();
```

You then need to register the postprocessor:

```java
commandManager.registerCommandPostProcessor(
cooldownManager.createPostprocessor()
);
```

### Builders

The cooldowns are configured using a `Cooldown` instance:

```java
Cooldown cooldown = Cooldown.of(
DurationFunction.constant(Duration.ofMinutes(5L))
);
Cooldown cooldown = Cooldown.of(
DurationFunction.constant(Duration.ofMinutes(5L)),
CooldownGroup.named("group-name")
);
```

which can then be applied to the command by either manually setting the meta value:

```java
commandBuilder.meta(CooldownManager.META_COOLDOWN_DURATION, cooldown);
```

or by applying the cooldown to the builder:

```java
commandBuilder.apply(cooldown);
```

### Annotations

Annotated commands may use the `@Cooldown` annotation:

```java
@Cooldown(duration = 5, timeUnit = ChronoUnit.MINUTES, group = "some-group")
public void yourCommand() {
// ...
}
```

You need to install the builder modifier for this to work:

```java
CooldownBuilderModifier.install(annotationParser);
```
11 changes: 11 additions & 0 deletions docs/processors/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# cloud-processors

## Modules

<div class="grid cards" markdown>

- [cloud-processors-confirmation](confirmation.md)
- [cloud-processors-cooldown](cooldown.md)
- [cloud-processors-requirements](requirements.md)

</div>
Loading

0 comments on commit d8439e6

Please sign in to comment.