package com.gmail.nossr50.util;

import java.text.DecimalFormat;

import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;

import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillType;

public final class Motd {
    private static final String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix");
    private static final PluginDescriptionFile pluginDescription = mcMMO.p.getDescription();

    private Motd() {}

    public static void displayAll(Player player) {
        displayVersion(player, pluginDescription.getVersion());
        displayHardcoreSettings(player);
        displayXpPerks(player);
        displayCooldownPerks(player);
        displayActivationPerks(player);
        displayLuckyPerks(player);
        displayWebsite(player, pluginDescription.getWebsite());
    }

    /**
     * Display version info.
     * @param player Target player
     * @param version Plugin version
     */
    public static void displayVersion(Player player, String version) {
        player.sendMessage(LocaleLoader.getString("MOTD.Version", version));
    }

    /**
     * Display Hardcore Mode settings.
     * @param player Target player
     */
    public static void displayHardcoreSettings(Player player) {
        if (Config.getInstance().getHardcoreEnabled()) {
            if (Config.getInstance().getHardcoreVampirismEnabled()) {
                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn"));
                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage()));
                player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", Config.getInstance().getHardcoreVampirismStatLeechPercentage()));
            }
            else {
                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOff"));
                player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", Config.getInstance().getHardcoreDeathStatPenaltyPercentage()));
            }
        }
    }

    /**
     * Display XP perks.
     * @param player Target player
     */
    public static void displayXpPerks(Player player) {
        player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", PerksUtils.handleXpPerks(player, 1))));
    }

    /**
     * Display cooldown perks.
     * @param player Target player
     */
    public static void displayCooldownPerks(Player player) {
        double cooldownReduction = 1 - (PerksUtils.handleCooldownPerks(player, 12) / 12.0);
        DecimalFormat percent = new DecimalFormat("##0.00%");

        player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", percent.format(cooldownReduction))));
    }

    /**
     * Display activiation perks.
     * @param player Target player
     */
    public static void displayActivationPerks(Player player) {
        player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", PerksUtils.handleActivationPerks(player, 0, 0))));
    }

    /**
     * Display "lucky" perks.
     * @param player Target player
     */
    public static void displayLuckyPerks(Player player) {
        for (SkillType skill : SkillType.values()) {
            if (Permissions.lucky(player, skill)) {
                player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc.login")));
                return;
            }
        }
    }

    /**
     * Display website info.
     * @param player Target player
     * @param website Plugin website
     */
    public static void displayWebsite(Player player, String website) {
        player.sendMessage(LocaleLoader.getString("MOTD.Website", website));
    }
}

@@ -2383,32 +2383,132 @@
 ayer player) %7B%0D%0A
+        int perkAmount = PerksUtils.handleXpPerks(player, 1);%0D%0A%0D%0A        if (perkAmount %3E 1) %7B%0D%0A    
         player.s
@@ -2659,47 +2659,33 @@
 c%22, 
-PerksUtils.handleXpPerks(player, 1))));
+perkAmount)));%0D%0A        %7D
 %0D%0A  
@@ -2928,24 +2928,70 @@
 ) / 12.0);%0D%0A
+%0D%0A        if (cooldownReduction %3E 0.0) %7B%0D%0A    
         Deci
@@ -3037,26 +3037,28 @@
 ##0.00%25%22);%0D%0A
-%0D%0A
+    
         play
@@ -3258,24 +3258,35 @@
 ction))));%0D%0A
+        %7D%0D%0A
     %7D%0D%0A%0D%0A   
@@ -3427,32 +3427,143 @@
 ayer player) %7B%0D%0A
+        int perkAmount = PerksUtils.handleActivationPerks(player, 0, 0);%0D%0A%0D%0A        if (perkAmount %3E 0) %7B%0D%0A    
         player.s
@@ -3738,58 +3738,33 @@
 c%22, 
-PerksUtils.handleActivationPerks(player, 0, 0))));
+perkAmount)));%0D%0A        %7D
 %0D%0A  

Fix perk messages being displayed even if you have no perks.