feat(annotations): add command containers (#364)
This is the first part of the introduction of annotation processing to cloud. A new `@CommandContainer` annotation has been introduced, which can be placed on classes to have the annotation parser automatically construct & parse the classes when `AnnotationParser.parseContainers()` is invoked. A future PR will introduce another processor that will scan for `@CommandMethod` annotations and verify the integrity of the annotated methods (visibility, argument annotations, etc.).
This commit is contained in:
parent
d613fd0208
commit
f1582fb64e
15 changed files with 543 additions and 2 deletions
|
|
@ -18,6 +18,8 @@ dependencies {
|
|||
implementation(libs.adventurePlatformBukkit)
|
||||
/* Bukkit */
|
||||
compileOnly(libs.bukkit)
|
||||
/* Annotation processing */
|
||||
annotationProcessor(project(":cloud-annotations"))
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2021 Alexander Söderberg & Contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package cloud.commandframework.examples.bukkit;
|
||||
|
||||
import cloud.commandframework.annotations.AnnotationParser;
|
||||
import cloud.commandframework.annotations.CommandMethod;
|
||||
import cloud.commandframework.annotations.processing.CommandContainer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@CommandContainer
|
||||
public final class ExampleCommandContainer {
|
||||
|
||||
/**
|
||||
* The constructor. {@link AnnotationParser} is an optional parameter.
|
||||
*
|
||||
* @param parser the parser
|
||||
*/
|
||||
public ExampleCommandContainer(final @NonNull AnnotationParser<CommandSender> parser) {
|
||||
// Woo...
|
||||
}
|
||||
|
||||
/**
|
||||
* This one gets parsed automatically!
|
||||
*
|
||||
* @param sender the sender
|
||||
*/
|
||||
@CommandMethod("container")
|
||||
public void containerCommand(final CommandSender sender) {
|
||||
sender.sendMessage("This is sent from a container!!");
|
||||
}
|
||||
}
|
||||
|
|
@ -235,6 +235,12 @@ public final class ExamplePlugin extends JavaPlugin {
|
|||
// Parse all @CommandMethod-annotated methods
|
||||
//
|
||||
this.annotationParser.parse(this);
|
||||
// Parse all @CommandContainer-annotated classes
|
||||
try {
|
||||
this.annotationParser.parseContainers();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//
|
||||
// Base command builder
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue