Resource (ACF - BETA) Annotation Command Framework

Discussion in 'Spigot Plugin Development' started by Aikar, Apr 19, 2017.

  1. Code (Java):
        @Subcommand("kick|gkick")
        @CommandAlias("gkick")
        @Syntax("<player> &e- Kick Player from the group.")
    Seems a bit much, you could just shorten it to one class than to have all these different annotations for specific things. With WorldEdit's system, it's easy to write it out, something like:
    Code (Java):
    @Command(aliases= {"kick" ,"gkick"}, info = "A command to kick a player", syntax = "kick <player>", permissions = {"plugin.kick"})
     
    Cool concept nonetheless though
     
    • Like Like x 1
  2. I find the value() style cleaner to read and keeps the annotation purposeful and consistent.
    Some of the annotations are usable on both subcommands and root commands.

    That is much harder to do if you shove everything into 1. Subcommand and Command would have to duplicate properties.
     
    • Agree Agree x 1
  3. https://github.com/aikar/commands/tree/modular

    Major work to abstract the core and move to being able to support bungee, sponge and others (nukkit etc)!
    Still wIP, but this will be an API break so as 0.5.0, but i'm trying to keep changes minimal.

    Namely, if you use Bukkit specific ACFUtil methods, they are moving to an ACFBukkitUtil
    And ACF.create is now going to be manager = BukkitCommandManager.create(plugin);
     
    • Like Like x 2
  4. A bug was fixed yesterday with using Replacements on the root CommandAlias, so highly recommended to get that!


    An interesting note about that setup - with replacements on the root command alias, you can actually let your users configure what every one of your commands will be!

    Code (Java):
    replacements.addReplacement("cmd.mycommand1",
        plugin.getConfig().getString("commands.mycommand1.command"));
    Code (YAML):

    commands
    :
      mycommand1
    :
         command
    : foo
     
    Then
    Code (Java):

    @CommandAlias("%cmd.mycommand1")
    public void MyCommand1 extends BaseCommand { }
     
    This will be /foo for the command.
     
    • Like Like x 1
    • Winner Winner x 1
  5. Having a bit of trouble with the maven revocations. When I try to enable my plugin I get
    Code (Text):
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: net/ultimatemc/crisis/BaseCommand
    Here is my pom.xml:
    Code (Text):
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>Crisis</groupId>
        <artifactId>Crisis</artifactId>
        <version>1.0.0</version>
        <name>Crisis</name>
        <description>Main plugin for Crisis on UltimateMC</description>

        <repositories>
            <repository>
                <id>zDevelopers</id>
                <url>http://maven.carrade.eu/artifactory/snapshots</url>
            </repository>
            <repository>
                <id>vault-repo</id>
                <url>http://nexus.hc.to/content/repositories/pub_releases</url>
            </repository>
            <repository>
                <id>aikar</id>
                <url>https://ci.emc.gs/nexus/content/groups/aikar/</url>
            </repository>
        </repositories>

        <dependencies>
            <!--Spigot API-->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.11.2-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <!--CraftBukkit-->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>craftbukkit</artifactId>
                <version>1.11.2</version>
                <scope>provided</scope>
            </dependency>
            <!--UltimateGuns-->
            <dependency>
                <groupId>net.crisismc</groupId>
                <artifactId>ultimateguns</artifactId>
                <version>1.0.0</version>
                <scope>provided</scope>
            </dependency>
            <!--ProtocolLib-->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>protocollib</artifactId>
                <version>1.0.0</version>
                <scope>provided</scope>
            </dependency>
            <!--Worldedit-->
            <dependency>
                <groupId>com.sk89q</groupId>
                <artifactId>worldedit</artifactId>
                <version>1.0.0</version>
                <scope>provided</scope>
            </dependency>
            <!--API for SQL-->
            <dependency>
                <groupId>com.zaxxer</groupId>
                <artifactId>HikariCP</artifactId>
                <version>2.4.7</version>
                <scope>compile</scope>
            </dependency>
            <!--  Gson: Java to Json conversion -->
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.jetbrains</groupId>
                <artifactId>annotations</artifactId>
                <version>RELEASE</version>
            </dependency>
            <!-- Mockito -->
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-module-junit4</artifactId>
                <version>RELEASE</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-api-mockito</artifactId>
                <version>RELEASE</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>
            <!-- zLib -->
            <dependency>
                <groupId>fr.zcraft</groupId>
                <artifactId>zlib</artifactId>
                <version>0.99-SNAPSHOT</version>
            </dependency>
            <!-- PlaceholderAPI -->
            <dependency>
                <groupId>be.maximvdw</groupId>
                <artifactId>placeholderapi</artifactId>
                <version>LATEST</version>
                <scope>provided</scope>
            </dependency>
            <!-- Vault -->
            <dependency>
                <groupId>net.milkbowl.vault</groupId>
                <artifactId>VaultAPI</artifactId>
                <version>1.6</version>
                <scope>provided</scope>
            </dependency>
            <!-- Annotation Command Framework -->
            <dependency>
                <groupId>co.aikar</groupId>
                <artifactId>acf-core</artifactId>
                <version>0.4.0-SNAPSHOT</version>
            </dependency>
        </dependencies>

        <build>
            <sourceDirectory>src/main/java</sourceDirectory>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.4.3</version>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>fr.zcraft.zlib.*</include>
                                <include>co.aikar.commands.*</include>
                            </includes>
                        </artifactSet>
                        <relocations>
                            <relocation>
                                <pattern>fr.zcraft.zlib</pattern>
                                <shadedPattern>net.ultimatemc.crisis</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>co.aikar.commands</pattern>
                                <shadedPattern>net.ultimatemc.crisis.acf</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <targetPath>.</targetPath>
                    <filtering>true</filtering>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>*.yml</include>
                    </includes>
                </resource>
            </resources>
        </build>
    </project>

    Also, follow up question for when I get this working: How can I setup a command like /balance [player] where not providing the player argument displays your own balance, and providing the player argument displays another player's balance and requires a special permission?
     
  6. electronicboy

    IRC Staff

    looks like it's not actually bundling ACF into the jar, what is your maven log output?
     
  7. I don't know if that artifactSet inclusion is related. That might be the problem. Try removing it.

    Also, that class its looking for is weird. That's not an ACF path nor is it the path that you relocated ACF to....

    Also, You do appear to be missing the -parameters section on the maven compiler plugin, its on the Maven Setup wiki page, but thats not the source of the reported issue.

    Code (Java):
    public void onBalance(Player player, @Optional OnlinePlayer playerToCheck) {}
    Then if playerToCheck == null, do self, else do playerToCheck.getPlayer()

    If you want to support offline players, simply use a string instead, just mark it optional
     
  8. Code (Text):
    [INFO] Scanning for projects...
    [INFO]                                                                        
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Crisis 1.0.0
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Crisis ---
    [INFO] Deleting C:\Users\ukssp\IdeaProjects\Crisis\target
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Crisis ---
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 2 resources to .
    [INFO]
    [INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ Crisis ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
    [INFO] Compiling 92 source files to C:\Users\ukssp\IdeaProjects\Crisis\target\classes
    [INFO] /C:/Users/ukssp/IdeaProjects/Crisis/src/main/java/net/ultimatemc/crisis/Crisis.java: Some input files use or override a deprecated API.
    [INFO] /C:/Users/ukssp/IdeaProjects/Crisis/src/main/java/net/ultimatemc/crisis/Crisis.java: Recompile with -Xlint:deprecation for details.
    [INFO] /C:/Users/ukssp/IdeaProjects/Crisis/src/main/java/net/ultimatemc/crisis/database/BaseLoader.java: Some input files use unchecked or unsafe operations.
    [INFO] /C:/Users/ukssp/IdeaProjects/Crisis/src/main/java/net/ultimatemc/crisis/database/BaseLoader.java: Recompile with -Xlint:unchecked for details.
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Crisis ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory C:\Users\ukssp\IdeaProjects\Crisis\src\test\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ Crisis ---
    [INFO] No sources to compile
    [INFO]
    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Crisis ---
    [INFO] No tests to run.
    [INFO]
    [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ Crisis ---
    [INFO] Building jar: C:\Users\ukssp\IdeaProjects\Crisis\target\Crisis-1.0.0.jar
    [INFO]
    [INFO] --- maven-shade-plugin:2.4.3:shade (default) @ Crisis ---
    [INFO] Excluding commons-lang:commons-lang:jar:2.6 from the shaded jar.
    [INFO] Excluding com.googlecode.json-simple:json-simple:jar:1.1.1 from the shaded jar.
    [INFO] Excluding com.google.guava:guava:jar:17.0 from the shaded jar.
    [INFO] Excluding org.avaje:ebean:jar:2.8.1 from the shaded jar.
    [INFO] Excluding javax.persistence:persistence-api:jar:1.0 from the shaded jar.
    [INFO] Excluding org.yaml:snakeyaml:jar:1.17 from the shaded jar.
    [INFO] Excluding com.zaxxer:HikariCP:jar:2.4.7 from the shaded jar.
    [INFO] Excluding org.slf4j:slf4j-api:jar:1.7.21 from the shaded jar.
    [INFO] Excluding org.jetbrains:annotations:jar:15.0 from the shaded jar.
    [INFO] Excluding junit:junit:jar:4.12 from the shaded jar.
    [INFO] Including fr.zcraft:zlib:jar:0.99-SNAPSHOT in the shaded jar.
    [INFO] Excluding org.bukkit:bukkit:jar:1.8.3-R0.1-SNAPSHOT from the shaded jar.
    [INFO] Excluding co.aikar:acf-core:jar:0.4.0-SNAPSHOT from the shaded jar.
    [INFO] Excluding co.aikar:minecraft-timings:jar:1.0.3 from the shaded jar.
    [INFO] Replacing original artifact with shaded artifact.
    [INFO] Replacing C:\Users\ukssp\IdeaProjects\Crisis\target\Crisis-1.0.0.jar with C:\Users\ukssp\IdeaProjects\Crisis\target\Crisis-1.0.0-shaded.jar
    [INFO] Dependency-reduced POM written at: C:\Users\ukssp\IdeaProjects\Crisis\dependency-reduced-pom.xml
    [INFO] Dependency-reduced POM written at: C:\Users\ukssp\IdeaProjects\Crisis\dependency-reduced-pom.xml
    [INFO]
    [INFO] --- maven-install-plugin:2.4:install (default-install) @ Crisis ---
    [INFO] Installing C:\Users\ukssp\IdeaProjects\Crisis\target\Crisis-1.0.0.jar to C:\Users\ukssp\.m2\repository\Crisis\Crisis\1.0.0\Crisis-1.0.0.jar
    [INFO] Installing C:\Users\ukssp\IdeaProjects\Crisis\dependency-reduced-pom.xml to C:\Users\ukssp\.m2\repository\Crisis\Crisis\1.0.0\Crisis-1.0.0.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.248 s
    [INFO] Finished at: 2017-05-21T12:21:29-04:00
    [INFO] Final Memory: 24M/320M
    [INFO] ------------------------------------------------------------------------
    The relocation for zLib is working which is the confusing thing.

    I removed the inclusion, same issue. The path from the error is actually net/ultimatemc/crisis/acf/BaseCommand, I posted an old error on mistake.

    For the command is there a way I can specify that using that optional player argument requires a specific permission? Or do I just have to check for the permission in the standard Spigot way?
     
  9. electronicboy

    IRC Staff

    Code (Text):

    [INFO] Excluding co.aikar:acf-core:jar:0.4.0-SNAPSHOT from the shaded jar.
    [INFO] Excluding co.aikar:minecraft-timings:jar:1.0.3 from the shaded jar.
     
    your artifact filtering is excluding those essential components
     
  10. That it is. Changing my artifact set to look like the following solved my issue.
    Code (Text):
                        <artifactSet>
                            <includes>
                                <include>fr.zcraft:zlib</include>
                                <include>co.aikar:acf-core</include>
                                <include>co.aikar:minecraft-timings</include>
                            </includes>
                        </artifactSet>
    Thanks for your help! It is strange that I needed to add those to my "includes" when it seems like others didn't need to.
     
  11. Can i change the default usage message?
     
  12. electronicboy

    IRC Staff

    you can use the @SyntaX annotation to change the usage message
     
  13. Oh, totally missed that one, thank you! :)
     
  14. How does the replacement works?
    This do not work for me.
     
  15. Not very helpful. Provide code, errors/stack-traces/what you've tried and we can get a better idea of what's wrong.
    http://xyproblem.info/
     
  16. electronicboy

    IRC Staff

    if you're using maven, run mvn -U <maven goal> to refresh your dependencies, you probably have an older version in your maven local
     
  17. I have refreshed my local repo but i still don't have the method. I'm currently using version 0.5.0-SNAPSHOT, is that the right one?

    EDIT: Just say on the GitHub page that the correct version is 0.4.0-SNAPSHOT so the problem is solved.
     
  18. The current version is 0.4.0, 0.5.0 existing is just a fluke from weeks ago so its really out of date and is about to be overridden soon with a breaking API change.

    Where did you get 0.5.0 from? All the post and GitHub lists 0.4.0
     
  19. Just here:
    http://ci.emc.gs/nexus/content/groups/aikar/co/aikar/acf-core/
     

Share This Page