use of org.spongepowered.api.event.EventContextKeys in project SpongeCommon by SpongePowered.
the class ContextValueFilterSourceDelegate method insertCauseCall.
@Override
protected void insertCauseCall(final MethodVisitor mv, final ListenerClassVisitor.ListenerParameter param, final Type targetType) {
final Field targetField;
try {
targetField = EventContextKeys.class.getField(this.anno.value());
} catch (final NoSuchFieldException ex) {
throw new IllegalArgumentException(String.format("Field %s specified by GetValue annotation was not found in EventContextKeys", this.anno.value()));
}
if (!EventContextKey.class.isAssignableFrom(targetField.getType())) {
throw new IllegalArgumentException(String.format("Field %s.%s was not an EventContextKey", targetField.getName(), targetField.getType()));
}
// cause.context().get(EventContextKeys.<anno.value()>
mv.visitMethodInsn(INVOKEVIRTUAL, CauseFilterSourceDelegate.CAUSE.getInternalName(), "context", "()" + ContextValueFilterSourceDelegate.EVENT_CONTEXT.getDescriptor(), false);
mv.visitFieldInsn(GETSTATIC, ContextValueFilterSourceDelegate.EVENT_CONTEXT_KEYS.getInternalName(), this.anno.value(), ContextValueFilterSourceDelegate.EVENT_CONTEXT_KEY.getDescriptor());
mv.visitMethodInsn(INVOKEVIRTUAL, ContextValueFilterSourceDelegate.EVENT_CONTEXT.getInternalName(), "get", Type.getMethodDescriptor(ParameterFilterSourceDelegate.OPTIONAL, ContextValueFilterSourceDelegate.EVENT_CONTEXT_KEY), false);
}
Aggregations