package me.ssscrazy.snowball;

import java.util.HashMap;

import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class SaveInventory {
	private HashMap<String, ItemStack> originalInventory = new HashMap<String, ItemStack>();
	private Player p;
	public SaveInventory(Player player) {
		p = player;
		Inventory inventory = player.getInventory();

		for (int i = 0; i < inventory.getSize(); i++) {
			ItemStack item = inventory.getItem(i);
			if(item != null)
			originalInventory.put("s" + i, item.clone());
		}
		if(player.getInventory().getHelmet() != null)
			originalInventory.put("Helmet", player.getInventory().getHelmet().clone());
		if(player.getInventory().getChestplate() != null)
			originalInventory.put("Chestplate", player.getInventory().getChestplate().clone());
		if(player.getInventory().getLeggings() != null)
			originalInventory.put("Leggings", player.getInventory().getLeggings().clone());
		if(player.getInventory().getBoots() != null)
			originalInventory.put("Boots", player.getInventory().getBoots().clone());
		
		
	}
	public void Load() {
		for (int i = 0; i < p.getInventory().getSize(); i++)  {
			p.getInventory().setItem(i, originalInventory.get("s" + i));
		}
		p.getInventory().setHelmet(originalInventory.get("Helmet"));
		p.getInventory().setChestplate(originalInventory.get("Chestplate"));
		p.getInventory().setLeggings(originalInventory.get("Leggings"));
		p.getInventory().setBoots(originalInventory.get("Boots"));
	}
}

@@ -191,16 +191,340 @@
 entory %7B
+ // Temporarily stores a player's inventory in this plugin's memory while the player is in a snowball match%0A%09%09%09     // This allows for players to play the normal game of Minecraft and join/leave arenas as they please.%0A%09%09%09     // i.e. the player does not need to worry about losing their items while in this special gamemode.
 %0A%09privat
@@ -605,16 +605,56 @@
 tack%3E();
+ // Create a list of the player's items.
 %0A%09privat
@@ -664,16 +664,17 @@
 layer p;
+ 
 %0A%09public
@@ -704,16 +704,103 @@
 layer) %7B
+ // This function stores the inventory of the player that was passed into the function.
 %0A%09%09p = p
@@ -852,16 +852,47 @@
 ntory();
+ // Get their entire inventory.
 %0A%0A%09%09for 
@@ -938,119 +938,299 @@
 +) %7B
-%0A%09%09%09ItemStack item = inventory.getItem(i);%0A%09%09%09if(item != null)%0A%09%09%09originalInventory.put(%22s%22 + i, item.clone());
+ // Cycle through all the potential item slots in their inventory%0A%09%09%09ItemStack item = inventory.getItem(i); // Get the item in that slot%0A%09%09%09if(item != null) // If it wasn't empty,%0A%09%09%09originalInventory.put(%22s%22 + i, item.clone()); // Get a copy of the item and put it into our saved inventory.
 %0A%09%09%7D
@@ -1269,32 +1269,76 @@
 elmet() != null)
+ // Check if the player is wearing a helmet.
 %0A%09%09%09originalInve
@@ -1392,32 +1392,60 @@
 lmet().clone());
+ // If so, store the helmet.
 %0A%09%09if(player.get
@@ -1472,32 +1472,49 @@
 plate() != null)
+ // Same as above
 %0A%09%09%09originalInve
@@ -1626,32 +1626,33 @@
 gings() != null)
+ 
 %0A%09%09%09originalInve
@@ -1710,32 +1710,33 @@
 ings().clone());
+ 
 %0A%09%09if(player.get
@@ -1878,66 +1878,219 @@
 () %7B
-%0A%09%09for (int i = 0; i %3C p.getInventory().getSize(); i++)  %7B
+ // This is called when we return the player's inventory after they leave a match.%0A%09%09for (int i = 0; i %3C p.getInventory().getSize(); i++)  %7B // Set their items back to how they were, in the same spots as before.
 %0A%09%09%09
@@ -2212,24 +2212,60 @@
 (%22Helmet%22));
+ // Put their armor back on as well.
 %0A%09%09p.getInve

Update SaveInventory.java