package protocolsupport.api;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

import org.bukkit.entity.Player;

public abstract class Connection {

	protected ProtocolVersion version;
	public Connection(ProtocolVersion version) {
		this.version = version;
	}

	public abstract Object getNetworkManager();

	public abstract boolean isConnected();

	public abstract InetSocketAddress getAddress();

	public abstract Player getPlayer();

	public ProtocolVersion getVersion() {
		return version;
	}

	public abstract void receivePacket(Object packet) throws ExecutionException;

	public abstract void sendPacket(Object packet) throws ExecutionException;

	protected final ArrayList<PacketSendListener> sendListeners = new ArrayList<>();
	protected final ArrayList<PacketReceiveListener> receiveListeners = new ArrayList<>();

	public void addPacketSendListener(PacketSendListener listener) {
		sendListeners.add(listener);
	}

	public void removePacketSendListener(PacketSendListener listener) {
		sendListeners.remove(listener);
	}

	public void addPacketReceiveListener(PacketReceiveListener listener) {
		receiveListeners.add(listener);
	}

	public void removePacketReceiveListener(PacketReceiveListener listener) {
		receiveListeners.remove(listener);
	}

	@FunctionalInterface
	public static interface PacketSendListener {
		public boolean onPacketSending(Object packet);
	}

	@FunctionalInterface
	public static interface PacketReceiveListener {
		public boolean onPacketReceiving(Object packet);
	}

}

@@ -75,16 +75,85 @@
 va.util.
+concurrent.ConcurrentHashMap;%0Aimport java.util.concurrent.CopyOnWrite
 ArrayLis
@@ -155,16 +155,16 @@
 ayList;%0A
-
 import j
@@ -786,32 +786,43 @@
 protected final 
+CopyOnWrite
 ArrayList%3CPacket
@@ -847,32 +847,43 @@
 Listeners = new 
+CopyOnWrite
 ArrayList%3C%3E();%0A%09
@@ -898,16 +898,27 @@
 d final 
+CopyOnWrite
 ArrayLis
@@ -965,16 +965,27 @@
 s = new 
+CopyOnWrite
 ArrayLis
@@ -1377,32 +1377,32 @@
 ner listener) %7B%0A
-
 %09%09receiveListene
@@ -1422,24 +1422,354 @@
 tener);%0A%09%7D%0A%0A
+%09private final ConcurrentHashMap%3CString, Object%3E metadata = new ConcurrentHashMap%3C%3E();%0A%0A%09public void addMetadata(String key, Object obj) %7B%0A%09%09metadata.put(key, obj);%0A%09%7D%0A%0A%09public Object removeMetadata(String key) %7B%0A%09%09return metadata.remove(key);%0A%09%7D%0A%0A%09public boolean hasMetadata(String key) %7B%0A%09%09return metadata.containsKey(key);%0A%09%7D%0A%0A
 %09@Functional

Add ability to add custom metadata to connection