| 157 | } |
| 158 | |
| 159 | private void fetcharrEvent(@NotNull FetcharrEvent event) { |
| 160 | if (!started) { |
| 161 | // Don't handle events unless the plugin is in a "running" state |
| 162 | // ie. don't attempt to handle events before Fetcharr starts plugins or after it stops them |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | WebhookAPI api = FetcharrAPIProvider.instance().registry().getFirst(WebhookAPI.class); // Be nice and let other plugins take over the API if they want to try |
| 167 | if (api == null) { |
| 168 | // Something went very wrong, and we still need an API, so fall back to one we know we control |
| 169 | logger.warn("Fetcharr registry did not return valid WebhookAPI while handling event {}", event.eventType().getName()); |
| 170 | api = WebhookAPIProvider.instance(); |
| 171 | } |
| 172 | |
| 173 | for (WebhookDestination d : api.destinations()) { |
| 174 | try { |
| 175 | if (!d.accepts(event)) { |
| 176 | continue; |
| 177 | } |
| 178 | |
| 179 | if (d.handle(event)) { |
| 180 | logger.debug("Destination {} ({}) handled event type {}", d.id(), d.type(), event.eventType().getName()); |
| 181 | } else { |
| 182 | logger.debug("Destination {} ({}) did not handle event type {}", d.id(), d.type(), event.eventType().getName()); |
| 183 | } |
| 184 | } catch (Exception ex) { |
| 185 | logger.warn("Destination {} ({}) threw an exception during handling of event {}", d.id(), d.type(), event.eventType().getName(), ex); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |