Merged in atomicint/apollo (pull request #5)

Temporary fix #13
This commit is contained in:
John Major
2015-04-29 04:34:51 +01:00
2 changed files with 10 additions and 6 deletions
@@ -27,10 +27,15 @@ public final class MessageHandlerChainSet {
* @return {@code true} if the Message propagated down the chain without being terminated or if the chain for the * @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}. * Message was not found, otherwise {@code false}.
*/ */
@SuppressWarnings("unchecked")
public <M extends Message> boolean notify(Player player, M message) { public <M extends Message> boolean notify(Player player, M message) {
@SuppressWarnings("unchecked") Class<M> clazz = (Class<M>) message.getClass();
MessageHandlerChain<M> chain = (MessageHandlerChain<M>) chains.get(message.getClass()); while (clazz.getSuperclass() != Message.class) {
return chain == null || chain.notify(player, message); clazz = (Class<M>) clazz.getSuperclass();
}
MessageHandlerChain<M> chain = (MessageHandlerChain<M>) chains.computeIfAbsent(clazz, MessageHandlerChain::new);
return chain.notify(player, message);
} }
/** /**
@@ -48,6 +48,7 @@ public final class MessageHandlerChainSetParser {
* @throws SAXException If a SAX error occurs. * @throws SAXException If a SAX error occurs.
* @throws ReflectiveOperationException If a reflection error occurs. * @throws ReflectiveOperationException If a reflection error occurs.
*/ */
@SuppressWarnings("unchecked")
public MessageHandlerChainSet parse(World world) throws IOException, SAXException, ReflectiveOperationException { public MessageHandlerChainSet parse(World world) throws IOException, SAXException, ReflectiveOperationException {
XmlNode messages = parser.parse(is); XmlNode messages = parser.parse(is);
if (!messages.getName().equals("messages")) { if (!messages.getName().equals("messages")) {
@@ -75,7 +76,6 @@ public final class MessageHandlerChainSetParser {
throw new IOException("Type node must have a value."); throw new IOException("Type node must have a value.");
} }
@SuppressWarnings("unchecked")
Class<? extends Message> messageClass = (Class<? extends Message>) Class.forName(messageClassName); Class<? extends Message> messageClass = (Class<? extends Message>) Class.forName(messageClassName);
for (XmlNode handlerNode : chainNode) { for (XmlNode handlerNode : chainNode) {
@@ -88,7 +88,6 @@ public final class MessageHandlerChainSetParser {
throw new IOException("Handler node must have a value."); throw new IOException("Handler node must have a value.");
} }
@SuppressWarnings("unchecked")
Class<? extends MessageHandler<? extends Message>> handlerClass = (Class<? extends MessageHandler<? extends Message>>) Class.forName(handlerClassName); Class<? extends MessageHandler<? extends Message>> handlerClass = (Class<? extends MessageHandler<? extends Message>>) Class.forName(handlerClassName);
MessageHandler<? extends Message> handler = handlerClass.getConstructor(World.class).newInstance(world); MessageHandler<? extends Message> handler = handlerClass.getConstructor(World.class).newInstance(world);
chainSet.putHandler(messageClass, handler); chainSet.putHandler(messageClass, handler);