package net.viper.status.modules.customcommands;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Collection;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Connection.Unsafe;

public class ForwardSender implements CommandSender, Connection {
   private ProxiedPlayer target;
   private Boolean admin;

   public ForwardSender(ProxiedPlayer sender, Boolean admin) {
      this.target = sender;
      this.admin = admin;
   }

   public ProxiedPlayer target() {
      return this.target;
   }

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

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

   @Override
   public void sendMessages(String... messages) {
      this.target.sendMessages(messages);
   }

   @Override
   public void sendMessage(BaseComponent... message) {
      this.target.sendMessage(message);
   }

   @Override
   public void sendMessage(BaseComponent message) {
      this.target.sendMessage(message);
   }

   @Override
   public Collection<String> getGroups() {
      return this.target.getGroups();
   }

   @Override
   public void addGroups(String... groups) {
      this.target.addGroups(groups);
   }

   @Override
   public void removeGroups(String... groups) {
      this.target.removeGroups(groups);
   }

   @Override
   public boolean hasPermission(String permission) {
      return this.admin ? true : this.target.hasPermission(permission);
   }

   @Override
   public void setPermission(String permission, boolean value) {
      this.target.setPermission(permission, value);
   }

   @Override
   public Collection<String> getPermissions() {
      Collection<String> perms = new java.util.ArrayList<>(this.target.getPermissions());
      if (this.admin) {
         perms.add("*");
      }
      return perms;
   }

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

   @Override
   public SocketAddress getSocketAddress() {
      return this.target.getSocketAddress();
   }

   @Override
   public void disconnect(String reason) {
      this.target.disconnect(reason);
   }

   @Override
   public void disconnect(BaseComponent... reason) {
      this.target.disconnect(reason);
   }

   @Override
   public void disconnect(BaseComponent reason) {
      this.target.disconnect(reason);
   }

   @Override
   public boolean isConnected() {
      return this.target.isConnected();
   }

   @Override
   public Unsafe unsafe() {
      return this.target.unsafe();
   }
}
