package net.ghostrealms.resident;

import net.ghostrealms.FriendException;
import net.ghostrealms.TownException;
import net.ghostrealms.plot.Plot;
import net.ghostrealms.town.Town;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created by River on 1/11/2015.
 */
public class Resident {
    private UUID id;
    private String username;
    private int townId;
    private List<UUID> friends = new ArrayList<UUID>();
    private List<Plot> ownedPlots = new ArrayList<Plot>();

    public void joinTown(int id) throws TownException {
        Town t = Town.getByID(id);
        if (t.isJoinable()) {
            if(!(townId == 0)) {
                leaveTown();
                townId = id;
            } else {
                townId = id;
            }
        } else {
            throw new TownException("Town not joinable");
        }
    }

    public void leaveTown() {
        this.townId = 0;
        //Set their town to 0 - null
    }

    public void addFriend(UUID id) throws FriendException {
        if(friends.contains(id)) {
            throw new FriendException("User is already a friend");
        }

        friends.add(id);
    }

    public void removeFriend(UUID id) throws FriendException {
        if(!friends.contains(id)) {
          throw new FriendException("User is not a friend");
        }
        friends.remove(id);
    }

}

@@ -51,16 +51,26 @@
 trealms.
+exception.
 FriendEx
@@ -101,16 +101,117 @@
 trealms.
+Metro;%0Aimport net.ghostrealms.exception.InsufficientFundsException;%0Aimport net.ghostrealms.exception.
 TownExce
@@ -284,16 +284,42 @@
 wn.Town;
+%0Aimport org.bukkit.Bukkit;
 %0A%0Aimport
@@ -641,16 +641,82 @@
 Plot%3E();
+%0A    %0A    public Resident(UUID id) %7B%0A        // pew pew todo%0A    %7D
 %0A%0A    pu
@@ -1069,32 +1069,86 @@
        %7D%0A    %7D%0A%0A
+    public UUID getUUID() %7B%0A        return id;%0A    %7D%0A%0A
     public void 
@@ -1597,32 +1597,32 @@
 nd%22);%0A        %7D%0A
-
         friends.
@@ -1638,12 +1638,1061 @@
 );%0A    %7D
+%0A    %0A    public List%3CResident%3E getFriends() %7B%0A        List%3CResident%3E list = new ArrayList%3CResident%3E();%0A        for(UUID id : friends) %7B%0A            list.add(new Resident(id));%0A        %7D%0A        return list;%0A    %7D%0A%0A    public double getBalance() %7B%0A        return Metro.getEconomy().getBalance(Bukkit.getOfflinePlayer(id));%0A    %7D%0A%0A    public void withdraw(double amount) %7B%0A        Metro.getEconomy().withdrawPlayer(Bukkit.getOfflinePlayer(id), amount);%0A    %7D%0A%0A    public void deposit(double amount) %7B%0A        Metro.getEconomy().depositPlayer(Bukkit.getOfflinePlayer(id), amount);%0A    %7D%0A%0A    public void pay(Resident res, double amount) throws InsufficientFundsException %7B%0A        double balance = Metro.getEconomy().getBalance(Bukkit.getOfflinePlayer(id));%0A        if(balance %3E amount) %7B%0A            Metro.getEconomy().withdrawPlayer(Bukkit.getOfflinePlayer(id), amount);%0A            Metro.getEconomy().depositPlayer(Bukkit.getOfflinePlayer(res.getUUID()), amount);%0A        %7D else %7B%0A            throw new InsufficientFundsException();%0A        %7D%0A    %7D
 %0A%0A%7D%0A

update to include a friend list method returing an arraylist of residents