package net.wayward_realms.waywardcharacters;

import net.wayward_realms.waywardlib.character.Character;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.List;

import static org.bukkit.block.Biome.*;

public class PlayerItemConsumeListener implements Listener {

    private WaywardCharacters plugin;

    public PlayerItemConsumeListener(WaywardCharacters plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
        Player player = event.getPlayer();
        Character character = plugin.getActiveCharacter(player);
        if (event.getItem().getType() == Material.POTION) {
            if (event.getItem().hasItemMeta()) {
                List<String> biomeStringList = event.getItem().getItemMeta().getLore();
                String biomeString = biomeStringList.get(1);
                Biome biome = plugin.convertBiomeFromString(biomeString);
                if (biome != null) {
                    boolean isSafe = plugin.isSafeWater(biome);
                    if (!isSafe){
                        player.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 1500, 2), true);
                        player.sendMessage(ChatColor.RED + "You feel sick. Perhaps it was the water.");
                        if (biome == OCEAN || biome == BEACH) {
                            character.setThirst(character.getThirst() - 2);
                            player.sendMessage(ChatColor.RED + "You suddenly feel dehydrated from drinking salt water.");
                            player.sendMessage(ChatColor.RED + "Thirst: -2" + ChatColor.GRAY + " (Total: " + character.getThirst() + ")");
                        }
                    }
                } else {
                    if (event.getItem().getItemMeta().hasDisplayName()) {
                        if (event.getItem().getItemMeta().getDisplayName().equals("Masheek")) {
                            if (event.getItem().getItemMeta().hasLore()) {
                                if (event.getItem().getItemMeta().getLore().contains("+5 mana")) {
                                    character.setMana(Math.min(character.getMana() + 5, character.getMaxMana()));
                                    event.getPlayer().sendMessage(plugin.getPrefix() + ChatColor.GREEN + "+5 mana" + ChatColor.GRAY + " (" + character.getMana() + "/" + character.getMaxMana() + ")");
                                }
                            }
                        }
                    }
                }
            } else {
                character.setThirst(character.getThirst() + 5);
                player.sendMessage(ChatColor.GREEN + "Thirst: +5" + ChatColor.GRAY + " (Total: " + character.getThirst() + ")");
            }
        } else if (event.getItem().getType() == Material.MILK_BUCKET) {
            character.setThirst(character.getThirst() + 5);
            event.getPlayer().sendMessage(ChatColor.GREEN + "Thirst: +5 " + ChatColor.GRAY + "(Total: " + character.getThirst() + ")");
        }
        if (event.getItem().getType() == Material.ROTTEN_FLESH) {
            character.setHealth(character.getHealth() - 5);
            event.getPlayer().sendMessage(ChatColor.RED + "Health: -5 " + ChatColor.GRAY + "(Total: " + character.getHealth() + ")");
        }
    }

}
@@ -1084,24 +1084,78 @@
 .getLore();%0A
+                if (biomeStringList.size() %3E 0) %7B%0A    
             
@@ -1203,12 +1203,16 @@
 get(
-1
+0
 );%0A
+    
     
@@ -1281,16 +1281,20 @@
 tring);%0A
+    
         
@@ -1342,16 +1342,20 @@
         
+    
 boolean 
@@ -1406,24 +1406,28 @@
             
+    
 if (!isSafe)
@@ -1448,24 +1448,28 @@
             
+   
+ 
 player.addPo
@@ -1534,24 +1534,28 @@
  2), true);%0A
+    
             
@@ -1662,32 +1662,36 @@
                 
+    
 if (biome == OCE
@@ -1734,32 +1734,36 @@
                 
+ 
+   
 character.setThi
@@ -1794,16 +1794,20 @@
 ) - 2);%0A
+    
         
@@ -1912,32 +1912,36 @@
  salt water.%22);%0A
+    
                 
@@ -2079,34 +2079,42 @@
                 
-%7D%0A
+    %7D%0A    
                 
@@ -2127,32 +2127,36 @@
                 
+   
+ 
 %7D else %7B%0A       
@@ -2140,32 +2140,36 @@
        %7D else %7B%0A
+    
                 
@@ -2242,32 +2242,36 @@
                 
+    
 if (event.getIte
@@ -2346,32 +2346,36 @@
                 
+  
+  
 if (event.getIte
@@ -2401,24 +2401,28 @@
 asLore()) %7B%0A
+    
             
@@ -2504,24 +2504,28 @@
 5 mana%22)) %7B%0A
+    
             
@@ -2654,32 +2654,36 @@
                 
+    
 event.getPlayer(
@@ -2822,32 +2822,70 @@
 xMana() + %22)%22);%0A
+                                    %7D%0A
                 

Fix water biome detection