/**
 * The MIT License
 * Copyright (c) 2015 Teal Cube Games
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package info.faceland.strife.listeners;

import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils;

import info.faceland.strife.StrifePlugin;
import info.faceland.strife.attributes.AttributeHandler;
import info.faceland.strife.attributes.StrifeAttribute;
import info.faceland.strife.data.Champion;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;

public class InventoryListener implements Listener {

    private final StrifePlugin plugin;

    public InventoryListener(StrifePlugin plugin) {
        this.plugin = plugin;
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onInventoryClose(InventoryCloseEvent event) {
        InventoryView inventoryView = event.getView();
        if (!(inventoryView.getTopInventory() instanceof PlayerInventory) && !(inventoryView.getBottomInventory()
                instanceof PlayerInventory)) {
            return;
        }
        PlayerInventory playerInventory;
        if (inventoryView.getTopInventory() instanceof PlayerInventory) {
            playerInventory = (PlayerInventory) inventoryView.getTopInventory();
        } else {
            playerInventory = (PlayerInventory) inventoryView.getBottomInventory();
        }
        HumanEntity humanEntity = playerInventory.getHolder();
        if (!(humanEntity instanceof Player)) {
            return;
        }
        final Player player = (Player) humanEntity;
        if (player.isDead() || player.getHealth() <= 0D) {
            return;
        }
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
            @Override
            public void run() {
                Champion champion = plugin.getChampionManager().getChampion(player.getUniqueId());
                champion.getAttributeValues(true);
                boolean spam = false;
                for (ItemStack itemStack : champion.getPlayer().getEquipment().getArmorContents()) {
                    if (itemStack == null || itemStack.getType() == Material.AIR) {
                        continue;
                    }
                    if (!AttributeHandler.meetsLevelRequirement(player, itemStack)) {
                        spam = true;
                    }
                }
                if (spam) {
                    MessageUtils.sendMessage(player,
                            "<red>You don't meet the requirement for one of your items! It will not give any stats!");
                }
                AttributeHandler.updateHealth(player, champion.getCacheAttribute(StrifeAttribute.HEALTH,
                        StrifeAttribute.HEALTH.getBaseValue()));
                double perc = champion.getCacheAttribute(StrifeAttribute.MOVEMENT_SPEED,
                        StrifeAttribute.MOVEMENT_SPEED.getBaseValue()) / 100D;
                float speed = 0.2F * (float) perc;
                player.setWalkSpeed(Math.min(Math.max(-1F, speed), 1F));
                player.setFlySpeed(Math.min(Math.max(-1F, speed), 1F));
            }
        });
    }

}

@@ -1448,34 +1448,8 @@
 n;%0A%0A
-import org.bukkit.Bukkit;%0A
 impo
@@ -2860,22 +2860,16 @@
         
-final 
 Player p
@@ -2991,149 +2991,8 @@
   %7D%0A
-        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A        
     
@@ -3086,24 +3086,16 @@
         
-      
-  
 champion
@@ -3121,24 +3121,16 @@
 (true);%0A
-        
         
@@ -3151,24 +3151,16 @@
  false;%0A
-        
         
@@ -3252,32 +3252,24 @@
             
-   
-     
 if (itemStac
@@ -3336,24 +3336,16 @@
         
-        
 continue
@@ -3342,32 +3342,24 @@
   continue;%0A
-        
             
@@ -3368,32 +3368,24 @@
             
-        
 if (!Attribu
@@ -3454,24 +3454,16 @@
         
-        
 spam = t
@@ -3479,34 +3479,18 @@
         
-     
-   %7D%0A        
+%7D%0A
         
@@ -3487,32 +3487,24 @@
 %7D%0A        %7D%0A
-        
         if (
@@ -3523,24 +3523,16 @@
         
-  
-      
 MessageU
@@ -3556,24 +3556,16 @@
 player,%0A
-        
         
@@ -3675,34 +3675,18 @@
         
-       
- 
 %7D%0A
-        
         
@@ -3786,32 +3786,24 @@
             
-        
 StrifeAttrib
@@ -3839,24 +3839,16 @@
         
-    
-    
 double p
@@ -3924,32 +3924,24 @@
             
-       
- 
 StrifeAttrib
@@ -3983,24 +3983,16 @@
 / 100D;%0A
-        
         
@@ -4030,32 +4030,24 @@
 rc;%0A        
- 
-       
 player.setWa
@@ -4095,32 +4095,24 @@
 ));%0A        
-    
-    
 player.setFl
@@ -4159,34 +4159,8 @@
 ));%0A
-            %7D%0A        %7D);%0A
     

Revert "scheduling armor update on close of inventory"