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
@@ -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 <M extends Message> boolean notify(Player player, M message) {
@SuppressWarnings("unchecked")
MessageHandlerChain<M> chain = (MessageHandlerChain<M>) chains.get(message.getClass());
return chain == null || chain.notify(player, message);
Class<M> clazz = (Class<M>) message.getClass();
while (clazz.getSuperclass() != Message.class) {
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 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<? extends Message> messageClass = (Class<? extends Message>) 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<? extends MessageHandler<? extends Message>> handlerClass = (Class<? extends MessageHandler<? extends Message>>) Class.forName(handlerClassName);
MessageHandler<? extends Message> handler = handlerClass.getConstructor(World.class).newInstance(world);
chainSet.putHandler(messageClass, handler);