Skip to content

Commit d2ce0b6

Browse files
authored
feat: misc. updates (#38)
Closes #31, #32, #36. <!-- readthedocs-preview incendocloud start --> ---- πŸ“š Documentation preview πŸ“š: https://incendocloud--38.org.readthedocs.build/en/38/ <!-- readthedocs-preview incendocloud end -->
1 parent 8afa943 commit d2ce0b6

11 files changed

Lines changed: 221 additions & 72 deletions

File tree

β€Ž.github/workflows/gradle.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: actions/setup-java@v4
2222
with:
2323
distribution: "temurin"
24-
java-version: 17
24+
java-version: 21
2525
- uses: gradle/gradle-build-action@v2
2626
with:
2727
# allow master and *-dev branches to write caches (default is only master/main)

β€Žcode/build.gradle.ktsβ€Ž

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ plugins {
44

55
dependencies {
66
implementation(libs.cloud.core)
7+
8+
// Minecraft
79
implementation(libs.cloud.minecraft.extras)
10+
implementation(libs.cloud.minecraft.paper)
11+
implementation(libs.paper)
12+
13+
// Processors
14+
implementation(libs.cloud.processors.cooldown)
815
}
916

1017
indra {
1118
javaVersions {
12-
minimumToolchain(8)
13-
target(8)
19+
minimumToolchain(21)
20+
target(21)
1421
}
1522
}
1623

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
[versions]
22
indra = "3.1.3"
33

4-
cloud = "2.0.0-beta.2"
5-
cloudMinecraft = "2.0.0-beta.2"
4+
cloud = "2.0.0-rc.2"
5+
cloudMinecraft = "2.0.0-beta.8"
6+
cloudProcessors = "1.0.0-beta.3"
7+
8+
paper = "1.20.6-R0.1-SNAPSHOT"
69

710
[plugins]
811
indra = { id = "net.kyori.indra", version.ref = "indra" }
912

1013
[libraries]
1114
cloud-core = { group = "org.incendo", name = "cloud-core", version.ref = "cloud" }
15+
16+
# Minecraft
1217
cloud-minecraft-extras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloudMinecraft" }
18+
cloud-minecraft-paper = { group = "org.incendo", name = "cloud-paper", version.ref = "cloudMinecraft" }
19+
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" }
20+
21+
# Processors
22+
cloud-processors-cooldown = { group = "org.incendo", name = "cloud-processors-cooldown", version.ref = "cloudProcessors" }

β€Žcode/settings.gradle.ktsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ dependencyResolutionManagement {
2222
name = "dv8tion"
2323
mavenContent { releasesOnly() }
2424
}
25+
maven("https://repo.papermc.io/repository/maven-public/") {
26+
name = "papermc"
27+
}
2528
}
2629
}
2730

