/*
 * RegenFeature.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.regen;

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.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.plugin.Plugin;


/**
 * RegenHandler
 * Handles the regeneration of players and cancels if its from being near full hunger
 *
 * @author ghowden
 */
@Singleton
public class RegenFeature extends UHCFeature {

    private static final int FOOD_LEVEL = 18;
    private static final double PLAYER_DEAD_HEALTH = 0.0;
    private static final float EXHAUSTION_OFFSET = 3.0F;

    public static final String NO_HEALTH_REGEN = BASE_PERMISSION+ "disableRegen";

    /**
     * Disables natural regen when enabled, normal when disabled
     * @param plugin the plugin
     * @param configManager the config manager
     * @param translate the translator
     */
    @Inject
    private RegenFeature(Plugin plugin, Configurator configManager, Translate translate) {
        super(plugin, configManager, translate);
    }

    /**
     * Whenever an entity regains health
     * @param erhe the entityregainhealthevent
     */
    @EventHandler
    public void onHealthRegen(EntityRegainHealthEvent erhe) {
        if (isEnabled()) {
            //If its a player regen
            if (erhe.getEntityType() == EntityType.PLAYER) {
                //If the player is in a hardcore world
                //If its just standard health regen
                if (erhe.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
                    Player p = (Player) erhe.getEntity();
                    if (p.hasPermission(NO_HEALTH_REGEN)) {
                        if (p.getFoodLevel() >= FOOD_LEVEL && p.getHealth() > PLAYER_DEAD_HEALTH && p.getHealth() < p.getMaxHealth()) {
                            p.setExhaustion(p.getExhaustion() - EXHAUSTION_OFFSET);
                        }
                        //Cancel the event to stop the regen
                        erhe.setCancelled(true);
                    }
                }
            }
        }
    }

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

    @Override
    public String getDescription() {
        return "Cancels a player's passive health regeneration";
    }
}

@@ -889,213 +889,31 @@
 ork.
-configuration.Configurator;%0Aimport com.publicuhc.pluginframework.shaded.inject.Inject;%0Aimport com.publicuhc.pluginframework.shaded.inject.Singleton;%0Aimport com.publicuhc.pluginframework.translate.Translate
+shaded.inject.Singleton
 ;%0Aim
@@ -937,38 +937,32 @@
 c.ultrahardcore.
-plugin
 features.UHCFeat
@@ -1134,170 +1134,99 @@
 nt;%0A
-import org.bukkit.plugin.Plugin;%0A%0A%0A/**%0A * RegenHandler%0A * Hand
+%0A%0A/**%0A * RegenFeature%0A *%0A * Enabled: Disab
 les 
-t
 he
+alth
  regen
-eration of players and cancels if its from being near full hunger%0A *%0A * @author ghowden
+ for players%0A * Disabled: Nothing
 %0A */
@@ -1500,26 +1500,13 @@
 N = 
-BASE_PERMISSION+ %22
+%22UHC.
 disa
@@ -1521,470 +1521,8 @@
 %22;%0A%0A
-    /**%0A     * Disables natural regen when enabled, normal when disabled%0A     * @param plugin the plugin%0A     * @param configManager the config manager%0A     * @param translate the translator%0A     */%0A    @Inject%0A    private RegenFeature(Plugin plugin, Configurator configManager, Translate translate) %7B%0A        super(plugin, configManager, translate);%0A    %7D%0A%0A    /**%0A     * Whenever an entity regains health%0A     * @param erhe the entityregainhealthevent%0A     */%0A
     
@@ -1609,16 +1609,17 @@
     if (
+!
 isEnable
@@ -1622,23 +1622,38 @@
 abled())
- %7B
 %0A    
+        return;%0A%0A
         
@@ -1676,36 +1676,32 @@
 r regen%0A        
-   
- 
 if (erhe.getEnti
@@ -1709,17 +1709,17 @@
 yType() 
-=
+!
 = Entity
@@ -1730,21 +1730,17 @@
 .PLAYER)
- %7B%0A  
+%0A
         
@@ -1747,58 +1747,26 @@
     
-  //If the player is in a hardcore world%0A 
+return;%0A%0A%0A
         
     
@@ -1761,23 +1761,16 @@
         
-       
 //If its
@@ -1801,32 +1801,24 @@
 gen%0A        
-      
-  
 if (erhe.get
@@ -1832,17 +1832,17 @@
 eason() 
-=
+!
 = Entity
@@ -1881,18 +1881,16 @@
 ATIATED)
- %7B
 %0A       
@@ -1886,32 +1886,41 @@
 ED)%0A            
+return;%0A%0A
         Player p
@@ -1949,33 +1949,25 @@
 tity();%0A
-         
+%0A
         
    if (p
@@ -1954,27 +1954,24 @@
 );%0A%0A        
-   
 if (p.hasPer
@@ -1994,24 +1994,25 @@
 H_REGEN)) %7B%0A
+%0A
             
@@ -2003,32 +2003,139 @@
  %7B%0A%0A            
+//this is a special addition due to a bukkit bug where it adds exhuastion even if the healing is cancelled%0A
             if (
@@ -2258,28 +2258,16 @@
         
-  
-          
 p.setExh
@@ -2326,33 +2326,19 @@
         
-            %7D%0A   
+%7D%0A%0A
         
@@ -2341,25 +2341,16 @@
         
-         
 //Cancel
@@ -2378,28 +2378,16 @@
 e regen%0A
-            
         
@@ -2419,62 +2419,8 @@
 e);%0A
-                    %7D%0A                %7D%0A            %7D%0A
     

update the regen feature