Skip to content

Commit

Permalink
Cloud Command System Migration
Browse files Browse the repository at this point in the history
# Introduction

**This is the first pass of the cloud command migration for FAVS.**
There will be a second one to restore old-fashioned command syntax, tracked as IntellectualSites#81.

_I have to highlight that this is my first experience with this, must-say wonderful, command system. I have spent a lot of time reading every available documentation and code piece. If @Citymonstret want to take a look and maybe give us tips to avoid "ugly" workarounds or handling, we would be glad!_

The whole pull request has been tested, not yet thoroughly, you can have a global overview, but it is not really ready.

If you have any question or remark, do not hesitate!

--

# General Command Management
I have opted to use the annotations extension of the cloud command system. In my opinion, this is better suited to the current brush format handling which is all done inside brush classes.

**Executors have been kept and brush & performer command are still handled inside their classes.**

- ``Snipe`` class has been extended for a usage as a commander, because FAVS relies on a lot on this class.
- ``CommandRegistry`` is the main place for the whole handling behind the scenes. Otherwise, commands are registered as usually done in cloud, with some specific annotations when needed.

**``SniperCommander`` class is the commander to use with cloud command system. If the player exists, it returns its sniper. Otherwise, it returns a simple ``SniperSender``, similar to ``CommandSender``.**

# Command Manager
FAVS uses the paper command manager, when available, to enjoy some improvements. Falls back to bukkit command manager otherwise.

- Async tab-completions are enabled if available.
- ``Snipe``, ``PerformerSnipe`` & ``Toolkit`` classes are registered into the injector in order to be injected in command methods.
- Command exceptions are adapted and customized with the FAVS message syntax.

# Command Post-Processor
FAVS requires the command post-processor ins order handle specific FAVS behavior.

- Handles the ``@RequireToolkit`` annotation, makes sure the toolkit is available and the value stored.
- Handles the ``@DynamicRange`` annotation, used to define a range from non-constant variables, using reflection.
- Prepares the brush & performer when needed, their ``Snipe`` and stores them.

# Annotations & Parser
FAVS uses some annotations to facilitate development, based on common rules and behaviors.

- Handles the ``@RequireToolkit`` annotation, modifies the command meta.
- Handles the custom command execution method handler, which should differ for brush & performer. Cloud commands are designed to live in a class instance, this is not suitable to the current management of brush & performer. I have opted for a custom execution method which uses the brush & performer instance from the execution context instead of the base instance. _This avoid extra parameters for each command method._

# Arguments
FAVS needs a lot of custom arguments for either factories, registries, custom types, custom needs, etc.

**Suggestions & parsers are also declared via annotations in custom classes.**

# Other Changes
- All classes related to internal command managing from VS have been removed.
- ``FastAsyncVoxelSniper`` class has been removed. As far as I know, this class was useless and is now for sure.
- Some classes and methods have been added or refactored, but the overall codebase is the same to try keeping maximum compatibility.
- Some translations have been reorganized or removed.
- Some code format has been modified, there will be another pull request next year hopefully to unify comments format.
- Improvements to brush properties loading. Previously, all aliases were loaded, subsequently loading the same brush several times.
- Modern switch syntax has replaced old ones.
- General improvements.

# Known Problems:
- There is currently one small issue with static/literal arguments and their aliases. Tab-completions are not handled for all aliases due to https://github.com/Incendo/cloud/blob/master/cloud-core/src/main/java/cloud/commandframework/arguments/StaticArgument.java#L134.
- Brigadier extension is voluntarily not used due to some incompatibilities with FAVS commands syntax.
  • Loading branch information
