package us.myles.ViaVersion.api.data;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.socket.SocketChannel;
import lombok.Getter;
import lombok.Setter;

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

public class UserConnection {
    @Getter
    private final SocketChannel channel;
    List<StoredObject> storedObjects = new ArrayList<>();
    @Getter
    @Setter
    private boolean active = true;
    @Getter
    @Setter
    private Object lastPacket;


    public UserConnection(SocketChannel socketChannel) {
        this.channel = socketChannel;
    }

    public <T extends StoredObject> T get(Class<T> objectClass) {
        for (StoredObject o : storedObjects) {
            if (o.getClass().equals(objectClass))
                return (T) o;
        }
        return null;
    }

    public <T extends StoredObject> boolean has(Class<T> objectClass) {
        for (StoredObject o : storedObjects) {
            if (o.getClass().equals(objectClass))
                return true;
        }
        return false;
    }

    public void put(StoredObject object) {
        storedObjects.add(object);
    }

    public void sendRawPacket(final ByteBuf packet, boolean currentThread) {
        final ChannelHandler handler = channel.pipeline().get("encoder");
        if (currentThread) {
            channel.pipeline().context(handler).writeAndFlush(packet);
        } else {
            channel.eventLoop().submit(new Runnable() {
                @Override
                public void run() {
                    channel.pipeline().context(handler).writeAndFlush(packet);
                }
            });
        }
    }

    public void sendRawPacket(final ByteBuf packet) {
        sendRawPacket(packet, false);
    }
}

@@ -245,16 +245,85 @@
 il.List;
+%0Aimport java.util.Map;%0Aimport java.util.concurrent.ConcurrentHashMap;
 %0A%0Apublic
@@ -403,21 +403,27 @@
 el;%0A    
-List%3C
+Map%3CClass, 
 StoredOb
@@ -448,25 +448,33 @@
 s = new 
-ArrayList
+ConcurrentHashMap
 %3C%3E();%0A  
@@ -767,393 +767,183 @@
     
-for (StoredObject o : storedObjects) %7B%0A            if (o.getClass().equals(objectClass))%0A                return (T) o;%0A        %7D%0A        return null;%0A    %7D%0A%0A    public %3CT extends StoredObject%3E boolean has(Class%3CT%3E objectClass) %7B%0A        for (StoredObject o : storedObjects) %7B%0A            if (o.getClass().equals(objectClass))%0A                return true;%0A        %7D%0A        return false
+return (T) storedObjects.get(objectClass);%0A    %7D%0A%0A    public %3CT extends StoredObject%3E boolean has(Class%3CT%3E objectClass) %7B%0A        return storedObjects.containsKey(objectClass)
 ;%0A  
@@ -1016,12 +1016,31 @@
 cts.
-add(
+put(object.getClass(), 
 obje

Change to use maps, much better for optimisation.