Search in sources :

Example 1 with RegisterCommandInterceptors

use of io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommandInterceptors in project Nucleus by NucleusPowered.

the class StandardModule method registerCommandInterceptors.

private void registerCommandInterceptors() throws Exception {
    RegisterCommandInterceptors annotation = getClass().getAnnotation(RegisterCommandInterceptors.class);
    if (annotation != null) {
        // for each annotation, attempt to register the service.
        for (Class<? extends ICommandInterceptor> service : annotation.value()) {
            // create the impl
            ICommandInterceptor impl;
            try {
                impl = service.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                String error = "ERROR: Cannot instantiate ICommandInterceptor " + service.getName();
                Nucleus.getNucleus().getLogger().error(error);
                throw new IllegalStateException(error, e);
            }
            if (impl instanceof Reloadable) {
                Reloadable reloadable = (Reloadable) impl;
                Nucleus.getNucleus().registerReloadable(reloadable);
                reloadable.onReload();
            }
            AbstractCommand.registerInterceptor(impl);
        }
    }
}
Also used : RegisterCommandInterceptors(io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommandInterceptors) ICommandInterceptor(io.github.nucleuspowered.nucleus.internal.command.ICommandInterceptor) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)

Aggregations

RegisterCommandInterceptors (io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommandInterceptors)1 ICommandInterceptor (io.github.nucleuspowered.nucleus.internal.command.ICommandInterceptor)1 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)1