diff --git a/src/main/java/cn/enaium/kookstarter/client/socket/DefaultHandler.java b/src/main/java/cn/enaium/kookstarter/client/socket/DefaultHandler.java index 7991a18..36328c8 100644 --- a/src/main/java/cn/enaium/kookstarter/client/socket/DefaultHandler.java +++ b/src/main/java/cn/enaium/kookstarter/client/socket/DefaultHandler.java @@ -103,22 +103,27 @@ public DefaultHandler(ObjectMapper objectMapper, ApplicationEventPublisher publi } case 0 -> {//事件 final var data = jsonNode.get("d"); - final var extra = data.get("extra"); - final var type = extra.get("type").asText(); - - final List list = events.stream().filter(it -> it.type().equals(type)).toList(); - if (list.isEmpty()) { - LOGGER.warn("未知事件:{}", type); + if (data.has("extra")) { + final var extra = data.get("extra"); + final var type = extra.get("type").asText(); + + final List list = events.stream().filter(it -> it.type().equals(type)).toList(); + if (list.isEmpty()) { + LOGGER.warn("未知事件:{}", type); + } else { + list.forEach(it -> { + try { + final Object event = objectMapper.readValue(message, it.klass()); + publisher.publishEvent(event); + } catch (JsonProcessingException e) { + LOGGER.error("事件处理失败", e); + } + }); + } } else { - list.forEach(it -> { - try { - final Object event = objectMapper.readValue(message, it.klass()); - publisher.publishEvent(event); - } catch (JsonProcessingException e) { - LOGGER.error("事件处理失败", e); - } - }); + LOGGER.error("事件获取extra失败:{}", jsonNode); } + } } }).then();