/*
 * HardcoreHeartsFeature.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.pluginfeatures.hardcorehearts;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.events.PacketListener;
import com.publicuhc.pluginframework.configuration.Configurator;
import com.publicuhc.pluginframework.shaded.inject.Inject;
import com.publicuhc.pluginframework.shaded.inject.Singleton;
import com.publicuhc.pluginframework.translate.Translate;
import com.publicuhc.ultrahardcore.pluginfeatures.UHCFeature;
import org.bukkit.plugin.Plugin;

@Singleton
public class HardcoreHeartsFeature extends UHCFeature {

    private final ProtocolManager m_manager = ProtocolLibrary.getProtocolManager();
    private final PacketListener m_listner;

    /**
     * Shows hardcore hearts in non hardcore worlds when enabled, requires protcollib
     * @param plugin the plugin
     * @param configManager the config manager
     * @param translate the translator
     */
    @Inject
    private HardcoreHeartsFeature(Plugin plugin, Configurator configManager, Translate translate) {
        super(plugin, configManager, translate);
        m_listner = new HardcoreHeartsListener(plugin);
    }

    @Override
    public void enableCallback(){
        m_manager.addPacketListener(m_listner);
    }

    @Override
    public void disableCallback(){
        m_manager.removePacketListener(m_listner);
    }

    @Override
    public String getFeatureID() {
        return "HardcoreHearts";
    }

    @Override
    public String getDescription() {
        return "Shows the hardcore hearts instead";
    }

    private static class HardcoreHeartsListener extends PacketAdapter {

        /**
         * listens for login packets to edit
         * @param bukkitPlugin the plugin
         */
        HardcoreHeartsListener(Plugin bukkitPlugin){
            //listen for login packets on the normal priority
            super(bukkitPlugin,ListenerPriority.NORMAL,PacketType.Play.Server.LOGIN);
        }

        @Override
        public void onPacketSending(PacketEvent event) {
            //if its a login packet write the first boolean to true (hardcore flag)
            if (event.getPacketType().equals(PacketType.Play.Server.LOGIN)) {
                event.getPacket().getBooleans().write(0, true);
            }
        }
    }
}

@@ -1216,73 +1216,8 @@
 er;%0A
-import com.publicuhc.pluginframework.configuration.Configurator;%0A
 impo
@@ -1337,66 +1337,8 @@
 on;%0A
-import com.publicuhc.pluginframework.translate.Translate;%0A
 impo
@@ -1360,38 +1360,32 @@
 c.ultrahardcore.
-plugin
 features.UHCFeat
@@ -1423,16 +1423,157 @@
 lugin;%0A%0A
+/**%0A * HardcoreHeartsFeature%0A *%0A * Enabled: Shows hardcore hearts on login to the server%0A * Disabled: Nothing%0A *%0A * Requires ProtocolLib%0A */%0A
 @Singlet
@@ -1855,16 +1855,23 @@
 tcollib%0A
+     *%0A
      * @
@@ -1904,256 +1904,72 @@
    *
- @param configManager the config manager%0A     * @param translate the translator%0A     */%0A    @Inject%0A    private HardcoreHeartsFeature(Plugin plugin, Configurator configManager, Translate translate) %7B%0A        super(plugin, configManager, translate);
+/%0A    @Inject%0A    private HardcoreHeartsFeature(Plugin plugin) %7B
 %0A   

update the hardcore hearts feature