β€Žcode/src/main/java/org/incendo/cloud/snippet/minecraft/MinecraftHelpExample.javaβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void helpCommand(final @NonNull CommandManager<NativeSenderType> commandM
7070
.entries()
7171
.stream()
7272
.map(CommandEntry::syntax)
73-
.map(Suggestion::simple)
73+
.map(Suggestion::suggestion)
7474
.collect(Collectors.toList())
7575
)
7676
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.incendo.cloud.snippet.minecraft;
2+
3+
import io.papermc.paper.command.brigadier.CommandSourceStack;
4+
import org.bukkit.command.CommandSender;
5+
import org.bukkit.plugin.java.JavaPlugin;
6+
import org.checkerframework.checker.nullness.qual.NonNull;
7+
import org.incendo.cloud.SenderMapper;
8+
import org.incendo.cloud.execution.ExecutionCoordinator;
9+
import org.incendo.cloud.paper.LegacyPaperCommandManager;
10+
import org.incendo.cloud.paper.PaperCommandManager;
11+
12+
public class PaperExample {
13+
14+
public void exampleLegacyNative(final @NonNull JavaPlugin yourPlugin) {
15+
final ExecutionCoordinator<CommandSender> executionCoordinator = ExecutionCoordinator.simpleCoordinator();
16+
// --8<-- [start:legacy_native]
17+
LegacyPaperCommandManager<CommandSender> commandManager = LegacyPaperCommandManager.createNative(
18+
yourPlugin, /* 1 */
19+
executionCoordinator /* 2 */
20+
);
21+
// --8<-- [end:legacy_native]
22+
}
23+
24+
public void exampleLegacyCustom(
25+
final @NonNull JavaPlugin yourPlugin,
26+
final @NonNull SenderMapper<CommandSender, YourSenderType> senderMapper
27+
) {
28+
final ExecutionCoordinator<YourSenderType> executionCoordinator = ExecutionCoordinator.simpleCoordinator();
29+
// --8<-- [start:legacy_custom]
30+
LegacyPaperCommandManager<YourSenderType> commandManager = new LegacyPaperCommandManager<>(
31+
yourPlugin, /* 1 */
32+
executionCoordinator, /* 2 */
33+
senderMapper /* 3 */
34+
);
35+
// --8<-- [end:legacy_custom]
36+
}
37+
38+
public void exampleModernNative(final @NonNull JavaPlugin javaPlugin) {
39+
final ExecutionCoordinator<CommandSourceStack> executionCoordinator = ExecutionCoordinator.simpleCoordinator();
40+
// --8<-- [start:modern_native]
41+
PaperCommandManager<CommandSourceStack> commandManager = PaperCommandManager.builder()
42+
.executionCoordinator(executionCoordinator)
43+
.buildOnEnable(javaPlugin);
44+
// or: .buildBootstrapped(bootstrapContext);
45+
// --8<-- [end:modern_native]
46+
}
47+
48+
public void exampleModernCustom(
49+
final @NonNull JavaPlugin javaPlugin,
50+
final @NonNull SenderMapper<CommandSourceStack, YourSenderType> senderMapper
51+
) {
52+
final ExecutionCoordinator<YourSenderType> executionCoordinator = ExecutionCoordinator.simpleCoordinator();
53+
// --8<-- [start:modern_custom]
54+
PaperCommandManager<YourSenderType> commandManager = PaperCommandManager.builder(senderMapper)
55+
.executionCoordinator(executionCoordinator)
56+
.buildOnEnable(javaPlugin);
57+
// or: .buildBootstrapped(bootstrapContext);
58+
// --8<-- [end:modern_custom]
59+
}
60+
61+
public record YourSenderType() {
62+
}
63+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.incendo.cloud.snippet.processors;
2+
3+
import org.checkerframework.checker.nullness.qual.NonNull;
4+
import org.incendo.cloud.CommandManager;
5+
import org.incendo.cloud.processors.cooldown.Cooldown;
6+
import org.incendo.cloud.processors.cooldown.CooldownConfiguration;
7+
import org.incendo.cloud.processors.cooldown.CooldownGroup;
8+
import org.incendo.cloud.processors.cooldown.CooldownManager;
9+
import org.incendo.cloud.processors.cooldown.CooldownRepository;
10+
import org.incendo.cloud.processors.cooldown.DurationFunction;
11+
import org.incendo.cloud.processors.cooldown.listener.ScheduledCleanupCreationListener;
12+
import org.incendo.cloud.processors.cooldown.profile.CooldownProfile;
13+
import java.time.Duration;
14+
import java.util.HashMap;
15+
import java.util.UUID;
16+
import java.util.concurrent.Executors;
17+
import java.util.concurrent.ScheduledExecutorService;
18+
19+
/**
20+
* Example of Cooldown usage.
21+
*/
22+
public class CooldownExample {
23+
24+
public void configurationExample() {
25+
// --8<-- [start:configuration]
26+
CooldownRepository<YourSenderType> repository = CooldownRepository.forMap(new HashMap<>());
27+
CooldownConfiguration<YourSenderType> configuration = CooldownConfiguration.<YourSenderType>builder()
28+
// ...
29+
.repository(repository)
30+
.addActiveCooldownListener(((sender, command, cooldown, remainingTime) -> { /* ... */}))
31+
.build();
32+
// --8<-- [end:configuration]
33+
}
34+
35+
public void cleanupExample() {
36+
// --8<-- [start:cleanup]
37+
CooldownRepository<YourSenderType> repository = CooldownRepository.forMap(new HashMap<>());
38+
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
39+
CooldownConfiguration<YourSenderType> configuration = CooldownConfiguration.<YourSenderType>builder()
40+
// ...
41+
.repository(repository)
42+
.addCreationListener(new ScheduledCleanupCreationListener<>(executorService, repository))
43+
.build();
44+
// --8<-- [end:cleanup]
45+
}
46+
47+
public void registrationExample(
48+
final @NonNull CommandManager<YourSenderType> commandManager,
49+
final @NonNull CooldownManager<YourSenderType> cooldownManager
50+
) {
51+
// --8<-- [start:registration]
52+
commandManager.registerCommandPostProcessor(
53+
cooldownManager.createPostprocessor()
54+
);
55+
// --8<-- [end:registration]
56+
}
57+
58+
public void creationExample(final @NonNull CooldownConfiguration<YourSenderType> configuration) {
59+
// --8<-- [start:creation]
60+
CooldownManager<YourSenderType> cooldownManager = CooldownManager.cooldownManager(
61+
configuration
62+
);
63+
// --8<-- [end:creation]
64+
}
65+
66+
public void mappingExample() {
67+
// --8<-- [start:mapping]
68+
CooldownRepository<YourSenderType> repository = CooldownRepository.mapping(
69+
YourSenderType::uuid,
70+
CooldownRepository.forMap(new HashMap<>())
71+
);
72+
// --8<-- [end:mapping]
73+
}
74+
75+
public void cooldownExample() {
76+
// --8<-- [start:cooldown]
77+
Cooldown<YourSenderType> cooldown = Cooldown.of(
78+
DurationFunction.constant(Duration.ofMinutes(5L))
79+
);
80+
Cooldown<YourSenderType> grouped = Cooldown.of(
81+
DurationFunction.constant(Duration.ofMinutes(5L)),
82+
CooldownGroup.named("group-name")
83+
);
84+
// --8<-- [end:cooldown]
85+
}
86+
87+
private record YourSenderType(@NonNull UUID uuid) {
88+
89+
}
90+
}

β€Ždocs/annotations/index.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The module can also function as an [annotation processor](#annotation-processing
88
There are extensions to `cloud-annotations` for Kotlin, more information [here](../kotlin/annotations.md).
99

1010
Examples can be found on
11-
[GitHub](https://github.com/Incendo/cloud-minecraft/tree/master/examples/example-bukkit/src/main/java/cloud/commandframework/examples/bukkit/annotations)
11+
[GitHub](https://github.com/Incendo/cloud-minecraft/tree/master/examples/example-bukkit/src/main/java/org/incendo/cloud/examples/bukkit/annotations)
1212

1313
## Links
1414

β€Ždocs/minecraft/paper.mdβ€Ž

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,30 @@ Cloud for Paper is available through [Maven Central](https://central.sonatype.co
2424

2525
## Usage
2626

27-
`cloud-paper` has a command manager implementation called
28-
{{ javadoc("https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/PaperCommandManager.html", "PaperCommandManager") }}
29-
that can be created in two ways.
27+
`cloud-paper` has two different command manager implementations:
28+
29+
- {{ javadoc("https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/PaperCommandManager.html", "PaperCommandManager") }}: Paper command API
30+
- {{ javadoc("https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/LegacyPaperCommandManager.html", "LegacyPaperCommandManager") }}: Legacy command API
31+
32+
{{ javadoc("https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/PaperCommandManager.html", "PaperCommandManager") }} should be preferred
33+
when targeting Paper 1.20.6+ exclusively. The new manager allows registering commands at bootstrapping time in addition to `onEnable`,
34+
which allows for using those commands in datapack functions.
35+
36+
If the plugin is targeting older Paper versions or non-paper servers, then
37+
{{ javadoc("https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/LegacyPaperCommandManager.html", "LegacyPaperCommandManager") }}
38+
should be used.
39+
40+
### Legacy
41+
42+
The legacy command manager can be instantiated in two different ways.
3043

3144
With a custom sender type:
3245

33-
```java
34-
PaperCommandManager<YourSenderType> commandManager = new PaperCommandManager<>(
35-
yourPlugin, /* 1 */
36-
executionCoordinator, /* 2 */
37-
senderMapper /* 3 */
38-
);
39-
```
46+
{{ snippet("minecraft/PaperExample.java", section = "legacy_custom", title = "") }}
4047

4148
Or, using Bukkit's {{ javadoc("https://jd.papermc.io/paper/1.20/org/bukkit/command/CommandSender.html", "CommandSender") }}:
4249

43-
```java
44-
PaperCommandManager<CommandSender> commandManager = PaperCommandManager.createNative(
45-
yourPlugin, /* 1 */
46-
executionCoordinator /* 2 */
47-
);
48-
```
50+
{{ snippet("minecraft/PaperExample.java", section = "legacy_native", title = "") }}
4951

5052
1. You need to pass an instance of the plugin that is constructing the command manager. This is used to register
5153
the commands and the different event listeners.
@@ -55,16 +57,26 @@ PaperCommandManager<CommandSender> commandManager = PaperCommandManager.createNa
5557
3. The sender mapper is a two-way mapping between Bukkit's
5658
{{ javadoc("https://jd.papermc.io/paper/1.20/org/bukkit/command/CommandSender.html", "CommandSender") }} and your custom sender type.
5759
Using {{ javadoc("<https://javadoc.io/doc/org.incendo/cloud-core/latest/org/incendo/cloud/SenderMapper.html#identity()>", "SenderMapper.identity()") }}
58-
is equivalent to the {{ javadoc("<https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/PaperCommandManager.html#createNative(org.bukkit.plugin.Plugin,org.incendo.cloud.execution.ExecutionCoordinator)>", "createNative") }}
60+
is equivalent to the {{ javadoc("<https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/LegacyPaperCommandManager.html#createNative(org.bukkit.plugin.Plugin,org.incendo.cloud.execution.ExecutionCoordinator)>", "createNative") }}
5961
static factory method.
6062

63+
### Modern
64+
65+
The modern command manager is created using a builder. You may either use the native
66+
{{ javadoc("https://jd.papermc.io/paper/1.20.6/io/papermc/paper/command/brigadier/CommandSourceStack.html", "CommandSourceStack") }}:
67+
{{ snippet("minecraft/PaperExample.java", section = "modern_native", title = "") }}
68+
69+
or a custom type:
70+
{{ snippet("minecraft/PaperExample.java", section = "modern_custom", title = "") }}
71+
6172
## Brigadier
6273

6374
Paper exposes [Brigadier](https://github.com/mojang/brigadier), which means that you may use the features
64-
from [cloud-brigadier](brigadier.md) on Paper servers.
75+
from [cloud-brigadier](brigadier.md) on Paper servers. When using the modern Paper manager, you do not need to explicitly
76+
enable Brigadier.
6577

66-
You may enable Brigadier mappings using
67-
{{ javadoc("<https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/PaperCommandManager.html#registerBrigadier()>", "PaperCommandManager#registerBrigadier()") }}.
78+
When using the legacy command manager you may enable Brigadier mappings using
79+
{{ javadoc("<https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/LegacyPaperCommandManager.html#registerBrigadier()>", "LegacyPaperCommandManager#registerBrigadier()") }}.
6880
You should make use of the
6981
capability system to make sure that Brigadier is available on the server your plugin is running on:
7082

@@ -85,7 +97,7 @@ Paper allows for non-blocking suggestions. You are highly recommended to make us
8597
the argument parsers during suggestion generation which ideally should not take place on the main server thread.
8698

8799
You may enable asynchronous completions using
88-
{{ javadoc("<https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/PaperCommandManager.html#registerAsynchronousCompletions()>", "PaperCommandManager#registerAsynchronousCompletions()") }}.
100+
{{ javadoc("<https://javadoc.io/doc/org.incendo/cloud-paper/latest/org/incendo/cloud/paper/LegacyPaperCommandManager.html#registerAsynchronousCompletions()>", "LegacyPaperCommandManager#registerAsynchronousCompletions()") }}.
89101
You should make use of the capability system to make sure that this is available on the server your plugin is running on:
90102

91103
```java

0 commit comments

Comments
Β (0)