com.github.jeuxjeux20.guicybukkit.command.CommandName Maven / Gradle / Ivy
package com.github.jeuxjeux20.guicybukkit.command;
import java.lang.annotation.*;
/**
* Defines the name of a command that a type represents.
* @see AnnotatedCommandConfigurator
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface CommandName {
/**
* Gets the name of the command.
*
* @return the name of the command
*/
String value();
/**
* Contains helpful methods for {@link CommandName}.
*/
final class Helper {
/**
* A constructor that you won't ever be able to use except with some dirty reflection.
*
* If you one day accomplish the incredible act of creating an instance of {@link Helper},
* your local grocery store will give you free cookies. Except if you're in
* lockdown.
*/
protected Helper() {
}
/**
* Gets the {@link CommandName} {@linkplain CommandName#value() value} of the specified class.
*
* If there is no {@link CommandName} annotation, a {@link UnsupportedOperationException} will be thrown.
* @throws UnsupportedOperationException when no {@link CommandName} annotation on the class has been found.
* @param clazz the class annotated with {@link CommandName} or not
* @return the command name
*/
public static String getCommandNameOrThrow(Class> clazz) {
CommandName annotation = clazz.getAnnotation(CommandName.class);
if (annotation == null)
throw new UnsupportedOperationException("No @CommandName annotation found on class " + clazz.getName() + ".");
return annotation.value();
}
}
}