Effective removal of annotated commands.

keep-around/6d4ac31d79b8d01b9303a187e765abb5ff83af9f
Pingex aka Raphaël 9 years ago
parent 38188d941d
commit b505e79d2a

@ -1,47 +0,0 @@
package net.pingex.dcf.commands;
import net.pingex.dcf.permissions.DefaultPermission;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicated a method which is in fact a command
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Deprecated
public @interface AnnotatedCommand
{
/**
* Main name of the command
*/
String name();
/**
* Command can also be called using the following list of aliases
*/
String[] aliases() default {};
/**
* Description of the command.
*/
String description() default Command.Defaults.DESCRIPTION;
/**
* Is the command enabled ? Can it be invoked ?
*/
boolean isEnabled() default Command.Defaults.IS_ENABLED;
/**
* Command usage help
*/
String usage() default Command.Defaults.USAGE;
/**
* Default permission, ie. when the permissions provider doesn't return anything.
*/
@Deprecated
DefaultPermission defaultPermission() default DefaultPermission.EVERYONE;
}

@ -222,23 +222,6 @@ public abstract class Command implements ICommandExecutor
return new Builder(name); return new Builder(name);
} }
/**
* Create a new command object from an annotated method
* @param target Target method
* @return A new created command built from the method, or `null` if the method is not a valid command.
*/
@Deprecated
public static Command buildFromAnnotatedCommand(AnnotatedCommand meta, Method target, Object invokable)
{
return builder(meta.name())
.aliases(Arrays.asList(meta.aliases()))
.description(meta.description())
.enabled(meta.isEnabled())
.usage(meta.usage())
.defaultPermission(meta.defaultPermission())
.build(target, invokable);
}
public String getName() public String getName()
{ {
return name; return name;

@ -103,26 +103,11 @@ public class CommandHandler
*/ */
public static void registerPlugin(PluginWrapper pluginWrapper) public static void registerPlugin(PluginWrapper pluginWrapper)
{ {
LOGGER.debug("Registering commands for plugin {}.", pluginWrapper.getId());
// Raw commands
if(IWithCommands.class.isAssignableFrom(pluginWrapper.getInstance().getClass())) if(IWithCommands.class.isAssignableFrom(pluginWrapper.getInstance().getClass()))
{ {
LOGGER.debug("Plugin has commands (raw commands)."); LOGGER.debug("Registering commands for plugin {}.", pluginWrapper.getId());
((IWithCommands) pluginWrapper.getInstance()).getCommands().forEach(CommandRegistry::registerCommand); ((IWithCommands) pluginWrapper.getInstance()).getCommands().forEach(CommandRegistry::registerCommand);
} }
// Annotated commands
if(IWithAnnotatedCommands.class.isAssignableFrom(pluginWrapper.getInstance().getClass()))
{
LOGGER.debug("Plugin has commands (annotated commands).");
((IWithAnnotatedCommands) pluginWrapper.getInstance()).getAnnotatedObjects().forEach(e ->
{
for(Method i : e.getClass().getMethods())
if(i.isAnnotationPresent(AnnotatedCommand.class))
CommandRegistry.registerCommand(Command.buildFromAnnotatedCommand(i.getAnnotation(AnnotatedCommand.class), i, e));
});
}
} }
/** /**
@ -131,25 +116,10 @@ public class CommandHandler
*/ */
public static void unregisterPlugin(PluginWrapper pluginWrapper) public static void unregisterPlugin(PluginWrapper pluginWrapper)
{ {
LOGGER.debug("Removing commands for plugin {}.", pluginWrapper.getId());
// Raw commands
if(IWithCommands.class.isAssignableFrom(pluginWrapper.getInstance().getClass())) if(IWithCommands.class.isAssignableFrom(pluginWrapper.getInstance().getClass()))
{ {
LOGGER.debug("Plugin has commands (raw commands)."); LOGGER.debug("Removing commands for plugin {}.", pluginWrapper.getId());
((IWithCommands) pluginWrapper.getInstance()).getCommands().forEach(CommandRegistry::unregisterCommand); ((IWithCommands) pluginWrapper.getInstance()).getCommands().forEach(CommandRegistry::unregisterCommand);
} }
// Annotated commands
if(IWithAnnotatedCommands.class.isAssignableFrom(pluginWrapper.getInstance().getClass()))
{
LOGGER.debug("Plugin has commands (annotated commands).");
((IWithAnnotatedCommands) pluginWrapper.getInstance()).getAnnotatedObjects().forEach(e ->
{
for(Method i : e.getClass().getMethods())
if(i.isAnnotationPresent(AnnotatedCommand.class))
CommandRegistry.unregisterCommandByName(i.getAnnotation(AnnotatedCommand.class).name());
});
}
} }
} }

@ -1,17 +0,0 @@
package net.pingex.dcf.commands;
import java.util.Set;
/**
* Indicates a plugin which can run commands (using annotated commands)
*/
@FunctionalInterface
@Deprecated
public interface IWithAnnotatedCommands
{
/**
* Gives all annotated commands for this plugin.
* @return A set of objects which contains annotated commands.
*/
Set<Object> getAnnotatedObjects();
}