/*
 * UltraHardcore.java
 *
 * Copyright (c) 2014 Graham Howden <graham_howden1 at yahoo.co.uk>.
 *
 * This file is part of UltraHardcore.
 *
 * UltraHardcore is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * UltraHardcore is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with UltraHardcore.  If not, see <http ://www.gnu.org/licenses/>.
 */
package com.publicuhc.ultrahardcore;

import com.publicuhc.pluginframework.FrameworkJavaPlugin;
import com.publicuhc.pluginframework.routing.Router;
import com.publicuhc.pluginframework.shaded.inject.AbstractModule;
import com.publicuhc.pluginframework.shaded.inject.Inject;
import com.publicuhc.pluginframework.shaded.inject.Singleton;
import com.publicuhc.pluginframework.shaded.metrics.Metrics;
import com.publicuhc.ultrahardcore.api.Feature;
import com.publicuhc.ultrahardcore.api.FeatureManager;

import java.util.ArrayList;
import java.util.List;

/**
 * UltraHardcore
 * <p/>
 * Main plugin class, init
 *
 * @author ghowden
 */
@Singleton
public class UltraHardcore extends FrameworkJavaPlugin {

    private FeatureManager featureManager;

    //When the plugin gets started
    @Override
    protected void onFrameworkEnable()
    {
        //enable metrics
        Metrics metrics = getMetrics();
        Metrics.Graph graph = metrics.createGraph("Features Loaded");
        for(final Feature feature : featureManager.getFeatures()){
            graph.addPlotter(new Metrics.Plotter(feature.getFeatureID()) {
                @Override
                public int getValue() {
                    return feature.isEnabled() ? 1 : 0;
                }
            });
        }
        metrics.addGraph(graph);
        metrics.start();
    }

    @Inject
    private void setFeatureManager(FeatureManager featureManager)
    {
        this.featureManager = featureManager;
    }

    /**
     * @return the feature manager for handling features
     */
    public FeatureManager getFeatureManager()
    {
        return featureManager;
    }

    /**
     * @return the plugin router, used for registering commands e.t.c.
     */
    public Router getCommandRouter()
    {
        return getRouter();
    }

    @Override
    protected List<AbstractModule> initialModules()
    {
        List<AbstractModule> customModules = new ArrayList<AbstractModule>();
        customModules.add(new UHCModule());
        return customModules;
    }
}
@@ -979,95 +979,47 @@
 ork.
-shaded.inject.AbstractModule;%0Aimport com.publicuhc.pluginframework.shaded.inject.Inject
+routing.exception.CommandParseException
 ;%0Aim
@@ -1067,25 +1067,17 @@
 .inject.
-Singleton
+*
 ;%0Aimport
@@ -1131,16 +1131,64 @@
 etrics;%0A
+import com.publicuhc.ultrahardcore.api.Command;%0A
 import c
@@ -1281,16 +1281,145 @@
 Manager;
+%0Aimport com.publicuhc.ultrahardcore.api.UHCFeature;%0Aimport com.publicuhc.ultrahardcore.api.exceptions.FeatureIDConflictException;
 %0A%0Aimport
@@ -1462,16 +1462,38 @@
 il.List;
+%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -1679,16 +1679,51 @@
 Manager;
+%0A    private Injector mainInjector;
 %0A%0A    //
@@ -2314,24 +2314,139 @@
 t();%0A    %7D%0A%0A
+    @Inject%0A    private void setMainInjector(Injector injector)%0A    %7B%0A        this.mainInjector = injector;%0A    %7D%0A%0A
     @Inject%0A
@@ -3092,16 +3092,16 @@
 ule());%0A
-
         
@@ -3127,10 +3127,984 @@
 s;%0A    %7D
+%0A%0A    /**%0A     * Register an addon module for features/commands%0A     *%0A     * @param module the module with the bindings within it%0A     *%0A     * @throws FeatureIDConflictException%0A     * @throws CommandParseException%0A     */%0A    @SuppressWarnings(%7B%22AnonymousInnerClass%22, %22EmptyClass%22%7D)%0A    public void registerAddon(AbstractModule module) throws FeatureIDConflictException, CommandParseException %7B%0A        //fetch the list of UHCFeatures from the module and add them to the manager%0A        Injector injector = mainInjector.createChildInjector(module);%0A%0A        Set%3CUHCFeature%3E features = injector.getInstance(Key.get(new TypeLiteral%3CSet%3CUHCFeature%3E%3E()%7B%7D));%0A        for(UHCFeature feature : features) %7B%0A            featureManager.addFeature(feature);%0A        %7D%0A%0A        Set%3CCommand%3E commands = injector.getInstance(Key.get(new TypeLiteral%3CSet%3CCommand%3E%3E()%7B%7D));%0A        for(Command command : commands) %7B%0A            getRouter().registerCommands(command, false);%0A        %7D%0A    %7D
 %0A%7D

add a method for registering an addon module