-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #31, #32, #36. <!-- readthedocs-preview incendocloud start --> ---- π Documentation preview π: https://incendocloud--38.org.readthedocs.build/en/38/ <!-- readthedocs-preview incendocloud end -->
- Loading branch information
1 parent
8afa943
commit d2ce0b6
Showing
11 changed files
with
221 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
[versions] | ||
indra = "3.1.3" | ||
|
||
cloud = "2.0.0-beta.2" | ||
cloudMinecraft = "2.0.0-beta.2" | ||
cloud = "2.0.0-rc.2" | ||
cloudMinecraft = "2.0.0-beta.8" | ||
cloudProcessors = "1.0.0-beta.3" | ||
|
||
paper = "1.20.6-R0.1-SNAPSHOT" | ||
|
||
[plugins] | ||
indra = { id = "net.kyori.indra", version.ref = "indra" } | ||
|
||
[libraries] | ||
cloud-core = { group = "org.incendo", name = "cloud-core", version.ref = "cloud" } | ||
|
||
# Minecraft | ||
cloud-minecraft-extras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloudMinecraft" } | ||
cloud-minecraft-paper = { group = "org.incendo", name = "cloud-paper", version.ref = "cloudMinecraft" } | ||
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" } | ||
|
||
# Processors | ||
cloud-processors-cooldown = { group = "org.incendo", name = "cloud-processors-cooldown", version.ref = "cloudProcessors" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
code/src/main/java/org/incendo/cloud/snippet/minecraft/PaperExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.incendo.cloud.snippet.minecraft; | ||
|
||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.cloud.SenderMapper; | ||
import org.incendo.cloud.execution.ExecutionCoordinator; | ||
import org.incendo.cloud.paper.LegacyPaperCommandManager; | ||
import org.incendo.cloud.paper.PaperCommandManager; | ||
|
||
public class PaperExample { | ||
|
||
public void exampleLegacyNative(final @NonNull JavaPlugin yourPlugin) { | ||
final ExecutionCoordinator<CommandSender> executionCoordinator = ExecutionCoordinator.simpleCoordinator(); | ||
// --8<-- [start:legacy_native] | ||
LegacyPaperCommandManager<CommandSender> commandManager = LegacyPaperCommandManager.createNative( | ||
yourPlugin, /* 1 */ | ||
executionCoordinator /* 2 */ | ||
); | ||
// --8<-- [end:legacy_native] | ||
} | ||
|
||
public void exampleLegacyCustom( | ||
final @NonNull JavaPlugin yourPlugin, | ||
final @NonNull SenderMapper<CommandSender, YourSenderType> senderMapper | ||
) { | ||
final ExecutionCoordinator<YourSenderType> executionCoordinator = ExecutionCoordinator.simpleCoordinator(); | ||
// --8<-- [start:legacy_custom] | ||
LegacyPaperCommandManager<YourSenderType> commandManager = new LegacyPaperCommandManager<>( | ||
yourPlugin, /* 1 */ | ||
executionCoordinator, /* 2 */ | ||
senderMapper /* 3 */ | ||
); | ||
// --8<-- [end:legacy_custom] | ||
} | ||
|
||
public void exampleModernNative(final @NonNull JavaPlugin javaPlugin) { | ||
final ExecutionCoordinator<CommandSourceStack> executionCoordinator = ExecutionCoordinator.simpleCoordinator(); | ||
// --8<-- [start:modern_native] | ||
PaperCommandManager<CommandSourceStack> commandManager = PaperCommandManager.builder() | ||
.executionCoordinator(executionCoordinator) | ||
.buildOnEnable(javaPlugin); | ||
// or: .buildBootstrapped(bootstrapContext); | ||
// --8<-- [end:modern_native] | ||
} | ||
|
||
public void exampleModernCustom( | ||
final @NonNull JavaPlugin javaPlugin, | ||
final @NonNull SenderMapper<CommandSourceStack, YourSenderType> senderMapper | ||
) { | ||
final ExecutionCoordinator<YourSenderType> executionCoordinator = ExecutionCoordinator.simpleCoordinator(); | ||
// --8<-- [start:modern_custom] | ||
PaperCommandManager<YourSenderType> commandManager = PaperCommandManager.builder(senderMapper) | ||
.executionCoordinator(executionCoordinator) | ||
.buildOnEnable(javaPlugin); | ||
// or: .buildBootstrapped(bootstrapContext); | ||
// --8<-- [end:modern_custom] | ||
} | ||
|
||
public record YourSenderType() { | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
code/src/main/java/org/incendo/cloud/snippet/processors/CooldownExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.incendo.cloud.snippet.processors; | ||
|
||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.cloud.CommandManager; | ||
import org.incendo.cloud.processors.cooldown.Cooldown; | ||
import org.incendo.cloud.processors.cooldown.CooldownConfiguration; | ||
import org.incendo.cloud.processors.cooldown.CooldownGroup; | ||
import org.incendo.cloud.processors.cooldown.CooldownManager; | ||
import org.incendo.cloud.processors.cooldown.CooldownRepository; | ||
import org.incendo.cloud.processors.cooldown.DurationFunction; | ||
import org.incendo.cloud.processors.cooldown.listener.ScheduledCleanupCreationListener; | ||
import org.incendo.cloud.processors.cooldown.profile.CooldownProfile; | ||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
/** | ||
* Example of Cooldown usage. | ||
*/ | ||
public class CooldownExample { | ||
|
||
public void configurationExample() { | ||
// --8<-- [start:configuration] | ||
CooldownRepository<YourSenderType> repository = CooldownRepository.forMap(new HashMap<>()); | ||
CooldownConfiguration<YourSenderType> configuration = CooldownConfiguration.<YourSenderType>builder() | ||
// ... | ||
.repository(repository) | ||
.addActiveCooldownListener(((sender, command, cooldown, remainingTime) -> { /* ... */})) | ||
.build(); | ||
// --8<-- [end:configuration] | ||
} | ||
|
||
public void cleanupExample() { | ||
// --8<-- [start:cleanup] | ||
CooldownRepository<YourSenderType> repository = CooldownRepository.forMap(new HashMap<>()); | ||
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); | ||
CooldownConfiguration<YourSenderType> configuration = CooldownConfiguration.<YourSenderType>builder() | ||
// ... | ||
.repository(repository) | ||
.addCreationListener(new ScheduledCleanupCreationListener<>(executorService, repository)) | ||
.build(); | ||
// --8<-- [end:cleanup] | ||
} | ||
|
||
public void registrationExample( | ||
final @NonNull CommandManager<YourSenderType> commandManager, | ||
final @NonNull CooldownManager<YourSenderType> cooldownManager | ||
) { | ||
// --8<-- [start:registration] | ||
commandManager.registerCommandPostProcessor( | ||
cooldownManager.createPostprocessor() | ||
); | ||
// --8<-- [end:registration] | ||
} | ||
|
||
public void creationExample(final @NonNull CooldownConfiguration<YourSenderType> configuration) { | ||
// --8<-- [start:creation] | ||
CooldownManager<YourSenderType> cooldownManager = CooldownManager.cooldownManager( | ||
configuration | ||
); | ||
// --8<-- [end:creation] | ||
} | ||
|
||
public void mappingExample() { | ||
// --8<-- [start:mapping] | ||
CooldownRepository<YourSenderType> repository = CooldownRepository.mapping( | ||
YourSenderType::uuid, | ||
CooldownRepository.forMap(new HashMap<>()) | ||
); | ||
// --8<-- [end:mapping] | ||
} | ||
|
||
public void cooldownExample() { | ||
// --8<-- [start:cooldown] | ||
Cooldown<YourSenderType> cooldown = Cooldown.of( | ||
DurationFunction.constant(Duration.ofMinutes(5L)) | ||
); | ||
Cooldown<YourSenderType> grouped = Cooldown.of( | ||
DurationFunction.constant(Duration.ofMinutes(5L)), | ||
CooldownGroup.named("group-name") | ||
); | ||
// --8<-- [end:cooldown] | ||
} | ||
|
||
private record YourSenderType(@NonNull UUID uuid) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.