package com.github.niwaniwa.we.core.player;

import com.github.niwaniwa.we.core.api.callback.Callback;
import com.github.niwaniwa.we.core.twitter.TwitterManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.permissions.Permission;
import twitter4j.Status;
import twitter4j.StatusUpdate;

import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public abstract class EggPlayer implements Twitter, WhitePlayer {

    private Player player;

    public EggPlayer(Player player) {
        this.player = player;
    }

    @Override
    public void remove() {
        player.remove();
    }

    @Override
    public String getName() {
        return player.getName();
    }

    @Override
    public String getFullName() {
        return getPrefix() + getName();
    }

    @Override
    public Player getPlayer() {
        return player;
    }

    @Override
    public UUID getUniqueId() {
        return player.getUniqueId();
    }

    @Override
    public boolean isOp() {
        return player.isOp();
    }

    @Override
    public boolean isOnline() {
        return player.isOnline();
    }

    @Override
    public void sendMessage(String message) {
        this.sendMessage(message, true);
    }

    @Override
    public void sendMessage(String[] message) {
        Arrays.asList(message).forEach(msg -> sendMessage(msg, true));
    }

    @Override
    public void sendMessage(String message, boolean replaceColorCode) {
        player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
    }

    @Override
    public TwitterManager getTwitterManager() {
        throw new UnsupportedOperationException(getClass().getSimpleName());
    }

    @Override
    public boolean hasPermission(String permission) {
        return player.hasPermission(permission);
    }

    @Override
    public boolean hasPermission(Permission permission) {
        return player.hasPermission(permission);
    }

    public void update() {
        player = Bukkit.getPlayer(getUniqueId());
    }

    @Override
    public InetSocketAddress getAddress() {
        return player.getAddress();
    }

    @Override
    public Object getHandle() {
        Object object = null;
        try {
            object = player.getClass().getMethod("getHandle").invoke(player);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            e.printStackTrace();
        }
        return object;
    }


    @Override
    public Location getLocation() {
        return player.getLocation();
    }

    @Override
    public Inventory getInventory() {
        return player.getInventory();
    }

    @Override
    public void teleport(Location loc) {
        player.teleport(loc);
    }

    @Override
    public void teleport(Entity entity) {
        player.teleport(entity);
    }

    @Override
    public void updateStatus(StatusUpdate update) {
        throw new UnsupportedOperationException(getClass().getSimpleName());
    }

    @Override
    public void updateStatus(StatusUpdate update, Callback callback) {
        throw new UnsupportedOperationException(getClass().getSimpleName());
    }

    @Override
    public void updateStatus(String tweet) {
        throw new UnsupportedOperationException(getClass().getSimpleName());
    }

    @Override
    public List<Status> getTimeLine() {
        throw new UnsupportedOperationException(getClass().getSimpleName());
    }

}

@@ -680,29 +680,25 @@
 private 
-Player player
+UUID uuid
 ;%0A%0A    p
@@ -747,23 +747,101 @@
 his.
-player = player
+uuid = player.getUniqueId();%0A    %7D%0A%0A    public EggPlayer(UUID uuid)%7B%0A        this.uuid = uuid
 ;%0A  
@@ -894,22 +894,27 @@
         
-p
+getP
 layer
+()
 .remove(
@@ -978,30 +978,35 @@
      return 
-p
+getP
 layer
+()
 .getName();%0A
@@ -1168,22 +1168,38 @@
  return 
-player
+Bukkit.getPlayer(uuid)
 ;%0A    %7D%0A
@@ -1256,30 +1256,35 @@
      return 
-p
+getP
 layer
+()
 .getUniqueId
@@ -1347,30 +1347,35 @@
      return 
-p
+getP
 layer
+()
 .isOp();%0A   
@@ -1439,22 +1439,27 @@
  return 
-p
+getP
 layer
+()
 .isOnlin
@@ -1812,22 +1812,27 @@
         
-p
+getP
 layer
+()
 .sendMes
@@ -2119,38 +2119,43 @@
 %0A        return 
-p
+getP
 layer
+()
 .hasPermission(p
@@ -2260,22 +2260,27 @@
  return 
-p
+getP
 layer
+()
 .hasPerm
@@ -2310,92 +2310,8 @@
  %7D%0A%0A
-    public void update() %7B%0A        player = Bukkit.getPlayer(getUniqueId());%0A    %7D%0A%0A
     
@@ -2375,30 +2375,35 @@
      return 
-p
+getP
 layer
+()
 .getAddress(
@@ -2523,22 +2523,27 @@
 bject = 
-p
+getP
 layer
+()
 .getClas
@@ -2576,22 +2576,27 @@
 .invoke(
-p
+getP
 layer
+()
 );%0A     
@@ -2822,30 +2822,35 @@
      return 
-p
+getP
 layer
+()
 .getLocation
@@ -2927,22 +2927,27 @@
  return 
-p
+getP
 layer
+()
 .getInve
@@ -3017,38 +3017,43 @@
  loc) %7B%0A        
-p
+getP
 layer
+()
 .teleport(loc);%0A
@@ -3123,22 +3123,27 @@
         
-p
+getP
 layer
+()
 .telepor

Change player code