/*
 * Feature.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.features;

import com.publicuhc.ultrahardcore.features.events.FeatureDisableEvent;
import com.publicuhc.ultrahardcore.features.events.FeatureEnableEvent;
import com.publicuhc.ultrahardcore.features.events.FeatureEvent;
import com.publicuhc.pluginframework.configuration.Configurator;
import com.publicuhc.pluginframework.shaded.inject.Inject;
import com.publicuhc.pluginframework.translate.Translate;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;

import java.util.List;

public abstract class Feature implements IFeature {

    /**
     * Is the feautre enabeld right now?
     */
    private boolean m_enabled;

    private final Configurator m_configManager;
    private final Plugin m_plugin;
    private final Translate m_translate;

    @Override
    public final boolean enableFeature(){
        if(isEnabled()){
            return false;
        }
        FeatureEvent event = new FeatureEnableEvent(this);
        Bukkit.getPluginManager().callEvent(event);
        if(!event.isCancelled()){
            m_enabled = true;
            enableCallback();
        }
        return true;
    }

    @Override
    public final boolean disableFeature(){
        if(!isEnabled()){
            return false;
        }
        FeatureDisableEvent event = new FeatureDisableEvent(this);
        Bukkit.getPluginManager().callEvent(event);
        if(!event.isCancelled()){
            m_enabled = false;
            disableCallback();
        }
        return true;
    }

    /**
     * Called when the feature is being enabled
     */
    protected void enableCallback(){}

    /**
     * Called when the feature is being disabled
     */
    protected void disableCallback(){}

    @Override
    public boolean isEnabled() {
        return m_enabled;
    }

    /**
     * Construct a new feature
     * @param plugin the plugin
     * @param configManager the config manager to use
     * @param translate the translator
     */
    @Inject
    protected Feature(Plugin plugin, Configurator configManager, Translate translate) {
        m_configManager = configManager;
        m_plugin = plugin;
        m_translate = translate;
    }

    /**
     * Are the features the same feature? Returns true if they have the same ID
     * @param obj Object
     * @return boolean
     */
    @Override
    public boolean equals(Object obj) {
        return obj instanceof IFeature && ((IFeature) obj).getFeatureID().equals(getFeatureID());
    }

    /**
     * @return the config manager for the feature
     */
    protected Configurator getConfigManager(){
        return m_configManager;
    }

    /**
     * @return the plugin for the feature
     */
    protected Plugin getPlugin(){
        return m_plugin;
    }

    /**
     * Return the hashcode of this feature
     * @return int
     */
    @Override
    public int hashCode(){
        return new HashCodeBuilder(17, 31).append(getFeatureID()).toHashCode();
    }

    /**
     * @return the translator
     */
    protected Translate getTranslate() {
        return m_translate;
    }

    @Override
    public List<String> getStatus() {
        return null;
    }

    /**
     * @param onOff the boolean
     * @return green 'ON' if true, red 'OFF' if false
     */
    protected String convertBooleanToOnOff(boolean onOff) {
        return onOff ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
    }
}

@@ -1043,190 +1043,8 @@
 nt;%0A
-import com.publicuhc.pluginframework.configuration.Configurator;%0Aimport com.publicuhc.pluginframework.shaded.inject.Inject;%0Aimport com.publicuhc.pluginframework.translate.Translate;%0A
 impo
@@ -1153,41 +1153,8 @@
 lor;
-%0Aimport org.bukkit.plugin.Plugin;
 %0A%0Aim
@@ -1321,133 +1321,8 @@
 d;%0A%0A
-    private final Configurator m_configManager;%0A    private final Plugin m_plugin;%0A    private final Translate m_translate;%0A%0A
     
@@ -2341,388 +2341,8 @@
  %7D%0A%0A
-    /**%0A     * Construct a new feature%0A     * @param plugin the plugin%0A     * @param configManager the config manager to use%0A     * @param translate the translator%0A     */%0A    @Inject%0A    protected Feature(Plugin plugin, Configurator configManager, Translate translate) %7B%0A        m_configManager = configManager;%0A        m_plugin = plugin;%0A        m_translate = translate;%0A    %7D%0A%0A
     
@@ -2644,284 +2644,8 @@
  %7D%0A%0A
-    /**%0A     * @return the config manager for the feature%0A     */%0A    protected Configurator getConfigManager()%7B%0A        return m_configManager;%0A    %7D%0A%0A    /**%0A     * @return the plugin for the feature%0A     */%0A    protected Plugin getPlugin()%7B%0A        return m_plugin;%0A    %7D%0A%0A
     
@@ -2850,130 +2850,8 @@
  %7D%0A%0A
-    /**%0A     * @return the translator%0A     */%0A    protected Translate getTranslate() %7B%0A        return m_translate;%0A    %7D%0A%0A
     

remove requirement for configurator e.t.c.