package kernitus.plugin.OldCombatMechanics.module;

import kernitus.plugin.OldCombatMechanics.OCMMain;
import kernitus.plugin.OldCombatMechanics.utilities.damage.DamageUtils;
import kernitus.plugin.OldCombatMechanics.utilities.damage.OCMEntityDamageByEntityEvent;
import kernitus.plugin.OldCombatMechanics.utilities.damage.WeaponDamages;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;

import java.util.Locale;

public class ModuleOldToolDamage extends Module {

    private String[] weapons = {"sword", "axe", "pickaxe", "spade", "hoe"};

    public ModuleOldToolDamage(OCMMain plugin){
        super(plugin, "old-tool-damage");
    }

    @EventHandler (ignoreCancelled = true)
    public void onEntityDamaged(OCMEntityDamageByEntityEvent event){
        Entity damager = event.getDamager();

        World world = damager.getWorld();

        if(!isEnabled(world)) return;

        Material mat = event.getWeapon().getType();

        if(!isHolding(mat, weapons)) return;

        double weaponDamage = WeaponDamages.getDamage(mat);
        if(weaponDamage <= 0) weaponDamage = 1;

        double baseDamage = event.getBaseDamage();

        event.setBaseDamage(weaponDamage);
        debug("Old tool damage: " + baseDamage + " New tool damage: " + weaponDamage, damager);

        //Set sharpness to 1.8 damage value
        double newSharpnessDamage = DamageUtils.getOldSharpnessDamage(event.getSharpnessLevel());
        debug("Old sharpness damage: " + event.getSharpnessDamage() + " New: " + newSharpnessDamage, damager);
        event.setSharpnessDamage(newSharpnessDamage);
    }

    private boolean isHolding(Material mat, String type){
        return mat.toString().endsWith("_" + type.toUpperCase(Locale.ROOT));
    }

    private boolean isHolding(Material mat, String[] types){
        boolean hasAny = false;
        for(String type : types)
            if(isHolding(mat, type))
                hasAny = true;
        return hasAny;
    }
}

@@ -482,16 +482,53 @@
 ocale;%0A%0A
+/**%0A * Restores old tool damage.%0A */%0A
 public c
@@ -582,16 +582,29 @@
 private 
+static final 
 String%5B%5D
@@ -604,23 +604,23 @@
 tring%5B%5D 
-weapons
+WEAPONS
  = %7B%22swo
@@ -774,17 +774,16 @@
 tHandler
- 
 (ignoreC
@@ -1013,19 +1013,30 @@
 aterial 
-mat
+weaponMaterial
  = event
@@ -1078,28 +1078,27 @@
 (!is
-Holding(mat, weapons
+Tool(weaponMaterial
 )) r
@@ -1159,19 +1159,30 @@
 tDamage(
-mat
+weaponMaterial
 );%0A     
@@ -1240,17 +1240,20 @@
  double 
-b
+oldB
 aseDamag
@@ -1359,17 +1359,20 @@
 ge: %22 + 
-b
+oldB
 aseDamag
@@ -1433,16 +1433,17 @@
       //
+ 
 Set shar
@@ -1752,39 +1752,36 @@
 ivate boolean is
-Holding
+Tool
 (Material mat, S
@@ -1781,99 +1781,142 @@
  mat
-, String type)%7B%0A        return mat.toString().endsWith(%22_%22 + type.toUpperCase(Locale.ROOT))
+erial)%7B%0A        for(String type : WEAPONS)%0A            if(isOfType(material, type))%0A                return true;%0A%0A        return false
 ;%0A  
@@ -1942,23 +1942,22 @@
 olean is
-Holding
+OfType
 (Materia
@@ -1973,16 +1973,13 @@
 ring
-%5B%5D
  type
-s
 )%7B%0A 
@@ -1989,154 +1989,75 @@
     
-boolean hasAny = false;%0A        for(String type : types)%0A            if(isHolding(mat, type))%0A                hasAny = true;%0A        return hasAny
+return mat.toString().endsWith(%22_%22 + type.toUpperCase(Locale.ROOT))
 ;%0A  

Add javadoc, slight refactor