skadistats.clarity.event.Event Java Examples

The following examples show how to use skadistats.clarity.event.Event. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InputSourceProcessor.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Event<OnMessage> evOnMessage(Class<? extends GeneratedMessage> messageClass) {
    Event<OnMessage> ev = evOnMessages.get(messageClass);
    if (ev == null) {
        ev = ctx.createEvent(OnMessage.class, messageClass);
        evOnMessages.put(messageClass, ev);
    }
    return ev;
}
 
Example #2
Source File: InputSourceProcessor.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Event<OnPostEmbeddedMessage> evOnPostEmbeddedMessage(Class<? extends GeneratedMessage> messageClass) {
    Event<OnPostEmbeddedMessage> ev = evOnPostEmbeddedMessages.get(messageClass);
    if (ev == null) {
        ev = ctx.createEvent(OnPostEmbeddedMessage.class, messageClass, BitStream.class);
        evOnPostEmbeddedMessages.put(messageClass, ev);
    }
    return ev;
}
 
Example #3
Source File: InputSourceProcessor.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@OnMessageContainer
public void processEmbedded(Class<? extends GeneratedMessage> containerClass, ByteString bytes) throws IOException {
    BitStream bs = BitStream.createBitStream(bytes);
    while (bs.remaining() >= 8) {
        int kind = engineType.readEmbeddedKind(bs);
        if (kind == 0) {
            // this seems to happen with console recorded replays
            break;
        }
        int size = bs.readVarUInt();
        if (size < 0 || bs.remaining() < size * 8) {
            throw new IOException(
                    String.format("invalid embedded packet size: got %d remaining bits, but size is %d bits.", bs.remaining(), size * 8)
            );
        }
        Class<? extends GeneratedMessage> messageClass = engineType.embeddedPacketClassForKind(kind);
        if (messageClass == null) {
            logUnknownMessage("embedded", kind);
            bs.skip(size * 8);
        } else {
            Event<OnMessage> ev = evOnMessage(messageClass);
            Event<OnPostEmbeddedMessage> evPost = evOnPostEmbeddedMessage(messageClass);
            if (ev.isListenedTo() || evPost.isListenedTo() || (unpackUserMessages && messageClass == NetworkBaseTypes.CSVCMsg_UserMessage.class)) {
                GeneratedMessage subMessage = Packet.parse(messageClass, ZeroCopy.wrap(packetReader.readFromBitStream(bs, size * 8)));
                if (ev.isListenedTo()) {
                    ev.raise(subMessage);
                }
                if (unpackUserMessages && messageClass == NetworkBaseTypes.CSVCMsg_UserMessage.class) {
                    NetworkBaseTypes.CSVCMsg_UserMessage userMessage = (NetworkBaseTypes.CSVCMsg_UserMessage) subMessage;
                    Class<? extends GeneratedMessage> umClazz = engineType.userMessagePacketClassForKind(userMessage.getMsgType());
                    if (umClazz == null) {
                        logUnknownMessage("usermessage", userMessage.getMsgType());
                    } else {
                        evOnMessage(umClazz).raise(Packet.parse(umClazz, userMessage.getMsgData()));
                    }
                }
                if (evPost.isListenedTo()) {
                    evPost.raise(subMessage, bs);
                }
            } else {
                bs.skip(size * 8);
            }
        }
    }
}
 
Example #4
Source File: Context.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public <A extends Annotation> Event<A> createEvent(Class<A> eventType, Class... parameterTypes) {
    return executionModel.createEvent(eventType, parameterTypes);
}
 
Example #5
Source File: ExecutionModel.java    From clarity with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public <A extends Annotation> Event<A> createEvent(Class<A> eventType, Class... parameterTypes) {
    Set<EventListener<A>> listeners = computeListenersForEvent(eventType, parameterTypes);
    return new Event<>(listeners);
}