diff --git a/src/org/apollo/game/message/MessageHandlerChainSet.java b/src/org/apollo/game/message/MessageHandlerChainSet.java index 95f67487..d9e25ef4 100644 --- a/src/org/apollo/game/message/MessageHandlerChainSet.java +++ b/src/org/apollo/game/message/MessageHandlerChainSet.java @@ -21,16 +21,21 @@ public final class MessageHandlerChainSet { /** * Notifies the appropriate {@link MessageHandlerChain} that a {@link Message} has been received. - * + * * @param player The {@link Player} receiving the Message. * @param message The Message. * @return {@code true} if the Message propagated down the chain without being terminated or if the chain for the * Message was not found, otherwise {@code false}. */ + @SuppressWarnings("unchecked") public boolean notify(Player player, M message) { - @SuppressWarnings("unchecked") - MessageHandlerChain chain = (MessageHandlerChain) chains.get(message.getClass()); - return chain == null || chain.notify(player, message); + Class clazz = (Class) message.getClass(); + while (clazz.getSuperclass() != Message.class) { + clazz = (Class) clazz.getSuperclass(); + } + + MessageHandlerChain chain = (MessageHandlerChain) chains.computeIfAbsent(clazz, MessageHandlerChain::new); + return chain.notify(player, message); } /** diff --git a/src/org/apollo/io/MessageHandlerChainSetParser.java b/src/org/apollo/io/MessageHandlerChainSetParser.java index 1b308551..1c34a088 100644 --- a/src/org/apollo/io/MessageHandlerChainSetParser.java +++ b/src/org/apollo/io/MessageHandlerChainSetParser.java @@ -48,6 +48,7 @@ public final class MessageHandlerChainSetParser { * @throws SAXException If a SAX error occurs. * @throws ReflectiveOperationException If a reflection error occurs. */ + @SuppressWarnings("unchecked") public MessageHandlerChainSet parse(World world) throws IOException, SAXException, ReflectiveOperationException { XmlNode messages = parser.parse(is); if (!messages.getName().equals("messages")) { @@ -75,7 +76,6 @@ public final class MessageHandlerChainSetParser { throw new IOException("Type node must have a value."); } - @SuppressWarnings("unchecked") Class messageClass = (Class) Class.forName(messageClassName); for (XmlNode handlerNode : chainNode) { @@ -88,7 +88,6 @@ public final class MessageHandlerChainSetParser { throw new IOException("Handler node must have a value."); } - @SuppressWarnings("unchecked") Class> handlerClass = (Class>) Class.forName(handlerClassName); MessageHandler handler = handlerClass.getConstructor(World.class).newInstance(world); chainSet.putHandler(messageClass, handler);