summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorSenmori <thesenmori@gmail.com>2018-10-13 11:56:40 +1100
committermd_5 <git@md-5.net>2018-10-13 11:56:46 +1100
commita827d5fe07a140221df0048673665337bbb93db4 (patch)
tree953b02c0196904198ae96536c335b021d11e8a78 /src/main
parent394166672c048dd170fc43a9953912ae59d0d654 (diff)
downloadplugin-annotations-a827d5fe07a140221df0048673665337bbb93db4.tar
plugin-annotations-a827d5fe07a140221df0048673665337bbb93db4.tar.gz
plugin-annotations-a827d5fe07a140221df0048673665337bbb93db4.tar.lz
plugin-annotations-a827d5fe07a140221df0048673665337bbb93db4.tar.xz
plugin-annotations-a827d5fe07a140221df0048673665337bbb93db4.zip
PLUG-305: Fix @Commands not able to be used on Command ExecutorsHEADmaster
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java58
1 files changed, 47 insertions, 11 deletions
diff --git a/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java
index 089e709..59a935d 100644
--- a/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java
+++ b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java
@@ -172,8 +172,8 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
// commands
// Begin processing external command annotations
Map<String, Map<String, Object>> commandMap = Maps.newLinkedHashMap();
- boolean result = processExternalCommands( rEnv.getElementsAnnotatedWith( Command.class ), mainPluginType, commandMap );
- if ( !result ) {
+ boolean validCommandExecutors = processExternalCommands( rEnv.getElementsAnnotatedWith( Commands.class ), mainPluginType, commandMap );
+ if ( !validCommandExecutors ) {
// #processExternalCommand already raised the errors
return false;
}
@@ -213,6 +213,12 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
joined.putAll( this.processPermissions( permissions ) );
permissionMetadata = joined;
}
+
+ // Process Permissions on command executors
+ boolean validPermissions = processExternalPermissions( rEnv.getElementsAnnotatedWith( Permissions.class ), mainPluginType, permissionMetadata );
+ if ( !validPermissions ) {
+ return false;
+ }
yml.put( "permissions", permissionMetadata );
// api-version
@@ -245,15 +251,43 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
return true;
}
+ private boolean processExternalPermissions(Set<? extends Element> commandExecutors, TypeElement mainPluginType, Map<String, Map<String, Object>> yml) {
+ for ( Element element : commandExecutors ) {
+ // Check to see if someone annotated a non-class with this
+ if ( !( element instanceof TypeElement ) ) {
+ this.raiseError( "Specified Command Executor class is not a class." );
+ return false;
+ }
+
+ TypeElement typeElement = ( TypeElement ) element;
+ if ( typeElement.equals( mainPluginType ) ) {
+ continue;
+ }
+
+ // Check to see if annotated class is actuall a command executor
+ TypeMirror mirror = this.processingEnv.getElementUtils().getTypeElement( CommandExecutor.class.getName() ).asType();
+ if ( !( this.processingEnv.getTypeUtils().isAssignable( typeElement.asType(), mirror ) ) ) {
+ this.raiseError( "Specified Command Executor class is not assignable from CommandExecutor " );
+ return false;
+ }
+
+ Map<String, Map<String, Object>> newMap = Maps.newLinkedHashMap();
+ Permissions annotation = typeElement.getAnnotation( Permissions.class );
+ if ( annotation != null && annotation.value().length > 0 ) {
+ newMap.putAll( processPermissions( annotation ) );
+ }
+ yml.putAll( newMap );
+ }
+ return true;
+ }
+
private void checkForNoArgsConstructor(TypeElement mainPluginType) {
- ExecutableElement construct = null;
for ( ExecutableElement constructor : ElementFilter.constructorsIn( mainPluginType.getEnclosedElements() ) ) {
if ( constructor.getParameters().isEmpty() ) {
return;
}
- construct = constructor;
}
- raiseError( "Main plugin class must have a no argument constructor.", construct );
+ raiseError( "Main plugin class must have a no argument constructor.", mainPluginType );
}
private void raiseError(String message) {
@@ -317,8 +351,10 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
return false;
}
- Command annotation = typeElement.getAnnotation( Command.class );
- commandMetadata.put( annotation.name(), this.processCommand( annotation ) );
+ Commands annotation = typeElement.getAnnotation( Commands.class );
+ if ( annotation != null && annotation.value().length > 0 ) {
+ commandMetadata.putAll( this.processCommands( annotation ) );
+ }
}
return true;
}
@@ -354,16 +390,16 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
command.put( "aliases", commandAnnotation.aliases() );
}
- if ( !"".equals( commandAnnotation.desc() ) ) {
+ if ( !commandAnnotation.desc().isEmpty() ) {
command.put( "description", commandAnnotation.desc() );
}
- if ( !"".equals( commandAnnotation.permission() ) ) {
+ if ( !commandAnnotation.permission().isEmpty() ) {
command.put( "permission", commandAnnotation.permission() );
}
- if ( !"".equals( commandAnnotation.permissionMessage() ) ) {
+ if ( !commandAnnotation.permissionMessage().isEmpty() ) {
command.put( "permission-message", commandAnnotation.permissionMessage() );
}
- if ( !"".equals( commandAnnotation.usage() ) ) {
+ if ( !commandAnnotation.usage().isEmpty() ) {
command.put( "usage", commandAnnotation.usage() );
}