/*
 * Copyright (c) 2015 Demigods RPG
 *
 * 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 com.demigodsrpg.demigames.profile;

import com.demigodsrpg.demigames.impl.Demigames;
import com.demigodsrpg.demigames.kit.Kit;
import com.demigodsrpg.demigames.kit.MutableKit;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.io.Serializable;
import java.util.Optional;
import java.util.UUID;

public class Profile implements Serializable {
    // -- DATA -- //

    private transient Optional<Player> player;

    private Kit kit;
    private String mojangUniqueId;
    private String currentSessionId;

    // -- CONSTRUCTORS -- //

    public Profile() {
        this.player = Optional.empty();
    }

    public Profile(Player player) {
        this.player = Optional.of(player);
        this.mojangUniqueId = player.getUniqueId().toString();
        this.kit = null;
        this.currentSessionId = null;
        Demigames.getProfileRegistry().put(mojangUniqueId, this);
    }

    public Profile(Player player, Kit kit) {
        this.player = Optional.of(player);
        this.mojangUniqueId = player.getUniqueId().toString();
        this.kit = MutableKit.of(kit);
        this.currentSessionId = null;
        Demigames.getProfileRegistry().put(mojangUniqueId, this);
    }

    // -- GETTERS -- //

    public Optional<Player> getPlayer() {
        if (!player.isPresent()) {
            OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(mojangUniqueId));
            if (offlinePlayer.isOnline()) {
                player = Optional.of(offlinePlayer.getPlayer());
            }
        }
        return player;
    }

    public String getMojangUniqueId() {
        return mojangUniqueId;
    }

    public Optional<Kit> getKit() {
        return Optional.ofNullable(kit);
    }

    public Optional<String> getCurrentSessionId() {
        return Optional.ofNullable(currentSessionId);
    }

    // -- MUTATORS -- //

    public void setKit(Kit kit) {
        this.kit = MutableKit.of(kit);
        Demigames.getProfileRegistry().put(mojangUniqueId, this);
    }

    public void setCurrentSessionId(String sessionId) {
        this.currentSessionId = sessionId;
        Demigames.getProfileRegistry().put(mojangUniqueId, this);
    }
}

@@ -1637,24 +1637,58 @@
 ngUniqueId;%0A
+    private String lastKnownName;%0A
     private 
@@ -1712,16 +1712,16 @@
 sionId;%0A
-
 %0A    // 
@@ -1947,32 +1947,79 @@
 d().toString();%0A
+        this.lastKnownName = player.getName();%0A
         this.kit
@@ -2281,32 +2281,79 @@
 d().toString();%0A
+        this.lastKnownName = player.getName();%0A
         this.kit
@@ -2887,24 +2887,24 @@
 niqueId() %7B%0A
-
         retu
@@ -2921,32 +2921,108 @@
 niqueId;%0A    %7D%0A%0A
+    public String getLastKnownName() %7B%0A        return lastKnownName;%0A    %7D%0A%0A
     public Optio

Add names to profiles.