Aurelien30000 committed Oct 15, 2023
1 parent ecf8611 commit 2d85872
Show file tree
Hide file tree
Showing 184 changed files with 7,214 additions and 5,038 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ dependencies {
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit")
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")

// Cloud command system
implementation(libs.cloudcore)
implementation(libs.cloudannotations)
implementation(libs.cloudbukkit)
implementation(libs.cloudpaper)

// Third party
implementation("dev.notmyfault.serverlib:ServerLib")
implementation("org.bstats:bstats-base")
Expand Down Expand Up @@ -97,6 +103,7 @@ tasks {
this.archiveClassifier.set(null as String?)
this.archiveFileName.set("${project.name}-${project.version}.${this.archiveExtension.getOrElse("jar")}")
this.destinationDirectory.set(rootProject.tasks.shadowJar.get().destinationDirectory.get())
relocate("cloud.commandframework", "com.thevoxelbox.voxelsniper.cloud")
relocate("org.incendo.serverlib", "com.thevoxelbox.voxelsniper.serverlib")
relocate("org.bstats", "com.thevoxelbox.voxelsniper.metrics")
relocate("io.papermc.lib", "com.thevoxelbox.voxelsniper.paperlib")
Expand Down
9 changes: 9 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Annotations
annotations = "24.0.1"

# Cloud command system
cloud = "1.8.3"

# Gradle plugins
shadow = "8.1.1"
pluginyml = "0.6.0"
Expand All @@ -14,6 +17,12 @@ hangar = "0.1.0"
# Annotations
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }

# Cloud command system
cloudcore = { group = "cloud.commandframework", name = "cloud-core", version.ref = "cloud" }
cloudannotations = { group = "cloud.commandframework", name = "cloud-annotations", version.ref = "cloud" }
cloudbukkit = { group = "cloud.commandframework", name = "cloud-bukkit", version.ref = "cloud" }
cloudpaper = { group = "cloud.commandframework", name = "cloud-paper", version.ref = "cloud" }

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
pluginyml = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" }
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/com/thevoxelbox/voxelsniper/BrushRegistrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ private void registerBlockResetBrush() {
BrushProperties properties = BrushProperties.builder()
.name("Block Reset")
.permission("voxelsniper.brush.blockreset")
.alias("brb")
.alias("blockresetbrush")
.alias("br")
.alias("blockreset")
.alias("block_reset")
.brushPatternType(BrushPatternType.ANY)
.creator(BlockResetBrush::new)
Expand All @@ -290,8 +290,8 @@ private void registerBlockResetSurfaceBrush() {
BrushProperties properties = BrushProperties.builder()
.name("Block Reset Surface")
.permission("voxelsniper.brush.blockresetsurface")
.alias("brbs")
.alias("blockresetbrushsurface")
.alias("brs")
.alias("blockresetsurface")
.alias("block_reset_surface")
.brushPatternType(BrushPatternType.ANY)
.creator(BlockResetSurfaceBrush::new)
Expand Down Expand Up @@ -429,8 +429,8 @@ private void registerDomeBrush() {
BrushProperties properties = BrushProperties.builder()
.name("Dome")
.permission("voxelsniper.brush.dome")
.alias("do")
.alias("dome")
.alias("domebrush")
.brushPatternType(BrushPatternType.PATTERN)
.creator(DomeBrush::new)
.build();
Expand All @@ -441,6 +441,7 @@ private void registerDrainBrush() {
BrushProperties properties = BrushProperties.builder()
.name("Drain")
.permission("voxelsniper.brush.drain")
.alias("dr")
.alias("drain")
.brushPatternType(BrushPatternType.ANY)
.creator(DrainBrush::new)
Expand Down Expand Up @@ -515,7 +516,9 @@ private void registerErodeBlendBrush() {
.permission("voxelsniper.brush.erodeblend")
.alias("eb")
.alias("erodeblend")
.alias("erode_blend")
.alias("erodeblendball")
.alias("erode_blend_ball")
.brushPatternType(BrushPatternType.ANY)
.creator(ErodeBlendBrush::new)
.build();
Expand Down Expand Up @@ -604,6 +607,7 @@ private void registerJaggedLineBrush() {
.permission("voxelsniper.brush.jaggedline")
.alias("j")
.alias("jagged")
.alias("jaggedline")
.alias("jagged_line")
.brushPatternType(BrushPatternType.PATTERN)
.creator(JaggedLineBrush::new)
Expand Down Expand Up @@ -723,7 +727,7 @@ private void registerRandomErodeBrush() {
.permission("voxelsniper.brush.randomerode")
.alias("re")
.alias("randomerode")
.alias("randome_rode")
.alias("random_erode")
.brushPatternType(BrushPatternType.ANY)
.creator(RandomErodeBrush::new)
.build();
Expand All @@ -734,8 +738,8 @@ private void registerRegenerateChunkBrush() {
BrushProperties properties = BrushProperties.builder()
.name("Regenerate Chunk")
.permission("voxelsniper.brush.regeneratechunk")
.alias("gc")
.alias("generatechunk")
.alias("rc")
.alias("regeneratechunk")
.alias("regenerate_chunk")
.brushPatternType(BrushPatternType.ANY)
.creator(RegenerateChunkBrush::new)
Expand All @@ -760,6 +764,7 @@ private void registerRotation2DBrush() {
.name("Rotation 2D")
.permission("voxelsniper.brush.rot2d")
.alias("rot2")
.alias("rot2d")
.alias("rotation2d")
.alias("rotation_2d")
.brushPatternType(BrushPatternType.ANY)
Expand All @@ -773,6 +778,7 @@ private void registerRotation2DVerticalBrush() {
.name("Rotation 2D Vertical")
.permission("voxelsniper.brush.rot2dvert")
.alias("rot2v")
.alias("rot2dv")
.alias("rotation2dvertical")
.alias("rotation_2d_vertical")
.brushPatternType(BrushPatternType.ANY)
Expand All @@ -786,6 +792,7 @@ private void registerRotation3DBrush() {
.name("Rotation 3D")
.permission("voxelsniper.brush.rot3d")
.alias("rot3")
.alias("rot3d")
.alias("rotation3d")
.alias("rotation_3d")
.brushPatternType(BrushPatternType.ANY)
Expand Down Expand Up @@ -942,7 +949,7 @@ private void registerSplatterBallBrush() {
.name("Splatter Ball")
.permission("voxelsniper.brush.splatterball")
.alias("sb")
.alias("splatball")
.alias("splatterball")
.alias("splatter_ball")
.brushPatternType(BrushPatternType.PATTERN)
.creator(SplatterBallBrush::new)
Expand All @@ -955,7 +962,7 @@ private void registerSplatterDiscBrush() {
.name("Splatter Disc")
.permission("voxelsniper.brush.splatterdisc")
.alias("sd")
.alias("splatdisc")
.alias("splatterdisc")
.alias("splatter_disc")
.brushPatternType(BrushPatternType.PATTERN)
.creator(SplatterDiscBrush::new)
Expand Down Expand Up @@ -994,7 +1001,7 @@ private void registerSplatterVoxelDiscBrush() {
.name("Splatter Voxel Disc")
.permission("voxelsniper.brush.splattervoxeldisc")
.alias("svd")
.alias("splatvoxeldisc")
.alias("splattervoxeldisc")
.alias("splatter_voxel_disc")
.brushPatternType(BrushPatternType.PATTERN)
.creator(SplatterVoxelDiscBrush::new)
Expand Down
Loading

0 comments on commit 2d85872

Please sign in to comment.