package com.forgeessentials.economy;

import java.util.HashMap;
import java.util.UUID;

import net.minecraft.entity.player.EntityPlayer;

import com.forgeessentials.api.IEconManager;
import com.forgeessentials.data.api.ClassContainer;
import com.forgeessentials.data.api.DataStorageManager;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;

/**
 * Call these methods to modify a target's Wallet.
 */
public class WalletHandler implements IEconManager {
    private static ClassContainer con = new ClassContainer(Wallet.class);
    private static HashMap<UUID, Wallet> wallets = new HashMap<UUID, Wallet>();

    @Override
    public void addToWallet(int amountToAdd, UUID player)
    {
        wallets.get(player).amount = wallets.get(player).amount + amountToAdd;
    }

    @Override
    public int getWallet(UUID player)
    {
        return wallets.get(player).amount;
    }

    @Override
    public void removeFromWallet(int amountToSubtract, UUID player)
    {
        if (wallets.get(player).amount - amountToSubtract >= 0)
        {
            wallets.get(player).amount = wallets.get(player).amount - amountToSubtract;
        }
    }

    @Override
    public void setWallet(int setAmount, EntityPlayer player)
    {
        wallets.get(player.getUniqueID()).amount = setAmount;
    }

    @Override
    public String currency(int amount)
    {
        if (amount == 1)
        {
            return ConfigEconomy.currencySingular;
        }
        else
        {
            return ConfigEconomy.currencyPlural;
        }
    }

    @Override
    public String getMoneyString(UUID username)
    {
        int am = getWallet(username);
        return am + " " + currency(am);
    }

    @SubscribeEvent
    public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event)
    {
        Wallet wallet = (Wallet) DataStorageManager.getReccomendedDriver().loadObject(con, event.player.getUniqueID().toString());
        if (wallet == null)
        {
            wallet = new Wallet(event.player, ModuleEconomy.startbuget);
        }
        wallets.put(event.player.getUniqueID(), wallet);
    }

    @SubscribeEvent
    public void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event)
    {
        if (wallets.containsKey(event.player.getUniqueID()))
        {
            DataStorageManager.getReccomendedDriver().saveObject(con, wallets.remove(event.player.getUniqueID()));
        }
    }
}

@@ -2077,16 +2077,17 @@
 .startbu
+d
 get);%0A  

Fix derp