CommandAPI icon indicating copy to clipboard operation
CommandAPI copied to clipboard

Inner classes can't be used with the annotation system

Open JorelAli opened this issue 4 years ago • 0 comments

CommandAPI version 5.11

Minecraft version 1.16.5

Describe the bug Given a class that actually is inner class:

@Command("weather")
@Permission("assentials.command.weather")
public class WeatherCommand {
    
    @Command("sun")
    @Permission("assentials.command.weather")
    public static class SunShortcut {
        @Default
        public static void run(CommandSender sender) {
            WeatherCommand.doSomething(sender, "clear");
        }
    }
    
      @Default
    public static void doSomething(CommandSender sender, @AMultiLiteralArgument({"clear"}) String literal) {
        // code
    }
}

Registering with the following fails

CommandAPI.registerCommand(WeatherCommand.SunShortcut.class);

You get this:

Task :compileJava
class WeatherCommand clashes with package of same name
public class WeatherCommand {
       ^
SunShortcut$Command.java:1: error: package com.lasttray.plugin.assentials.command.WeatherCommand clashes with class of same name
package com.lasttray.plugin.assentials.command.WeatherCommand;

Using Maven you get a similar issue:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project CommandAPITest: Compilation failure
[ERROR] /D:/eclipseworkspaces/1.13commandapi/commandapi-test-200/target/generated-sources/annotations/WeatherCommand/SunShortcut$Command.java:[14,17] cannot find symbol
[ERROR]   symbol:   variable SunShortcut
[ERROR]   location: class WeatherCommand.SunShortcut$Command
[ERROR] -> [Help 1]

The generated result is mangled:

├── generated-sources
└── annotations
    ├── WeatherCommand
    │   └── SunShortcut$Command.java
    └── WeatherCommand$Command.java

WeatherCommand$Command.java

import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.arguments.MultiLiteralArgument;

// This class was automatically generated by the CommandAPI
public class WeatherCommand$Command {

    @SuppressWarnings("unchecked")
    public static void register() {

        new CommandAPICommand("weather")
            .withPermission("assentials.command.weather")
            .withArguments(new MultiLiteralArgument("clear"))
            .executes((sender, args) -> {
                WeatherCommand.doSomething(sender, (String) args[0]);
            })
            .register();

        }

}

SunShortcut$Command.java

package WeatherCommand;

import dev.jorel.commandapi.CommandAPICommand;

// This class was automatically generated by the CommandAPI
public class SunShortcut$Command {

    @SuppressWarnings("unchecked")
    public static void register() {

        new CommandAPICommand("sun")
            .withPermission("assentials.command.weather")
            .executes((sender, args) -> {
                SunShortcut.run(sender);
            })
            .register();

        }

}

JorelAli avatar May 10 '21 12:05 JorelAli