public static void registerPacket(Class packet) { if (!net.cubespace.ComuCator.API.Message.Message.class.isAssignableFrom(packet)) { Logger.warn("This packet does not implement the Message Interface - " + packet.getName()); return; } // Create the Packet once try { net.cubespace.ComuCator.API.Message.Message message = (net.cubespace.ComuCator.API.Message.Message) packet.newInstance(); // Find the Channel to which this Packet belongs String channel; if (packet.isAnnotationPresent(Channel.class)) { channel = ((Channel) packet.getAnnotation(Channel.class)).value(); } else { channel = message.getChannel(); } // If there is no channel for this Packet => Outta here if (channel == null) { Logger.warn( "The packet has no Channel annotation and did gave null back on getChannel() - " + packet.getName()); return; } Long key = StringCode.getStringCode(channel); Long classKey = StringCode.getStringCode(packet.getName()); synchronized (packets) { // Check if Channel exists if (packets.containsKey(key)) { packets.get(key).put(classKey, packet); } else { LinkedHashMap<Long, Class> classes = new LinkedHashMap<>(); classes.put(classKey, packet); packets.put(key, classes); ChannelKeyCache.addToCache(channel); } ClassKeyCache.addToCache(packet); } } catch (Exception e) { Logger.warn( "The packet could not be build. Make sure it has a default Constructor - " + packet.getName()); } }